agrajag/Program.cs

55 lines
1.8 KiB
C#

using ChatSharp;
using System;
using System.Configuration;
using System.Collections.Specialized;
using System.Linq;
namespace agrajag
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("starting agrajag");
NameValueCollection cfg = ConfigurationManager.AppSettings;
var client = new IrcClient(
$"{cfg.Get("irc_host")}:{cfg.Get("irc_port")}",
new IrcUser(cfg.Get("bot_nick"), cfg.Get("bot_user")),
cfg.Get("irc_ssl") == "true"
);
client.ConnectionComplete += (s, e) => {
Console.WriteLine($"connected. joining {cfg.Get("channels")}");
cfg.Get("channels")
.Split(',')
.ToList()
.ForEach(c => client.JoinChannel(c));
};
client.ChannelMessageReceived += (s, e) =>
{
var channel = client.Channels[e.PrivateMessage.Source];
if (e.PrivateMessage.Message == ".list")
channel.SendMessage(string.Join(", ", channel.Users.Select(u => u.Nick)));
else if (e.PrivateMessage.Message.StartsWith(".ban "))
{
if (!channel.UsersByMode['@'].Contains(client.User))
{
channel.SendMessage("I'm not an op here!");
return;
}
var target = e.PrivateMessage.Message.Substring(5);
client.WhoIs(target, whois => channel.ChangeMode("+b *!*@" + whois.User.Hostname));
}
};
client.ConnectAsync();
while (true) ; // Waste CPU cycles
}
}
}