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_
) {}

Parameters

debug_

Whether or not to include debugging output.

Examples

1 import kameloso.plugins.common.core : 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 lu.string : beginsWith;
58         import std.algorithm.comparison : among;
59 
60         static if (funstring.among!(
61                 "object",
62                 "dialect",
63                 "kameloso",
64                 "Message") ||
65             funstring.beginsWith("askTo"))
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 = "`MessageProxy` is missing a wrapper for `kameloso.messaging.%s`";
74             enum message = pattern.format(funstring);
75             static assert(0, message);
76         }
77     }
78 }

Meta