UnittestPlugin

Unit test plugin.

version(unittest)
final
class UnittestPlugin : IRCPlugin {
@Resource
auto resFileWithoutSubdir;
@Resource("unittest")
auto resFileWithSubdir;
@Configuration
auto confFileWithoutSubdir;
@Configuration("unittest")
auto confFileWithSubdir;
}

Members

Variables

unittestSettings
UnittestSettings unittestSettings;

Unit test plugin settings.

Mixed In Members

From mixin MessagingProxy

hasMessagingProxy
enum hasMessagingProxy;

Flag denoting that MessagingProxy has been mixed in.

chan
void chan(string channelName, string content, Message.Property properties, string caller)

Sends a channel message.

reply
void reply(IRCEvent event, string content, Message.Property properties, string caller)

Replies to a channel message.

query
void query(string nickname, string content, Message.Property properties, string caller)

Sends a private query message to a user.

privmsg
void privmsg(string channel, string nickname, string content, Message.Property properties, string caller)

Sends either a channel message or a private query message depending on the arguments passed to it.

emote
void emote(string emoteTarget, string content, Message.Property properties, string caller)

Sends an ACTION "emote" to the supplied target (nickname or channel).

mode
void mode(string channel, const(char)[] modes, string content, Message.Property properties, string caller)

Sets a channel mode.

topic
void topic(string channel, string content, Message.Property properties, string caller)

Sets the topic of a channel.

invite
void invite(string channel, string nickname, Message.Property properties, string caller)

Invites a user to a channel.

join
void join(string channel, string key, Message.Property properties, string caller)

Joins a channel.

kick
void kick(string channel, string nickname, string reason, Message.Property properties, string caller)

Kicks a user from a channel.

part
void part(string channel, string reason, Message.Property properties, string caller)

Leaves a channel.

quit
void quit(string reason, Message.Property properties, string caller)

Disconnects from the server, optionally with a quit reason.

whois
void whois(string nickname, Message.Property properties, string caller)

Queries the server for WHOIS information about a user.

raw
void raw(string line, Message.Property properties, string caller)

Sends text to the server, verbatim.

immediate
void immediate(string line, Message.Property properties, string caller)

Sends raw text to the server, verbatim, bypassing all queues and throttling delays.

immediateline
alias immediateline = immediate

Merely an alias to immediate, because we use both terms at different places.

From mixin IRCPluginImpl!(Yes.debug_)

hasIRCPluginImpl
enum hasIRCPluginImpl;

Flag denoting that IRCPluginImpl has been mixed in.

Introspection
struct Introspection

Namespace for the alias sequences of all event handler functions in this module, as well as the one of all IRCEventHandler annotations in the module.

isEnabled
bool isEnabled()

Introspects the current plugin, looking for a Settings-annotated struct member that has a bool annotated with Enabler, which denotes it as the bool that toggles a plugin on and off.

allow
FilterResult allow(IRCEvent event, Permissions permissionsRequired)

Judges whether an event may be triggered, based on the event itself and the annotated required Permissions of the handler in question. Wrapper function that merely calls kameloso.plugins.common.allowImpl. The point behind it is to make something that can be overridden and still allow it to call the original logic (below).

onEvent
void onEvent(IRCEvent event)

Forwards the supplied IRCEvent to IRCPluginImpl.onEventImpl.

onEventImpl
void onEventImpl(IRCEvent origEvent)

Pass on the supplied IRCEvent to module-level functions annotated with an IRCEventHandler, registered with the matching IRCEvent.Types.

this
this(IRCPluginState state)

Basic constructor for a plugin.

postprocess
void postprocess(IRCEvent event)

Lets a plugin modify an IRCEvent while it's begin constructed, before it's finalised and passed on to be handled.

initResources
void initResources()

Writes plugin resources to disk, creating them if they don't exist.

deserialiseConfigFrom
void deserialiseConfigFrom(string configFile, string[][string] missingEntries, string[][string] invalidEntries)

Loads configuration for this plugin from disk.

setSettingByName
bool setSettingByName(string setting, string value)

Change a plugin's Settings-annotated settings struct member by their string name.

printSettings
void printSettings()

Prints the plugin's Settings-annotated settings struct.

serialiseConfigInto
bool serialiseConfigInto(Appender!(char[]) sink)

Gathers the configuration text the plugin wants to contribute to the configuration file.

tick
bool tick(Duration elapsed)

Tick function. Called once every main loop iteration.

selftest
Ternary selftest(Selftester tester)

Self-test function.

name
string name()

Returns the name of the plugin. (Technically it's the name of the module.)

channelSpecificCommands
IRCPlugin.CommandMetadata[string] channelSpecificCommands(string channelName)

Compile a list of our a plugin's oneliner commands.

commands
IRCPlugin.CommandMetadata[string] commands()

Forwards to IRCPluginImpl.commandsImpl.

commandsImpl
auto commandsImpl()

Collects all IRCEventHandler.Command command words and IRCEventHandler.Regex regex expressions that this plugin offers at compile time, then at runtime returns them alongside their descriptions and their visibility, as an associative array of IRCPlugin.CommandMetadatas keyed by command name strings.

onBusMessage
void onBusMessage(string header, Sendable content)

Proxies a bus message to the plugin, to let it handle it (or not).

Inherited Members

From IRCPlugin

CommandMetadata
struct CommandMetadata

Metadata about a IRCEventHandler.Command- and/or IRCEventHandler.Regex-annotated event handler.

state
IRCPluginState state;

An IRCPluginState instance containing variables and arrays that represent the current state of the plugin. Should generally be passed by reference.

postprocess
void postprocess(IRCEvent event)

Allows a plugin to modify an event post-parsing.

onEvent
void onEvent(IRCEvent event)

Called to let the plugin react to a new event, parsed from the server.

initResources
void initResources()

Called when the plugin is requested to initialise its disk resources.

deserialiseConfigFrom
void deserialiseConfigFrom(string configFile, string[][string] missingEntries, string[][string] invalidEntries)

Reads serialised configuration text into the plugin's settings struct.

serialiseConfigInto
bool serialiseConfigInto(Appender!(char[]) sink)

Called to let the plugin contribute settings when writing the configuration file.

setSettingByName
bool setSettingByName(string setting, string value)

Called when we want to change a setting by its string name.

setup
void setup()

Called at program start but before connection has been established.

printSettings
void printSettings()

Called when we want a plugin to print its Settings-annotated struct of settings.

teardown
void teardown()

Called during shutdown of a connection; a plugin's would-be destructor.

name
string name()

Returns the name of the plugin.

commands
CommandMetadata[string] commands()

Returns an array of the descriptions of the commands a plugin offers.

channelSpecificCommands
CommandMetadata[string] channelSpecificCommands(string channelName)

Returns an array of the descriptions of the channel-specific commands a plugin offers.

reload
void reload()

Reloads the plugin, where such is applicable.

onBusMessage
void onBusMessage(string header, Sendable content)

Called when a bus message arrives from another plugin.

isEnabled
bool isEnabled()

Returns whether or not the plugin is enabled in its settings.

tick
bool tick(Duration elapsed)

Called on each iteration of the main loop.

initialise
void initialise()

Called when the plugin is first loaded.

Ternary (from std.typecons)
public import std.typecons : Ternary;
Undocumented in source.
selftest
Ternary selftest(Selftester )

Performs self-tests against another bot.

Examples

import std.conv : to;
import std.path : buildNormalizedPath;

IRCPluginState state;
state.settings.configDirectory = "conf";
state.settings.resourceDirectory = "res";
auto plugin = new UnittestPlugin(state);

assert((plugin.name == "unittest_"), plugin.name);

assert(!plugin.isEnabled);
plugin.unittestSettings.enabled = true;
assert(plugin.isEnabled);

assert((plugin.Introspection.allEventHandlerUDAsInModule.length > 2),
    plugin.Introspection.allEventHandlerUDAsInModule.length.to!string);
assert((plugin.Introspection.allEventHandlerFunctionsInModule.length > 2),
    plugin.Introspection.allEventHandlerFunctionsInModule.length.to!string);

immutable resPathWithout = buildNormalizedPath(
    plugin.state.settings.resourceDirectory,
    "unittest.delme");
immutable resPathWith = buildNormalizedPath(
    plugin.state.settings.resourceDirectory,
    "unittest",
    "unittest.delme");

assert((plugin.resFileWithoutSubdir == resPathWithout), plugin.resFileWithoutSubdir);
assert((plugin.resFileWithSubdir == resPathWith), plugin.resFileWithSubdir);

immutable confPathWithout = buildNormalizedPath(
    plugin.state.settings.configDirectory,
    "unittest.delme");
immutable confPathWith = buildNormalizedPath(
    plugin.state.settings.configDirectory,
    "unittest",
    "unittest.delme");

assert((plugin.confFileWithoutSubdir == confPathWithout), plugin.confFileWithoutSubdir);
assert((plugin.confFileWithSubdir == confPathWith), plugin.confFileWithSubdir);