A Function which allows users to send messages to each other, even when the intended recipient is offline.
Inheritance: Function
Exemple #1
0
        public override List <IRCResponse> GetResponse(BotMessage message)
        {
            if (!Regex.IsMatch(message.Command, "^(r(emove)?tell)$", RegexOptions.IgnoreCase))
            {
                return(null);
            }

            if (message.ParameterList.Count == 0)
            {
                return new List <IRCResponse>()
                       {
                           new IRCResponse(ResponseType.Say, "You didn't specify a message to remove!", message.ReplyTo)
                       }
            }
            ;

            List <string> keysToRemove = new List <string>();

            foreach (string user in Tell.MessageMap.Keys)
            {
                List <IRCResponse> response = new List <IRCResponse>();

                lock (Tell.tellMapLock)
                {
                    int index = Tell.MessageMap[user].FindIndex(s =>
                                                                s.From.ToLowerInvariant() == message.User.Name.ToLowerInvariant() &&
                                                                Regex.IsMatch(s.Message, ".*" + message.Parameters + ".*", RegexOptions.IgnoreCase));

                    if (index < 0)
                    {
                        continue;
                    }

                    response.Add(new IRCResponse(ResponseType.Say, "Message \"" +
                                                 Tell.MessageMap[user][index].Message +
                                                 "\", sent on date \"" +
                                                 Tell.MessageMap[user][index].SentDate +
                                                 "\" to \"" +
                                                 user +
                                                 "\" removed from the message database!", message.ReplyTo));

                    Tell.MessageMap[user].RemoveAt(index);

                    if (Tell.MessageMap[user].Count == 0)
                    {
                        Tell.MessageMap.Remove(user);
                    }
                }

                Tell.WriteMessages();

                return(response);
            }

            return(new List <IRCResponse>()
            {
                new IRCResponse(ResponseType.Say, "No message sent by you containing \"" + message.Parameters + "\" found in the message database!", message.ReplyTo)
            });
        }
    }
Exemple #2
0
        public override List <IRCResponse> GetResponse(BotMessage message)
        {
            if (message.Type != "PRIVMSG")
            {
                return(null);
            }

            List <IRCResponse> responses = new List <IRCResponse>();

            List <string> keysToDelete = new List <string>();
            Dictionary <string, List <Tell.TellMessage> > keysToKeep = new Dictionary <string, List <Tell.TellMessage> >();

            lock (Tell.tellMapLock)
            {
                foreach (KeyValuePair <string, List <Tell.TellMessage> > kvp in Tell.MessageMap)
                {
                    if (Regex.IsMatch(message.User.Name, kvp.Key, RegexOptions.IgnoreCase))
                    {
                        foreach (Tell.TellMessage msg in kvp.Value)
                        {
                            if (msg.Target == "PM" || msg.Target == message.ReplyTo)
                            {
                                responses.Add(new IRCResponse(ResponseType.Say, message.User.Name + ": " + msg.Message, msg.Target == "PM" ? message.User.Name : msg.Target));
                                responses.Add(new IRCResponse(ResponseType.Say, "^ from " + msg.From + " on " + msg.SentDate, msg.Target == "PM" ? message.User.Name : msg.Target));
                            }
                            else
                            {
                                if (!keysToKeep.ContainsKey(kvp.Key))
                                {
                                    keysToKeep.Add(kvp.Key, new List <Tell.TellMessage>());
                                }
                                keysToKeep[kvp.Key].Add(msg);
                            }
                        }

                        keysToDelete.Add(kvp.Key);
                    }
                }
                foreach (string key in keysToDelete)
                {
                    Tell.MessageMap[key].Clear();
                    Tell.MessageMap.Remove(key);
                }
                Tell.MessageMap = Tell.MessageMap.Concat(keysToKeep).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);
            }

            if (responses.Count == 0)
            {
                return(null);
            }

            Tell.WriteMessages();

            return(responses);
        }