static void Main(string[] args) { Markov Bot = new Markov(); //* Bot.LoadAuxiliaries("Auxiliaries.txt"); Bot.LoadBanList("Bans.txt"); Bot.LoadSwapList("Swaps.txt"); Bot.Train("Training.txt"); Bot.SaveBrain("BRAIN"); /*/ * Bot.LoadBrain("BRAIN"); * //*/ while (true) { Console.Write("> "); String Text = null; while (Text == null) { Text = Console.ReadLine(); } Console.WriteLine(Bot.GenerateReply(Text)); } }
static void Main(string[] args) { Markov bot = new Markov(); //* var sw = Stopwatch.StartNew(); bot.LoadAuxiliaries("../../Files/Auxiliaries.txt"); sw.Stop(); Console.WriteLine($"Auxiliaries {sw.Elapsed.TotalMilliseconds.ToString("N0")} ms"); sw = Stopwatch.StartNew(); bot.LoadBanList("../../Files/Bans.txt"); sw.Stop(); Console.WriteLine($"Bans {sw.Elapsed.TotalMilliseconds.ToString("N0")} ms"); sw = Stopwatch.StartNew(); bot.LoadSwapList("../../Files/Swaps.txt"); sw.Stop(); Console.WriteLine($"Swaps {sw.Elapsed.TotalMilliseconds.ToString("N0")} ms"); sw = Stopwatch.StartNew(); bot.Train("../../Files/Training.txt"); sw.Stop(); Console.WriteLine($"Training {sw.Elapsed.TotalMilliseconds.ToString("N0")} ms"); sw = Stopwatch.StartNew(); bot.SaveBrain("../../Files/BRAIN.dat"); sw.Stop(); Console.WriteLine($"BRAIN {sw.Elapsed.TotalMilliseconds.ToString("N0")} ms"); /*/ * Bot.LoadBrain("../../Files/BRAIN.dat"); * //*/ while (true) { Console.Write("> "); String text = null; while (text == null) { text = Console.ReadLine(); } Console.WriteLine(bot.GenerateReply(text)); } }
static void Main(string[] args) { Console.WriteLine("Loading Brain"); Markov Markov = new Markov(); Markov.LoadBrain("BRAIN"); Console.WriteLine("Brain Loaded. Auditing..."); if (!Markov.Audit()) { throw new InvalidOperationException("Audit Failed"); } Console.WriteLine("Audit Passed. Connecting to server..."); IrcClient Client = new IrcClient(); // *** MAIN PROCESSING EventHandler <IrcMessageEventArgs> Replier = delegate(Object Sender, IrcMessageEventArgs Event) { IrcChannel Channel = (IrcChannel)Sender; TextInfo TI = new CultureInfo("en-CA", false).TextInfo; if (Event.Text.ToLower() == "!exit" && Event.Source.Name.ToLower() == "sukasa") { Client.Quit("*DEAD*"); Client.Disconnect(); } else { Byte[] Value = new Byte[1]; RNG.GetBytes(Value); if ((Value[0] >= 245 || Event.Text.ToLower().Contains("kbot"))) { String Reply = DoCapitalization(Markov.GenerateReply(Event.Text)); Client.LocalUser.SendMessage(Channel.Name, Reply); } Markov.Learn(Event.Text); } }; IrcUserRegistrationInfo RegInfo = new IrcUserRegistrationInfo(); RegInfo.NickName = "kBot"; RegInfo.UserName = "******"; RegInfo.RealName = "4th order Markov chain bot"; Uri ServerAddress = new Uri("irc://irc.irchighway.net:6667"); using (var connectedEvent = new ManualResetEventSlim(false)) { Client.Connected += (sender2, e2) => connectedEvent.Set(); Client.Connect(ServerAddress, RegInfo); if (!connectedEvent.Wait(10000)) { Client.Dispose(); Console.WriteLine("Connection to {0} timed out.", ServerAddress); return; } Console.WriteLine("Connected to {0}.", ServerAddress); // *** POST-INIT Client.MotdReceived += delegate(Object Sender, EventArgs E) { Console.WriteLine("Joining Channels..."); Client.Channels.Join("#la-mulana"); }; // *** DEBUG OUTPUT Client.RawMessageReceived += delegate(Object Sender, IrcRawMessageEventArgs Event) { Console.WriteLine(Event.RawContent); }; // *** PING Client.PingReceived += delegate(Object Sender, IrcPingOrPongReceivedEventArgs Event) { Console.WriteLine("Ping Pong"); Client.Ping(Event.Server); }; // *** CHANNEL JOINING Client.LocalUser.JoinedChannel += delegate(Object Sender, IrcChannelEventArgs Event) { Event.Channel.MessageReceived += Replier; }; // *** MESSAGE ECHOING Client.RawMessageSent += delegate(Object Sender, IrcRawMessageEventArgs Event) { Console.WriteLine(Event.RawContent); }; // *** ERROR REPORTING Client.Error += delegate(Object Sender, IrcErrorEventArgs Event) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Event.Error.Message); Console.ForegroundColor = ConsoleColor.Gray; }; // *** ERROR REPORTING Client.ErrorMessageReceived += delegate(Object Sender, IrcErrorMessageEventArgs Event) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Event.Message); Console.ForegroundColor = ConsoleColor.Gray; }; // *** ERROR REPORTING Client.ProtocolError += delegate(Object Sender, IrcProtocolErrorEventArgs Event) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(Event.Message); Console.ForegroundColor = ConsoleColor.Gray; }; // *** REJOIN AFTER KICK Client.LocalUser.LeftChannel += delegate(Object Sender, IrcChannelEventArgs Event) { Client.Channels.Join(Event.Channel.Name); }; Int32 Counter = 0; while (Client.IsConnected) { Thread.Sleep(5); if (++Counter == 12000) { Console.Write("Manual Ping "); Client.Ping(); Counter = 0; } while (Console.KeyAvailable) { if (Console.ReadKey().Key == ConsoleKey.Delete) { Client.Disconnect(); } } } Console.WriteLine("Saving Brain"); Markov.SaveBrain("BRAIN"); } }