dialect 0.3.1

IRC parsing library


To use this package, run the following command in your project's root directory:

dialect CircleCI Linux/OSX Travis Linux/OSX and documentation Windows GitHub commits since last release

IRC parsing library with support for a wide variety of server daemons.

It uses exceptions to signal errors during parsing, so it's not nothrow. Some parts of it create new strings, so it can't be @nogc. It is however pure and @safe with the default "library" build configuration.

Note that while IRC is standardised, servers still come in many flavours, some of which outright conflict with others. If something doesn't immediately work, generally it's because we simply haven't encountered that type of event before, and so no rules for how to parse it have yet been written.

Used in the kameloso bot. However, while dialect unavoidably caters to its needs, it is independent from it. Likely some remnants of code that violate separation of concern still exist, and they are to be considered bugs.

Please report bugs. Unreported bugs can only be fixed by accident.

What it looks like

API documentation can be found here.

struct IRCEvent
{
    enum Type { ... }  // large enum of IRC event types

    Type type;
    string raw;
    IRCUser sender;
    IRCUser target;
    string channel;
    string content;
    string aux;
    string tags;
    uint num;
    int count;
    int altcount;
    long time;
    string errors;

    version(TwitchSupport)
    {
        string emotes;
        string id;
    }
}

struct IRCUser
{
    string nickname;
    string ident;
    string address;
    string account;

    version(TwitchSupport)
    {
        string displayName;
        string badges;
        string colour;
    }
}

struct IRCChannel
{
    struct Mode { ... }

    string name;
    Mode[] modes
    string modechars;
    string topic;
    string[][char] mods;
    bool[string] users;
}

struct IRCServer
{
    enum Daemon { ... }

    string address;
    ushort port;

    // More internals
}

struct IRCClient
{
    string nickname;
    string user;
    string ident;
    string realName;

    // More internals
}

struct IRCParser
{
    IRCClient client;
    IRCServer server;
    this(IRCClient, IRCServer);

    IRCEvent toIRCEvent(const string);  // <--
}

How to use

This assumes you have a program set up to read from an IRC server. This is not a bot framework; for that you're better off with the full kameloso and writing a plugin that suits your needs.

  • Instantiate an IRCClient and configure its members. (required for context when parsing)
  • Instantiate an IRCServer and configure its members. (it may work without but just give it a host address)
  • Instantiate an IRCParser with your client and server via constructor. Pass it by ref if passed around between functions.
  • Read a string from the server and parse it into an IRCEvent with yourParser.toIRCEvent(string).
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 = "+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 == "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 == "1000");
    assert(count == 1);
    assert(altcount == 4);
}

See the /tests directory for more example parses.

Roadmap

  • detect and remove final non-bot-agnostic remnants

Built with

License

This project is licensed under the MIT license - see the LICENSE file for details.

Authors:
  • JR
Dependencies:
lu:core, lu:meld
Versions:
0.3.1 2019-Oct-07
0.3.0 2019-Sep-28
0.2.1 2019-Sep-15
0.2.0 2019-Sep-15
0.1.0 2019-Sep-12
Show all 11 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 22 downloads this month

  • 562 downloads total

Score:
0.6
Short URL:
dialect.dub.pm