static void Main(string[] args) { var settings = Properties.Settings.Default; ircClient = new IrcClient(settings.IrcServer, new IrcUser(settings.IrcNick, settings.IrcNick)); ircClient.ConnectionComplete += (s, e) => ircClient.JoinChannel(settings.IrcChannel); ircClient.ConnectAsync(); Uri baseAddress = new Uri("net.pipe://localhost"); using (ServiceHost host = new ServiceHost(typeof(Program), baseAddress)) { host.AddServiceEndpoint(typeof(IBotService), new NetNamedPipeBinding(), "BotService"); host.Open(); Console.WriteLine("TfsBot {0} started...", Application.ProductVersion); Console.WriteLine("Press <Enter> to stop the bot."); Console.ReadLine(); host.Close(); } ircClient.Quit("Shutdown..."); }
// Start the bot public IRCBot() { // Load the settings if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/settings.json")) settings = Utils.Load<Settings>(); else Utils.Save(ref settings); // Load the words if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/words.json")) words = Utils.Load<Words>(); else Utils.Save(ref words); // Load the seen_tells' if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/seen_tell.json")) seenTell = Utils.Load<Seen_Tell>(); else Utils.Save(ref seenTell); /* // Load the aliase if (File.Exists(Directory.GetCurrentDirectory() + "/Settings/alias.json")) alias = Utils.Load<Alias>(); else Utils.Save(ref alias); */ // Create the randomizer BaseUtils.random = new Random(); // Startup BaseUtils.LogSpecial(settings.name + " - a friendly IRC bot!"); // Connection client = new IrcClient(settings.host, new IrcUser(settings.name, settings.name)); client.ConnectionComplete += (s, e) => { client.SendMessage("identify " + settings.pw, new[] { "NickServ" }); settings.channels.ForEach(c => client.JoinChannel(c)); }; client.ChannelMessageRecieved += Client_ChannelMessageRecieved; client.UserKicked += Client_UserKicked; //client.NickChanged += Client_NickChanged; client.ConnectAsync(); AppDomain.CurrentDomain.ProcessExit += (s, e) => { client.Quit(); BaseUtils.Writer().WriteLine("[Stop] ============ " + DateTime.UtcNow.ToShortDateString() + " " + DateTime.UtcNow.ToLongTimeString() + " ============"); BaseUtils.Writer().Close(); }; // Stop GC GC.KeepAlive(this); }