kameloso.plugins.sedreplace

The SedReplace plugin imitates the UNIX sed tool, allowing for the replacement/substitution of text. It does not require the tool itself though, and will work on Windows too.

$ echo "foo bar baz" | sed "s/bar/qux/"
foo qux baz

It has no bot commands, as everything is done by scanning messages for signs of s/this/that/ patterns.

It supports a delimiter of /, |, #, @, , _ and ;, but more can be trivially added. See the DelimiterCharacters alias.

You can also end it with a g to set the global flag, to have more than one match substituted.

$ echo "foo bar baz" | sed "s/bar/qux/g"
$ echo "foo bar baz" | sed "s|bar|qux|g"
$ echo "foo bar baz" | sed "s#bar#qux#g"
$ echo "foo bar baz" | sed "s@bar@qux@"
$ echo "foo bar baz" | sed "s bar qux "
$ echo "foo bar baz" | sed "s_bar_qux_"
$ echo "foo bar baz" | sed "s;bar;qux"  // only if relaxSyntax is true

Members

Aliases

DelimiterCharacters
alias DelimiterCharacters = AliasSeq!('/', '|', '#', '@', ' ', '_', ';')

Characters to support as delimiters in the replace expression.

Classes

SedReplacePlugin
class SedReplacePlugin

The SedReplace plugin stores a buffer of the last said line of every user, and if a new message comes in with a sed-replace-like pattern in it, tries to apply it on the original message as a regex-like replace.

Functions

initPrevlines
void initPrevlines(SedReplacePlugin plugin, string channelName, string nickname)

Initialises the records of previous messages from a user when they join a channel.

onJoin
void onJoin(SedReplacePlugin plugin, IRCEvent event)

Initialises the records of previous messages from a user when they join a channel.

onMessage
void onMessage(SedReplacePlugin plugin, IRCEvent event)

Parses a channel message and looks for any sed-replace expressions therein, to apply on the previous message.

onPart
void onPart(SedReplacePlugin plugin, IRCEvent event)

Removes the records of previous messages from a user when they leave a channel.

onQuit
void onQuit(SedReplacePlugin plugin, IRCEvent event)

Removes the records of previous messages from a user when they quit.

onWelcome
void onWelcome(SedReplacePlugin plugin)

Sets up a fiber to periodically clear the lists of previous messages from users once every timeBetweenPurges.

sedReplace
auto sedReplace(string line, string expr, bool relaxSyntax)

sed-replaces a line with a substitution string.

sedReplaceImpl
auto sedReplaceImpl(string line, string expr, bool relaxSyntax)

Private sed-replace implementation.

selftest
auto selftest(SedReplacePlugin plugin, Selftester s)

Performs self-tests against another bot.

Structs

Line
struct Line

Struct aggregate of a spoken line and the timestamp when it was said.

SedReplaceSettings
struct SedReplaceSettings

All sed-replace plugin settings, gathered in a struct.

See Also

Meta