void ReadMessages() { lock (tellFileLock) lock (tellMapLock) { string fileName = Path.Combine(Settings.Instance.DataPath, Settings.Instance.Server + string.Format("{0}TellMessages.xml", Path.DirectorySeparatorChar)); if (!File.Exists(fileName)) { return; } XmlDocument doc = new XmlDocument(); using (FileStream fstream = File.OpenRead(fileName)) { using (StreamReader reader = new StreamReader(fstream)) { doc.Load(reader); XmlNode root = doc.DocumentElement; foreach (XmlNode userNode in root.SelectNodes(@"/Users/User")) { string user = userNode.SelectSingleNode("Name").FirstChild.Value; List <TellMessage> tellMessages = new List <TellMessage>(); foreach (XmlNode messageNode in userNode.SelectNodes(@"Messages/Message")) { TellMessage tellMessage = new TellMessage(); tellMessage.Message = messageNode.SelectSingleNode("Text").FirstChild.Value; tellMessage.From = messageNode.SelectSingleNode("From").FirstChild.Value; tellMessage.SentDate = messageNode.SelectSingleNode("Date").FirstChild.Value; tellMessage.Target = messageNode.SelectSingleNode("Target").FirstChild.Value; tellMessages.Add(tellMessage); } MessageMap.Add(user, tellMessages); } } } } }
public override List <IRCResponse> GetResponse(BotMessage message) { if (!Regex.IsMatch(message.Command, "^(tell)$", RegexOptions.IgnoreCase)) { return(null); } if (message.ParameterList.Count == 0) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Tell who what?", message.ReplyTo) } } ; if (message.ParameterList.Count == 1 || message.Parameters.Substring(message.ParameterList[0].Length + 1).Trim(' ').Length == 0) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a message for me to tell " + message.ParameterList[0], message.ReplyTo) } } ; if (message.ParameterList[0].ToLowerInvariant() == Settings.Instance.CurrentNick.ToLowerInvariant()) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Thanks for telling me that " + message.User.Name + ", I'm sure I'll find that useful...", message.ReplyTo) } } ; if (RateLimit(message.User.Name)) { return new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "You've already sent 3 messages in the last 5 minutes, slow down!", message.ReplyTo) } } ; lock (tellMapLock) { foreach (string target in message.ParameterList[0].Split('&')) { string to = WildcardToRegex(target); string msg = message.Parameters.Substring(message.ParameterList[0].Length + 1); if (!MessageMap.ContainsKey(to)) { MessageMap.Add(to, new List <TellMessage>()); } TellMessage tellMessage = new TellMessage(); tellMessage.From = message.User.Name; tellMessage.SentDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss (UTC zz)"); tellMessage.Message = StringUtils.ReplaceNewlines(StringUtils.StripIRCFormatChars(msg), " | "); if (message.TargetType == IRCMessage.TargetTypes.CHANNEL) { tellMessage.Target = message.ReplyTo; } else { tellMessage.Target = "PM"; } MessageMap[to].Add(tellMessage); } } WriteMessages(); return(new List <IRCResponse>() { new IRCResponse(ResponseType.Say, "Ok, I'll tell " + string.Join(" & ", message.ParameterList[0].Split('&')) + " that when they next speak.", message.ReplyTo) }); }
void ReadMessages() { lock (tellFileLock) lock (tellMapLock) { string fileName = Path.Combine(Settings.Instance.DataPath, Settings.Instance.Server + string.Format("{0}TellMessages.xml", Path.DirectorySeparatorChar)); if (!File.Exists(fileName)) return; XmlDocument doc = new XmlDocument(); using (FileStream fstream = File.OpenRead(fileName)) { using (StreamReader reader = new StreamReader(fstream)) { doc.Load(reader); XmlNode root = doc.DocumentElement; foreach (XmlNode userNode in root.SelectNodes(@"/Users/User")) { string user = userNode.SelectSingleNode("Name").FirstChild.Value; List<TellMessage> tellMessages = new List<TellMessage>(); foreach (XmlNode messageNode in userNode.SelectNodes(@"Messages/Message")) { TellMessage tellMessage = new TellMessage(); tellMessage.Message = messageNode.SelectSingleNode("Text").FirstChild.Value; tellMessage.From = messageNode.SelectSingleNode("From").FirstChild.Value; tellMessage.SentDate = messageNode.SelectSingleNode("Date").FirstChild.Value; tellMessage.Target = messageNode.SelectSingleNode("Target").FirstChild.Value; tellMessages.Add(tellMessage); } MessageMap.Add(user, tellMessages); } } } } }
public override List<IRCResponse> GetResponse(BotMessage message) { if (!Regex.IsMatch(message.Command, "^(tell)$", RegexOptions.IgnoreCase)) return null; if (message.ParameterList.Count == 0) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Tell who what?", message.ReplyTo) }; if (message.ParameterList.Count == 1 || message.Parameters.Substring(message.ParameterList[0].Length + 1).Trim(' ').Length == 0) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You didn't give a message for me to tell " + message.ParameterList[0], message.ReplyTo) }; if (message.ParameterList[0].ToLowerInvariant() == Settings.Instance.CurrentNick.ToLowerInvariant()) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Thanks for telling me that " + message.User.Name + ", I'm sure I'll find that useful...", message.ReplyTo) }; if (RateLimit(message.User.Name)) return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "You've already sent 3 messages in the last 5 minutes, slow down!", message.ReplyTo) }; lock (tellMapLock) { foreach (string target in message.ParameterList[0].Split('&')) { string to = WildcardToRegex(target); string msg = message.Parameters.Substring(message.ParameterList[0].Length + 1); if (!MessageMap.ContainsKey(to)) { MessageMap.Add(to, new List<TellMessage>()); } TellMessage tellMessage = new TellMessage(); tellMessage.From = message.User.Name; tellMessage.SentDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss (UTC zz)"); tellMessage.Message = StringUtils.ReplaceNewlines(StringUtils.StripIRCFormatChars(msg), " | "); if (message.TargetType == IRCMessage.TargetTypes.CHANNEL) tellMessage.Target = message.ReplyTo; else tellMessage.Target = "PM"; MessageMap[to].Add(tellMessage); } } WriteMessages(); return new List<IRCResponse>() { new IRCResponse(ResponseType.Say, "Ok, I'll tell " + string.Join(" & ", message.ParameterList[0].Split('&')) + " that when they next speak.", message.ReplyTo) }; }