MessagingProxy

Mixin to give shorthands to the functions in kameloso.messaging, for easier use when in a with (plugin) { /* ... */ } scope.

This merely makes it possible to use commands like raw("PING :irc.freenode.net") without having to import kameloso.messaging and include the thread ID of the main thread in every call of the functions.

mixin template MessagingProxy (
Flag!"debug_" debug_ = No.debug_
) {
version(unittest)
private
static if(!is(typeof(this) : IRCPlugin))
enum wrongThisPattern;
version(unittest)
private
static if(!is(typeof(this) : IRCPlugin))
enum wrongThisMessage;
}

Members

Aliases

immediateline
alias immediateline = immediate

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

Functions

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

Sends a channel message.

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

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

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

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

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.

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

Sets a channel mode.

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

Leaves a channel.

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.

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

Sends a private query message to a user.

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

Disconnects from the server, optionally with a quit reason.

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

Sends text to the server, verbatim.

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

Replies to a channel message.

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

Sets the topic of a channel.

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

Queries the server for WHOIS information about a user.

Manifest constants

hasMessagingProxy
enum hasMessagingProxy;

Flag denoting that MessagingProxy has been mixed in.

Parameters

debug_

Whether or not to include debugging output.

Examples

1 import kameloso.plugins.common : IRCPlugin, IRCPluginImpl, IRCPluginState;
2 
3 class MyPlugin : IRCPlugin
4 {
5     mixin MessagingProxy;
6     mixin IRCPluginImpl;
7 }
8 
9 IRCPluginState state;
10 MyPlugin plugin = new MyPlugin(state);
11 
12 with (plugin)
13 {
14     // The below calls will fail in-contracts, so don't call them.
15     // Just generate the code so we know they compile.
16     if (plugin !is null) return;
17 
18     /*chan(string.init, string.init);
19     query(string.init, string.init);
20     privmsg(string.init, string.init, string.init);
21     emote(string.init, string.init);
22     mode(string.init, string.init, string.init);
23     topic(string.init, string.init);
24     invite(string.init, string.init);
25     join(string.init, string.init);
26     kick(string.init, string.init, string.init);
27     part(string.init, string.init);
28     quit(string.init);
29     enum whoisProperties = (Message.Property.forced | Message.Property.quiet);
30     whois(string.init, whoisProperties);
31     raw(string.init);
32     immediate(string.init);
33     immediateline(string.init);*/
34     askToWriteln(string.init);
35     askToTrace(string.init);
36     askToLog(string.init);
37     askToInfo(string.init);
38     askToWarn(string.init);
39     askToWarning(string.init);
40     askToError(string.init);
41 }
42 
43 class MyPlugin2 : IRCPlugin
44 {
45     mixin MessagingProxy fromMixin;
46     mixin IRCPluginImpl;
47 }
48 
49 static if (__VERSION__ >= 2097L)
50 {
51     static import kameloso.messaging;
52 
53     MyPlugin2 plugin2 = new MyPlugin2(state);
54 
55     foreach (immutable funstring; __traits(derivedMembers, kameloso.messaging))
56     {
57         import std.algorithm.comparison : among;
58         import std.algorithm.searching : startsWith;
59 
60         static if (funstring.among!(
61                 "object",
62                 "dialect",
63                 "kameloso",
64                 "Message") ||
65             funstring.startsWith("ask"))
66         {
67             //pragma(msg, "ignoring " ~ funstring);
68         }
69         else static if (!__traits(compiles, { mixin("alias _ = plugin2.fromMixin." ~ funstring ~ ";"); }))
70         {
71             import std.format : format;
72 
73             enum pattern = "`MessagingProxy` is missing a wrapper for `kameloso.messaging.%s`";
74             enum message = pattern.format(funstring);
75             static assert(0, message);
76         }
77     }
78 }