dialect 0.2.1
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
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.
- 0.2.1 released 5 years ago
- zorael/dialect
- MIT
- Copyright © 2019, JR
- Authors:
- Dependencies:
- lu:core, lu:meld
- 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 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
25095 downloads total
-
- Score:
- 0.7
- Short URL:
- dialect.dub.pm