formatMessageMonochrome

Formats an IRCEvent into an output range sink, in monochrome.

It formats the timestamp, the type of the event, the sender or sender alias, the channel or target, the content body, as well as auxiliary information.

version(WithPrinterPlugin)
package @safe
void
formatMessageMonochrome
(
Sink
)
(,
auto ref Sink sink
,
const ref IRCEvent event
,
const Flag!"bellOnMention" bellOnMention
,
const Flag!"bellOnError" bellOnError
)
if (
isOutputRange!(Sink, char[])
)

Parameters

plugin PrinterPlugin

Current PrinterPlugin.

sink Sink

Output range to format the IRCEvent into.

event IRCEvent

The IRCEvent that is to be formatted.

bellOnMention Flag!"bellOnMention"

Whether or not to emit a terminal bell when the bot's nickname is mentioned in chat.

bellOnError Flag!"bellOnError"

Whether or not to emit a terminal bell when an error occurred.

Examples

1 import kameloso.plugins.common.core : IRCPluginState;
2 import std.array : Appender;
3 
4 Appender!(char[]) sink;
5 
6 IRCPluginState state;
7 state.server.daemon = IRCServer.Daemon.twitch;
8 PrinterPlugin plugin = new PrinterPlugin(state);
9 
10 IRCEvent event;
11 
12 with (event.sender)
13 {
14     nickname = "nickname";
15     address = "127.0.0.1";
16     version(TwitchSupport) displayName = "Nickname";
17     //account = "n1ckn4m3";
18     class_ = IRCUser.Class.whitelist;
19 }
20 
21 event.type = IRCEvent.Type.JOIN;
22 event.channel = "#channel";
23 
24 formatMessageMonochrome(plugin, sink, event, No.bellOnMention, No.bellOnError);
25 immutable joinLine = sink.data[11..$].idup;
26 version(TwitchSupport) assert((joinLine == "[join] [#channel] Nickname"), joinLine);
27 else assert((joinLine == "[join] [#channel] nickname"), joinLine);
28 sink.clear();
29 
30 event.type = IRCEvent.Type.CHAN;
31 event.content = "Harbl snarbl";
32 
33 formatMessageMonochrome(plugin, sink, event, No.bellOnMention, No.bellOnError);
34 immutable chanLine = sink.data[11..$].idup;
35 version(TwitchSupport) assert((chanLine == `[chan] [#channel] Nickname: "Harbl snarbl"`), chanLine);
36 else assert((chanLine == `[chan] [#channel] nickname: "Harbl snarbl"`), chanLine);
37 sink.clear();
38 
39 version(TwitchSupport)
40 {
41     event.sender.badges = "broadcaster/0,moderator/1,subscriber/9";
42     //colour = "#3c507d";
43 
44     formatMessageMonochrome(plugin, sink, event, No.bellOnMention, No.bellOnError);
45     immutable twitchLine = sink.data[11..$].idup;
46     assert((twitchLine == `[chan] [#channel] Nickname [broadcaster/0,moderator/1,subscriber/9]: "Harbl snarbl"`),
47         twitchLine);
48     sink.clear();
49     event.sender.badges = string.init;
50 }
51 
52 event.type = IRCEvent.Type.ACCOUNT;
53 event.channel = string.init;
54 event.content = string.init;
55 event.sender.account = "n1ckn4m3";
56 event.aux[0] = "n1ckn4m3";
57 
58 formatMessageMonochrome(plugin, sink, event, No.bellOnMention, No.bellOnError);
59 immutable accountLine = sink.data[11..$].idup;
60 version(TwitchSupport) assert((accountLine == "[account] Nickname (n1ckn4m3)"), accountLine);
61 else assert((accountLine == "[account] nickname (n1ckn4m3)"), accountLine);
62 sink.clear();
63 
64 event.errors = "DANGER WILL ROBINSON";
65 event.content = "Blah balah";
66 event.num = 666;
67 event.count[0] = -42;
68 event.count[1] = 123;
69 event.count[5] = 420;
70 event.aux[0] = string.init;
71 event.aux[1] = "aux1";
72 event.aux[4] = "aux5";
73 event.type = IRCEvent.Type.ERROR;
74 
75 formatMessageMonochrome(plugin, sink, event, No.bellOnMention, No.bellOnError);
76 immutable errorLine = sink.data[11..$].idup;
77 version(TwitchSupport)
78 {
79     enum expected = `[error] Nickname: "Blah balah" (aux1) (aux5) ` ~
80         "{-42} {123} {420} [#666] ! DANGER WILL ROBINSON !";
81     assert((errorLine == expected), errorLine);
82 }
83 else
84 {
85     enum expected = `[error] nickname: "Blah balah" (aux1) (aux5) ` ~
86         "{-42} {123} {420} [#666] ! DANGER WILL ROBINSON !";
87     assert((errorLine == expected), errorLine);
88 }
89 //sink.clear();

Meta