private void connect() { // Tell people we're going to connect Console.WriteLine("Connecting to " + ircServer + ":" + ircPort + " ...\n"); try { // Try to make a connection to the server ircClient = new TcpClient(ircServer, ircPort); stream = ircClient.GetStream(); reader = new StreamReader(stream); writer = new StreamWriter(stream); readerStreamClosed = false; // We're connected, so let's set our bool to true. setConnectionState(true); // Let the ping control know we can ping now. setCanPing(true); // Set the current ping attempt to 0. Really useful for when the bot has to reconnect for any reason. pongAttempt = 0; // Start up our incoming data listener IncomingData(); // Authorize who we are. authorize(); // Let's turn on the AI stuff. myAI = new AI(); if (AIML == true) { myAIML = new AIMLbrain(); } if (LB == true) { myLB = new LBbrain(); } Thread.Sleep(1500); // Auto join the channel, if there is one if (channel != "") { Thread.Sleep(500); join(channel); } } catch (Exception e) { // Show the exception DisplayData("ERROR: " + e.ToString()); setConnectionState(false); } Thread.Sleep(1000); // Let's turn on the twitter client, if it needs to be turned on. if (useTwitter) { twitterClientOn = true; Thread.Sleep(500); sendInitialTwitterMessage(); } }
private void userCommand(string command, string commandParam, string nick, string location) { #region All Level Commands if (command == "!SPLASH") { Thread.Sleep(1000); // throttle it so it won't commit a flood if tons of people use it. sendToChannel("Kon Splash!", location); Console.WriteLine(">> " + channel + " : Kon Splash!"); } // Haiku!. if (command == "!HAIKU") { if (LB) { String inputMessage = ""; if (commandParam != "") { string[] messageLine = commandParam.Split(new char[] { ' ' }); int msgLength = messageLine.Length - 1; for (int i = 1; i <= msgLength; i++) { inputMessage = inputMessage + messageLine[i] + " "; } } inputMessage = inputMessage.Trim(); string haiku = LBbrain.generateHaiku(inputMessage); sendToChannel(haiku, location); } else { sendToChannel("4LB Brain not active and the Haiku cannot be generated", location); } } if (command == "!BRAININFO") { sendToChannel("My brain contains " + myAI.getBrainLength() + " lines.", location); } if (command == "!LBINFO") { if (LB) { sendToChannel("My LB brain contains " + myLB.getBrainLength() + " lines.", location); } else { sendToChannel("4LB Brain must be turned on in order to use this command.", location); } } if (command == "!KONINFO") { sendToChannel(version, location); } #endregion #region User Level Commands if (command == "!RELOADAIML") { if ((isUser(nick)) || (isAdmin(nick))) { if (AIML) { sendToChannel("4Reloading AIML..please wait before using any commands..", location); Console.WriteLine(">> RELOADING AI"); AIMLbrain.unloadAIMLbrain(); myAIML = null; myAIML = new AIMLbrain(); // Let's put the thread to sleep while it's reloading. Thread.Sleep(1300); sendToChannel("2AI Reloaded!", location); } else { sendToChannel("4The AIML brain is not currently in use.", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!TOGGLEAIML") { if ((isUser(nick)) || (isAdmin(nick))) { if (AIML) { AIML = false; AIMLbrain.unloadAIMLbrain(); myAIML = null; sendToChannel("4No longer using AIML for replies...", location); } else { AIML = true; LB = false; sendToChannel("4Loading AIML files..please wait before using any commands..", location); myAIML = new AIMLbrain(); sendToChannel("4Now using AIML in addition to my brain for replies...", location); myLB = null; } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!TOGGLELB") { if ((isUser(nick)) || (isAdmin(nick))) { if (LB) { LB = false; sendToChannel("4No longer using the LB Brain for replies...", location); myLB = null; } else { LB = true; AIML = false; sendToChannel("4Now using the LB Brain in addition to my brain for replies...", location); myAIML = null; myLB = new LBbrain(); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!CHANNELUSERS") { if ((isUser(nick)) || (isAdmin(nick))) { sendToChannel(channelUsers, location); } else { sendToChannel("4You do not have access to this command.", location); } } //Private UTTER.. will send a random channel user a message if (command == "!PUTTER") { if ((isUser(nick)) || (isAdmin(nick))) { converse(location, "a", randomChannelUser()); } else { sendToChannel("4You do not have access to this command.", location); } } // Regular UTTER.. will send a random message to the location the command was used if (command == "!UTTER") { if ((isUser(nick)) || (isAdmin(nick))) { converse(location, "thisisanutteryoushouldnthaveanylinesthatmatchthisstufflol", nick); } else { sendToChannel("4You do not have access to this command.", location); } } // Total nonsense... won't try to generate coherent sentences. if (command == "!TOTALNONSENSE") { if ((isUser(nick)) || (isAdmin(nick))) { string nonsense = LBbrain.totalNonsense(); sendToChannel(nonsense, location); } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!JOIN") { if ((isUser(nick)) || (isAdmin(nick))) { join(commandParam); } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!PART") { if ((isUser(nick)) || (isAdmin(nick))) { // Get the channel and leave part(commandParam); } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!TOGGLETOPIC") { if ((isUser(nick)) || (isAdmin(nick))) { if (topics) { topics = false; sendToChannel("4I will no longer try to locate the topic in what you say to me.", location); } else { topics = true; sendToChannel("4I will now try to locate the topic in what you say to me.", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!TOGGLECOPYANSWER") { if ((isUser(nick)) || (isAdmin(nick))) { if (useAnswerLine == false) { useAnswerLine = true; sendToChannel("4I will reply with answers I find.", location); } else { useAnswerLine = false; sendToChannel("4I will now stop replying with direct answers I find.", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!TOGGLEDOUBLESENTENCES") { if ((isUser(nick)) || (isAdmin(nick))) { if (doubleSentences) { doubleSentences = false; sendToChannel("4I will no longer try to combine two sentences.", location); } else { doubleSentences = true; sendToChannel("4I will now try to combine two sentences together.", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!TOGGLEANSWERSEARCH") { if ((isUser(nick)) || (isAdmin(nick))) { if (answerSearch) { answerSearch = false; sendToChannel("4I will no longer try to find appropriate answers.", location); } else { answerSearch = true; sendToChannel("4I will now try to find approprate answers.", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!RANDOMTALK") { if ((isUser(nick)) || (isAdmin(nick))) { if ((commandParam != "") && (commandParam != " ")) { int randomTalkP; try { randomTalkP = System.Convert.ToInt32(commandParam); } catch (Exception e) { sendToChannel("4!randomTalk # where # is 1 to 100", location); randomTalkP = randomTalk; Console.WriteLine("Error: " + e.ToString()); } randomTalk = randomTalkP; sendToChannel("3RandomTalk now set to: " + randomTalk + "%", location); Console.WriteLine("** Random Talk changed to: " + randomTalk + "%"); } else { sendToChannel("3RandomTalk is currently set to: " + randomTalk + "%", location); Thread.Sleep(100); sendToChannel("3To change the percent use: !randomTalk # where # is 0 to 100", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!DINFO") { // For now, the nicks allowed to use this will be hardcoded if ((isUser(nick)) || (isAdmin(nick))) { sendToChannel("Reconnects: " + reconnectAttempts + "/" + retryAttempts + " :: PING control is currently: " + canPing + " :: Ping Attempt #: " + pongAttempt, location); } else { sendToChannel("4You do not have access to this command.", location); } } // Returns the latest Twitter status update, if applicable. if (command == "!TWITTER") { if ((isUser(nick)) || (isAdmin(nick))) { if (twitterClientOn) { try { if (twitterMessage != "") { sendToChannel("Current tweet:2 " + twitterMessage, location); } else { sendToChannel("4Twitter is either disabled or there are no messages to display.", location); } } catch (Exception e) { sendToChannel("4Twitter Client is not enabled or error encountered.", location); Console.WriteLine(e.ToString()); } } else { sendToChannel("Twitter Client is not enabled or error encountered.", location); } } else { sendToChannel("4You do not have access to this command.", location); } } #endregion #region Admin Level Commands if (command == "!QUIT") { // For now, the nicks allowed to use this will be hardcoded if (isAdmin(nick)) { writer.WriteLine("QUIT " + ":" + version); writer.Flush(); Console.WriteLine("Kon can now be closed"); Thread.Sleep(500); quit_program(); } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!ADDUSER") { // For now, the nicks allowed to use this will be hardcoded if (isAdmin(nick)) { if ((commandParam == " ") || (commandParam == "")) { sendToChannel("4A name must be attached to this command. !addUser (name)", location); } else { addUser(commandParam); sendToChannel(commandParam + " added to the list of users", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!REMUSER") { // For now, the nicks allowed to use this will be hardcoded if (isAdmin(nick)) { if ((commandParam == " ") || (commandParam == "")) { sendToChannel("4A name must be attached to this command. !addUser (name)", location); } else { remUser(commandParam); sendToChannel(commandParam + " removed from the list of users", location); } } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!RECONNECT") { // For now, the nicks allowed to use this will be hardcoded if (isAdmin(nick)) { writer.WriteLine("QUIT :Reconnecting"); writer.Flush(); Thread.Sleep(100); setConnectionState(false); } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!RAW") { if (isAdmin(nick)) { string[] IncomingMessage; IncomingMessage = commandParam.Split(new char[] { ' ' }); int messageStartingPoint = 1; if (IncomingMessage.Length < 1) { sendToChannel("4Error with command.", location); } messageStartingPoint = 1; // Determine what the message is. int commandLength = IncomingMessage.Length - 1; string message = ""; for (; messageStartingPoint <= commandLength; messageStartingPoint++) { message = message + IncomingMessage[messageStartingPoint] + " "; } writer.WriteLine(message); writer.Flush(); } else { sendToChannel("4You do not have access to this command.", location); } } if (command == "!MSG") { if (isAdmin(nick)) { string[] IncomingMessage; IncomingMessage = commandParam.Split(new char[] { ' ' }); string whereToSendMessage = ""; int messageStartingPoint = 1; if (IncomingMessage.Length >= 2) { whereToSendMessage = IncomingMessage[1].ToString(); } else { sendToChannel("4Error with command.", location); } messageStartingPoint = 2; // Determine what the message is. int commandLength = IncomingMessage.Length - 1; string message = ""; for (; messageStartingPoint <= commandLength; messageStartingPoint++) { message = message + IncomingMessage[messageStartingPoint] + " "; } if (whereToSendMessage != "") { sendToChannel(message, whereToSendMessage); } } else { sendToChannel("4You do not have access to this command.", location); } } /* * I was going to try to get an MSN client to work with Kon, but it isn't working right. Disabled for now. * if (command == "!MSN") * { * if (isAdmin(nick)) * { * * string[] IncomingMessage; * IncomingMessage = commandParam.Split(new char[] { ' ' }); * * if (IncomingMessage.Length >= 2) * { * string msnUserName = IncomingMessage[1]; * string msnPassWord = IncomingMessage[2]; * * // start a new MSN client * msnClient = new msn(msnUserName, msnPassWord); * } * * else * sendToChannel("4Error in command.", location); * * } * else * sendToCha * nnel("4You do not have access to this command.", location); * }*/ #endregion }