dialect 0.2.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.

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 { ... }

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

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

struct IRCUser
{
    enum Class { ... }

    Class class_;
    string nickname;
    string alias_;
    string ident;
    string address;
    string account;
    long lastWhois;  // BUG, does not belong in a bot-agnostic library

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

struct IRCServer
{
    enum Daemon { ... }
    enum CaseMapping { ... }

    string address;
    ushort port;

    // More internals
}

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

    // More internals
}

struct IRCParser
{
    IRCClient client;

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

How to use

This assumes you have a program set up to read information 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 IRCParser with an IRCClient (via constructor), and configure its members. Read a string from the server and parse it with IRCParser.toIRCEvent(string).

IRCParser parser;

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);
}

string furtherFromServer = ":kameloso^!~ident@81-233-105-99-no80.tbcn.telia.com NICK :kameloso_";
IRCEvent event3 = parser.toIRCEvent(furtherFromServer);

with (event3)
{
    assert(type == IRCEvent.Type.NICK);
    assert(sender.nickname == "kameloso^");
    assert(sender.ident == "~ident");
    assert(sender.address == "81-233-105-99-no80.tbcn.telia.com");
    assert(target.nickname = "kameloso_");
}

See the /tests directory for more example parses.

Roadmap

  • remove final non-bot-agnostic remnants

License

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

Authors:
  • JR
Dependencies:
lu:core, lu:meld
Versions:
0.2.1 2019-Sep-15
0.2.0 2019-Sep-15
0.1.0 2019-Sep-12
0.0.3 2019-Sep-07
0.0.2 2019-Sep-05
Show all 8 versions
Download Stats:
  • 7 downloads today

  • 114 downloads this week

  • 174 downloads this month

  • 174 downloads total

Score:
1.5
Short URL:
dialect.dub.pm