c# port of irctokens https://irctokens.hmm.st
Go to file
Ben Harris 933a4f8560
continuous-integration/drone/push Build is passing Details
rename to IrcSharp
also tidy up formatting with vs tools
2020-04-22 16:28:51 -04:00
IrcStates rename to IrcSharp 2020-04-22 16:28:51 -04:00
IrcTokens rename to IrcSharp 2020-04-22 16:28:51 -04:00
Sample rename to IrcSharp 2020-04-22 16:28:51 -04:00
StatesSample rename to IrcSharp 2020-04-22 16:28:51 -04:00
.drone.yml add drone config 2020-04-22 11:43:27 -04:00
.editorconfig rename to IrcSharp 2020-04-22 16:28:51 -04:00
.gitignore init 2020-04-19 23:14:41 -04:00
IrcSharp.sln rename to IrcSharp 2020-04-22 16:28:51 -04:00
LICENSE init 2020-04-19 23:14:41 -04:00
README.md add build status badge 2020-04-22 11:50:50 -04:00

README.md

irctokens

Build Status

this is a c# port of jesopo's irctokens

usage

tokenization

using IrcTokens;

...

var line = new Line("@id=123 :ben!~ben@host.tld PRIVMSG #channel :hello there!");
Console.WriteLine(line);
Console.WriteLine(line.Format());

formatting

var line = new Line {Command = "USER", Params = new List<string> {"user", "0", "*", "real name"}};
Console.WriteLine(line);
Console.WriteLine(line.Format());

stateful

see the full example in Sample/Client.cs

public class Client
{
    private readonly Socket _socket;
    private readonly StatefulDecoder _decoder;
    private readonly StatefulEncoder _encoder;
    private readonly byte[] _bytes;

    public Client()
    {
        _decoder = new StatefulDecoder();
        _encoder = new StatefulEncoder();
        _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
        _bytes = new byte[1024];
    }

    public void Start()
    {
        _socket.Connect("127.0.0.1", 6667);

        Send(new Line {Command = "USER", Params = new List<string> {"username", "0", "*", "real name"}});
        Send(new Line {Command = "NICK", Params = new List<string> {"statefulbot"}});

        while (true)
        {
            var bytesReceived = _socket.Receive(_bytes);
            var lines = _decoder.Push(_bytes);

            if (lines.Count == 0)
            {
                Console.WriteLine("! disconnected");
                _socket.Shutdown(SocketShutdown.Both);
                break;
            }

            foreach (var line in lines)
            {
                Console.WriteLine($"< {line.Format()}");

                switch (line.Command)
                {
                    case "PING":
                        Send(new Line {Command = "PONG", Params = line.Params});
                        break;
                    case "001":
                        Send(new Line {Command = "JOIN", Params = new List<string> {"#channel"}});
                        break;
                }
            }
        }
    }

    private void Send(Line line)
    {
        Console.WriteLine($"> {line.Format()}");
        _encoder.Push(line);
        while (_encoder.PendingBytes.Length > 0)
            _encoder.Pop(_socket.Send(_encoder.PendingBytes));
    }
}

contact

come say hi on #irctokens on irc.tilde.chat