Skip to content

Repository files navigation

IRC Message Parser

NuGet

Description

Library containing types and parsers for IRC message, as specified in RFC 1459. Compatible with Twitch Messaging Interface (TMI).

Library provides multiple implementations of parsers, depending on the needs. Custom parsers can be implemented by implementing one of the appropriate interfaces; ICommandParser, IContentParser, ITagsParser, IPrefixParser and/or IMessageParser.

ITagsParser implementations

  • TagsParser - default implementation, validates and parses all of the message tags (both keys and values) in a dictionary. This allocates most memory.

  • LazyTagsParser - recommended if messages are expected to contain many tags, and tags are expected to be used only via the indexer. Any other behaviour of LazyTags will fall back to the default implementation and allocate whole dictionary containing all the tags. Format of the input is not validated apart from empty/null check.

ICommandParser implementations

  • CommandParser - default but slower implementation. Allows for case insensitive commands (e.g. PRIVMSG, privmsg, etc), as per the spec.

  • FastCommandParser - faster implementation using the source generated parser for the Command enum. The parsing is case-sensitive, and only all-uppercase command names or 3 digit numerics are accepted.

Example

usingSystem.Diagnostics;usingTeraa.Irc;usingTeraa.Irc.Parsing;// Recommended for Twitchvarparser=newMessageParser{TagsParser=newLazyTagsParser(),CommandParser=newFastCommandParser(),};// Parse ExamplestringrawMessage="@emote-only=0;followers-only=-1;r9k=0;slow=0;subs-only=0 :tmi.twitch.tv ROOMSTATE #channel";IMessagemessage=parser.Parse(rawMessage);Debug.Assert(message.Tagsis not null);Debug.Assert(message.Prefixis not null);Debug.Assert(message.Argis not null);Console.WriteLine(message.Tags["followers-only"]);// -1Console.WriteLine(message.Prefix.Name);// tmi.twitch.tvConsole.WriteLine(message.Command);// ROOMSTATEConsole.WriteLine(message.Arg);// #channel// ToString Examplemessage=newMessage(Command:Command.PRIVMSG,Prefix:newPrefix(Name:"nick",User:"user",Host:"host"),Arg:"#channel",Content:newContent(Text:"Hello"));rawMessage=parser.ToString(message);Console.WriteLine(rawMessage);// :nick!user@host PRIVMSG #channel :Hello

References

About

IRC Message Parser

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages