IRCParser

Parser that takes raw IRC strings and produces IRCEvents based on them.

Parsing requires state, which means that IRCParsers must be equipped with a IRCServer and a IRCClient for context when parsing. Because of this it has its postblit @disabled, so as not to make copies when only one instance should exist.

The alternative is to make it a class, which works too.

See the /tests directory for unit tests.

Constructors

this
this(IRCClient client, IRCServer server)

Create a new IRCParser with the passed IRCClient and IRCServer as base context for parsing.

Postblit

this(this)
this(this)

Disallow copying of this struct.

Members

Enums

Update
enum Update

Bitfield enum of what member of an instance of IRCParser was updated (if any).

Functions

clientUpdated
void clientUpdated(bool updated)

Wrapper for backwards compatibility with pre-bitfield update-signaling.

clientUpdated
bool clientUpdated()

Wrapper for backwards compatibility with pre-bitfield update-signaling.

initPostprocessors
void initPostprocessors()

Initialises defined postprocessors.

serverUpdated
bool serverUpdated()

Wrapper for backwards compatibility with pre-bitfield update-signaling.

serverUpdated
void serverUpdated(bool updated)

Wrapper for backwards compatibility with pre-bitfield update-signaling.

toIRCEvent
auto toIRCEvent(string raw)

Parses an IRC string into an IRCEvent.

Variables

client
IRCClient client;

The current IRCClient with all the context needed for parsing.

postprocessors
Postprocessor[] postprocessors;

Array of active Postprocessors, to be iterated through and processed after parsing is complete.

server
IRCServer server;

The current IRCServer with all the context needed for parsing.

typenums
IRCEvent.Type[1024] typenums;

An dialect.defs.IRCEvent.Type[1024] reverse lookup table for fast numeric lookups.

updates
Update updates;

Bitfield of in what way the parser's internal state was altered during parsing.

Examples

IRCClient client;
client.nickname = "...";

IRCServer server;
server.address = "...";

IRCParser parser = IRCParser(client, server);

string fromServer = ":zorael!~NaN@address.tld MODE #channel +v nickname";
IRCEvent event = parser.toIRCEvent(fromServer);

with (event)
{
    assert(type == IRCEvent.Type.MODE);
    assert(sender.nickname == "zorael");
    assert(sender.ident == "~NaN");
    assert(sender.address == "address.tld");
    assert(target.nickname == "nickname");
    assert(channel == "#channel");
    assert(aux[0] = "+v");
}

string alsoFromServer = ":cherryh.freenode.net 435 oldnick newnick #d :Cannot change nickname while banned on channel";
IRCEvent event2 = parser.toIRCEvent(alsoFromServer);

with (event2)
{
    assert(type == IRCEvent.Type.ERR_BANONCHAN);
    assert(sender.address == "cherryh.freenode.net");
    assert(channel == "#d");
    assert(target.nickname == "oldnick");
    assert(content == "Cannot change nickname while banned on channel");
    assert(aux[0] == "newnick");
    assert(num == 435);
}

// Requires Twitch support via build configuration "twitch"
string fullExample = "@badge-info=subscriber/15;badges=subscriber/12;color=;display-name=SomeoneOnTwitch;emotes=;flags=;id=d6729804-2bf3-495d-80ce-a2fe8ed00a26;login=someoneontwitch;mod=0;msg-id=submysterygift;msg-param-mass-gift-count=1;msg-param-origin-id=49\\s9d\\s3e\\s68\\sca\\s26\\se9\\s2a\\s6e\\s44\\sd4\\s60\\s9b\\s3d\\saa\\sb9\\s4c\\sad\\s43\\s5c;msg-param-sender-count=4;msg-param-sub-plan=1000;room-id=71092938;subscriber=1;system-msg=someoneOnTwitch\\sis\\sgifting\\s1\\sTier\\s1\\sSubs\\sto\\sxQcOW's\\scommunity!\\sThey've\\sgifted\\sa\\stotal\\sof\\s4\\sin\\sthe\\schannel!;tmi-sent-ts=1569013433362;user-id=224578549;user-type= :tmi.twitch.tv USERNOTICE #xqcow"
IRCEvent event4 = parser.toIRCEvent(fullExample);

with (event)
{
    assert(type == IRCEvent.Type.TWITCH_BULKGIFT);
    assert(sender.nickname == "someoneontwitch");
    assert(sender.displayName == "SomeoneOnTwitch");
    assert(sender.badges == "subscriber/12");
    assert(channel == "#xqcow");
    assert(content == "SomeoneOnTwitch is gifting 1 Tier 1 Subs to xQcOW's community! They've gifted a total of 4 in the channel!");
    assert(aux[0] == "1000");
    assert(count[0] == 1);
    assert(count[1] == 4);
}