public static String getReply(String reply, String conversation, String nick) { cResponse rawReply; rawReply = AIMLbot.chat(conversation, nick); // needs to change a bit. reply = rawReply.getOutput(); // Let's replace stuff that Kon wasn't able to find in AIML with something from his brain. reply = reply.Replace("NANIMONAI", IRC.myAI.pullFromBrain()); reply = reply.Replace("REPLACETHISWITHSOMETHING", IRC.myAI.pullFromBrain()); reply = reply.Replace("HEHADNOIDEAWHATHESAID", IRC.myAI.pullFromBrain()); reply = reply.Replace("KONHASNOFREAKINCLUERIGHTNOW", IRC.myAI.pullFromBrain()); reply = reply.Replace("REPLACETHISMORESOITSTOPSREPEATING", IRC.myAI.pullFromBrain()); // Now we'll replace a few other things to help make it better. reply = reply.Replace(@"Perhaps some of my AIML files are missing. You can download them from http://www.alicebot.org/ and place them in the following directory: C:\Documents and Settings\James\My Documents\Visual Studio 2005\Projects\Kon\Kon\bin\Debug\aiml", IRC.myAI.pullFromBrain()); reply = reply.Replace("I think you mean \"it's\" or \"it is\" not \"its\".", IRC.myAI.pullFromBrain()); reply = reply.Replace("I answer a lot of silly questions.", IRC.myAI.pullFromBrain()); reply = reply.Replace("Try asking me in simpler terms.", IRC.myAI.pullFromBrain()); // Replace "un-named user" with the nick of the person speaking to the bot. reply = reply.Replace("un-named user", nick); return(reply); }
public void MessageHandler(Connection conn, InstantMessage im) { Log.Instance.WriteStatus("INMSG (" + conn.m_type.ToString() + ") << " + im.User + " : " + im.Text); string strUniqueID = im.User + conn.m_type.ToString(); if (m_bLoadingUsers || m_bLoadingReminders) { conn.SendMessage(im.User, "RemindMe is performing maintenance. Please try again in a few minutes. If the problem persists, please contact [email protected]"); // TODO: fiond out why the bot gets stuck with one of these two being true all the time Log.Instance.WriteLine("m_bLoadingUsers = {0} , m_bLoadingReminders = {1}", m_bLoadingUsers.ToString(), m_bLoadingReminders.ToString()); return; } User user = userMgr.GetUserByService(conn.m_type, im.User); // unknown user? Then get out ohere quickly if (user == null) { // we don't want to send email back to spammers if ((m_imers[strUniqueID] == null || (int)m_imers[strUniqueID] < 1)) // && conn.m_type != ConnectionType.EMAIL) { conn.SendMessage(im.User, m_rm.GetString("unknown_user") + adMgr.GetNextAdText(null, conn.m_type)); } // protect against spamming the bot, max of 1 im if (m_imers[strUniqueID] == null) { m_imers[strUniqueID] = 1; } else { m_imers[strUniqueID] = (int)m_imers[strUniqueID] + 1; } return; } if ((im.Text.ToLower() == @"/reset aim" || im.Text.ToLower() == @"/reset icq" || im.Text.ToLower() == @"/reset yahoo" || im.Text.ToLower() == @"/reset msn") && user.Class == UserClassType.ADMIN) { string [] strList = im.Text.Split(' '); ConnectionType ct = (ConnectionType)Enum.Parse(typeof(ConnectionType), strList[1], true); Connection resetcon = conMgr.GetConnection(ct); if (resetcon != null) { resetcon.Disconnect(); Thread.Sleep(1000); resetcon.Connect(); } return; } if (im.Text.ToLower() == @"/whoami") { conn.SendMessage(im.User, "\r\nUser: "******"(" + user.UserID + ")" + "\r\nClass: " + user.Class.ToString() + "\r\nEmail: " + user.Email + "\r\nPlanNumber: " + user.PlanNumber); return; } Regex reg = new Regex(@"^f**k\s+you", RegexOptions.IgnoreCase); Match m = reg.Match(im.Text); if (m.Success) { conn.SendMessage(im.User, "That's really not nice!"); m_fuers[im.User] = 1; return; } // /help commands reg = new Regex(@"^[\/\-\:]+help\s*[\w\s]*$", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { string strResponse = helpMgr.GetResponse(im.Text); if (strResponse.Length > 1) { conn.SendMessage(im.User, strResponse); } return; } // /list reg = new Regex(@"^\/list", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { string strResponse = "\nCurrent Pending Reminders:\n"; foreach (Reminder aRem in DataManagerObj.GetUsersReminders(user.UserID)) { strResponse += aRem.ID + " " + aRem.UserTimeString + "\n"; } conn.SendMessage(im.User, strResponse); return; } // /cancel 1234 -- show a reminder reg = new Regex(@"^/cancel\s+(\d+)\s*$", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { string remId = m.Groups[1].Captures[0].ToString(); int iRemID = int.Parse(remId); Reminder aRem = DataManagerObj.GetReminder(iRemID); if (aRem != null && aRem.UserID == user.UserID) { aRem.Delivered = true; DataManagerObj.SaveReminder(aRem); string strResponse = m_rm.GetString("cancel_reminder_conf"); strResponse = strResponse.Replace("%d", aRem.ID); conn.SendMessage(im.User, strResponse); } return; } // /show 1234 - display the details of reminder 1234 reg = new Regex(@"^/show\s+(\d+)\s*$", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { string remId = m.Groups[1].Captures[0].ToString(); int iRemID = int.Parse(remId); Reminder aRem = DataManagerObj.GetReminder(iRemID); if (aRem != null && aRem.UserID == user.UserID) { string strResponse = m_rm.GetString(@"reminder_info_IM"); User creatorObj = _dataManager.GetUser(aRem.CreatorID); strResponse = strResponse.Replace("%d", aRem.ID.ToString()); strResponse = strResponse.Replace("%a", creatorObj.Username); strResponse = strResponse.Replace("%b", aRem.UserTimeString); strResponse = strResponse.Replace("%c", aRem.Message); conn.SendMessage(im.User, strResponse); } return; } // remind me ....... reg = new Regex(@"^remind\s+\w+\s+\w+", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { ProcessParse(conn, im, user, @"creation_parse"); return; } // in 20 minutes remind me to transfer reg = new Regex(@"^.*?\s+remind\s+[\w_,]+\s+.*", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { ProcessParse(conn, im, user, @"creation_parse"); return; } reg = new Regex(@"^repeat\s+\w+", RegexOptions.IgnoreCase); m = reg.Match(im.Text); if (m.Success) { ProcessParse(conn, im, user, @"repeat_parse"); return; } if (user != null && conn.m_type != ConnectionType.EMAIL) { if (_aliceBotReady) { cResponse reply = _aliceBot.chat(im.Text, user.Username); conn.SendMessage(im.User, reply.getOutput()); } else { string strMsg = m_rm.GetString("known_user_default"); strMsg = strMsg.Replace("%u", user.Username); conn.SendMessage(im.User, strMsg); } } }