dialect 0.0.3

IRC parsing library


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

Manual usage
Put the following dependency into your project's dependences section:

dialect CircleCI Linux/OSX Travis Linux/OSX and documentation 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.

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;

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

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

    string address;
    ushort port;

    // More internals
}

struct IRCClient
{
    version(RichClient)  // dub configuration "rich"
    {
        string nickname;
        string user;
        string ident;
        string realName;
        string quitReason;
        string account;
        string password;
        string pass;

        IRCServer server;

        version(TwitchSupport)  // dub configuration "twitch"
        {
            string colour;
        }

        // More internals
    }
    else  // dub configuration "simple" (default)
    {
        string nickname;
        IRCServer server;

        // More internals
    }

    version(FlagUpdatedClient)
    {
        bool updated;
    }
}

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 and configure its members, notably its .client. 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

  • investigate @nogc
  • fix AppVeyor failing to build lu:core

License

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

Authors:
  • JR
Dependencies:
lu:core
Versions:
3.0.0 2024-Aug-11
2.2.0 2024-Jan-27
2.1.0 2024-Jan-05
2.0.4 2023-Aug-19
2.0.3 2023-Jun-25
Show all 47 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 25095 downloads total

Score:
0.7
Short URL:
dialect.dub.pm