protected void Connect(string server, IrcRegistrationInfo registrationInfo) { // Create new IRC client and connect to given server. var client = new StandardIrcClient(); client.FloodPreventer = new IrcStandardFloodPreventer(4, 2000); client.Connected += IrcClient_Connected; client.Disconnected += IrcClient_Disconnected; client.Registered += IrcClient_Registered; // Wait until connection has succeeded or timed out. using (var connectedEvent = new ManualResetEventSlim(false)) { client.Connected += (sender2, e2) => connectedEvent.Set(); client.Connect(server, false, registrationInfo); if (!connectedEvent.Wait(10000)) { client.Dispose(); ConsoleUtilities.WriteError("Connection to '{0}' timed out.", server); return; } } // Add new client to collection. this.allClients.Add(client); Console.Out.WriteLine("Now connected to '{0}'.", server); }
public static void Main(string[] args) { IrcBot bot = null; try { // Write information about program. Console.WriteLine(ProgramInfo.AssemblyTitle); Console.WriteLine("Version {0}", ProgramInfo.AssemblyVersion); Console.WriteLine(ProgramInfo.AssemblyCopyright); Console.WriteLine(); // Create and run bot. bot = new MarkovChainTextBot(); bot.Run(); } #if !DEBUG catch (Exception ex) { ConsoleUtilities.WriteError("Fatal error: " + ex.Message); } #endif finally { if (bot != null) { bot.Dispose(); } } }
private void ReadCommand(string command, IList <string> parameters) { CommandProcessor processor; if (this.commandProcessors.TryGetValue(command, out processor)) { try { processor(command, parameters); } catch (Exception ex) { ConsoleUtilities.WriteError("Error: {0}", ex.Message); } } else { ConsoleUtilities.WriteError("Command '{0}' not recognized.", command); } }