Skip to content

Instantly share code, notes, and snippets.

@txdv
Created July 1, 2011 07:21
Show Gist options
  • Save txdv/1058034 to your computer and use it in GitHub Desktop.
Save txdv/1058034 to your computer and use it in GitHub Desktop.
A showcase how to create an IRC bot with a web frontend (all in 1 thread)
using System;
using System.Collections;
using System.Collections.Generic;
// Modified version of SmartIrc4Net available at: https://github.com/txdv/smartirc4net
using Meebey.SmartIrc4net;
using Manos.Http;
public class Test
{
public static void Main(string[] args)
{
var context = Manos.IO.Managed.Context.Create();
IrcClient irc = new IrcClient(context, context.CreateSocket());
irc.OnReadLine += delegate(object sender, ReadLineEventArgs e) {
Console.WriteLine("<= {0}", e.Line);
};
irc.OnWriteLine += delegate(object sender, WriteLineEventArgs e) {
Console.WriteLine("=> {0}", e.Line);
};
irc.OnJoin += delegate(object sender, JoinEventArgs e) {
Console.WriteLine(" ----> O my god, {0} just did something", e.Who);
};
irc.Connect("213.161.196.11", 6667, delegate {
irc.Login("TestRobot", "TestRobot");
irc.RfcJoin("#six");
irc.RfcJoin("#ruby");
});
HttpServer server = new HttpServer(context, delegate (IHttpTransaction transaction) {
var res = transaction.Response;
foreach (var chan in irc.JoinedChannels) {
res.WriteLine(chan);
}
res.End();
}, context.CreateSocket(), true);
server.Listen("127.0.0.1", 8082);
context.Start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment