MessageCollector

MessageCollector is a feature-complete message collector with timeouts, callbacks, and filters, inspired by Discord.js. It can be used for listening to user input in seperate messages

Constructors

this
this(Channel chan, bool delegate(Message) filter, Opts[string] opts)

Class constructor.

this
this(Channel chan, bool delegate(Message) filter)

Class constructor.

Members

Functions

end
void end(Message[] messages)

End the callback.

onEnd
void onEnd(void delegate(Message[]) callback)

Set the callback to be run at the end, when this.end() is called

onMessage
void onMessage(void delegate(Message) callback)

Set the callback to be run upon each message

onMessageCreate
void onMessageCreate(MessageCreate event)

Listen for message create events, internally. This is where the bulk of the logic is. Shouldn't be overloaded or overwritten

Variables

callback
void delegate(Message) callback;

The callback to execute upon each message, as a delegate

cap
int cap;

The maximum amount of messages to listen to

chan
Channel chan;

The channel the MessageCollector is for. Only listens to messages in this channel

done
bool done;

Whether the MessageCollector is finished or not, used to track state internally

endCallback
Nullable!(void delegate(Message[]) @(safe)) endCallback;

The delegate to run when end() is called, passed to the Vibe.d timer upon creation; is @safe, but the delegate passed to onEnd does not need to be @safe, as it constructs a @trusted one from whatever's passed to it

filter
Nullable!(bool delegate(Message)) filter;

An optional (delegate) filter to check against; should return a bool, and take a Message; can be passed to the constructor. Example: m => m.author.id == 1234567890

idleTimeout
Nullable!(Duration) idleTimeout;

The time the collector should wait after a message. The collector ends, and calls the ending callback, when this time is up

idleTimeoutTimer
Nullable!(Timer) idleTimeoutTimer;

A Vibe.d Timer coresponding to the idleTimeout variable, used to track idle timeout internally - resetted after each message recieved

messages
Message[] messages;

An array of messages which is appended to every time a message is recieved, provided to the ending callback when done

messagesSoFar
long messagesSoFar;

The number of messages listened to so far, used to track state internally

timeout
Nullable!(Duration) timeout;

The time the collector should run for, represented as a Duration object. The collector ends, and calls the ending callback, when this time is up

timeoutTimer
Nullable!(Timer) timeoutTimer;

A Vibe.d timer coresponding to the timeout variable, used to track timeout internally

Inherited Members

From Plugin

bot
Bot bot;

Bot instance for this plugin. Should always be set

state
PluginState state;

Current runtime state for this plugin

__anonymous
mixin Listenable

Undocumented in source.

__anonymous
mixin Commandable

Undocumented in source.

__anonymous
mixin StateSyncable

Undocumented in source.

dynamicLibraryPath
string dynamicLibraryPath;

The path to the dynamic library this plugin was loaded from. If set, this signals this Plugin was loaded from a dynamic library, and can be reloaded from the given path.

log
Logger log()

Plugin log instance.

load
void load(Bot bot, PluginState state)

Used to load the Plugin, initially loading state if requred.

unload
void unload(Bot bot)

Used to unload the Plugin. Saves config/storage if required.

storageDirectoryPath
string storageDirectoryPath()

Returns path to this plugins storage directory.

storagePath
string storagePath()

Returns path to this plugins storage file.

configPath
string configPath()

Returns path to this plugins config file.

storage
Storage storage()

Storage instance for this plugin.

config
Storage config()

Config instance for this plugin

options
PluginOptions options()

PluginOptions for this plugin

client
Client client()

Client instance for the Bot running this plugin

me
User me()

User instance for the account this bot is running under

name
string name()

Returns the name of this plugin.

Meta