Beispiel #1
0
 private void ListCommands(CommandInfo info)
 {
     foreach (KeyValuePair<string, Tuple<CommandMethod, string>> mthd in Commands) {
         string ThisMessage = CommandSymbol + mthd.Key;
         ThisMessage += " - " + mthd.Value.Item2;
         SendNotice(info.Caller, ThisMessage);
     }
 }
Beispiel #2
0
        public void Alias(CommandInfo info)
        {
            string args = info.Arguments.Trim();
            var argParts = args.Split(' ');

            if (argParts.Length == 3)
                PerformAliasOperation(argParts, info.Source);
            else if (argParts.Length == 1)
                DisplayUserAliases(argParts[0], info.Source, args);
            else
                FattyBot.SendMessage(info.Source, "Not the right number of inputs");
        }
Beispiel #3
0
        public void Dictionary(CommandInfo info)
        {
            string searchURL = "http://www.dictionaryapi.com/api/v1/references/collegiate/xml/" + info.Arguments + "?key=" + DictionaryKey;
            HttpWebRequest searchRequest = HttpWebRequest.Create(searchURL) as HttpWebRequest;
            HttpWebResponse searchResponse = searchRequest.GetResponse() as HttpWebResponse;
            StreamReader reader = new StreamReader(searchResponse.GetResponseStream());
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(reader);
            StringBuilder messageAccumulator = new StringBuilder();

            var res = xmlDoc.GetElementsByTagName("entry");
            if (res.Count > 0) {
                messageAccumulator.Append(res.Count + " result(s): ");
                string candidateMessage = res[0].Attributes["id"].Value;
                string shortUrl = GoogleInterface.GetShortURL("http://www.merriam-webster.com/dictionary/" + info.Arguments);
                var chldrn = res[0].ChildNodes;
                foreach (XmlNode chld in chldrn) {
                    if (chld.Name == "def") {
                        var defnodes = chld.ChildNodes;
                        foreach (XmlNode def in defnodes) {
                            if (def.Name == "dt") {
                                candidateMessage += def.InnerText + " | ";
                                if (!FattyBot.TryAppend(messageAccumulator, candidateMessage, info.Source, shortUrl.Length + 2)) {
                                    break;
                                }
                            }
                        }
                    }
                }
                messageAccumulator.Append(" " + shortUrl);
            }
            else {
                messageAccumulator.Append("No results found. ");
                res = xmlDoc.GetElementsByTagName("suggestion");

                if (res.Count > 0) {
                    messageAccumulator.Append("Did you mean: ");
                    foreach (XmlNode nd in res) {
                        if (!FattyBot.TryAppend(messageAccumulator, nd.InnerText + "|", info.Source))
                            break;
                    }
                    messageAccumulator.Remove(messageAccumulator.Length - 1, 1);
                    messageAccumulator.Append("?");
                }
            }

            FattyBot.SendMessage(info.Source, messageAccumulator.ToString());
        }
Beispiel #4
0
        private void Seen(CommandInfo info)
        {
            Tuple<DateTime, String> lastSeentEntry;

            UserAliasGroup group;
            AliasInterface.FattyUserAliases.GetAliasGroup(info.Arguments, out group);
            if (group != null) {
                DateTime newestDateTime = DateTime.MinValue;
                string newestNick = "";
                string newestMessage = "";
                foreach(string uAlias in group.GetUserAliases()){
                    Tuple<DateTime, string> dateThing;
                    bool found = SeenList.TryGetValue(uAlias, out dateThing);
                    if (found && dateThing.Item1 > newestDateTime) {
                        newestDateTime = dateThing.Item1;
                        newestNick = uAlias;
                        newestMessage = dateThing.Item2;
                    }
                }

                if (newestNick.Length > 0) {
                    DateTime lastSeentTime = newestDateTime;
                    TimeSpan lastSeenSpan = DateTime.Now - lastSeentTime;
                    string prettyTime = GetPrettyTime(lastSeenSpan);
                    SendMessage(info.Source, String.Format("Last seen {0} on {1}. {2} ago. \"{3}\"", newestNick, lastSeentTime, prettyTime, newestMessage));
                }
                else
                    SendMessage(info.Source, String.Format("Haven't ever seen \"{0}\" around", info.Arguments));
            }
            else {
                bool userSeen = SeenList.TryGetValue(info.Arguments.ToLower(), out lastSeentEntry);

                if (userSeen) {
                    DateTime lastSeentTime = lastSeentEntry.Item1;
                    TimeSpan lastSeenSpan = DateTime.Now - lastSeentTime;
                    string prettyTime = GetPrettyTime(lastSeenSpan);

                    if (info.Caller == info.Arguments)
                        SendMessage(info.Source, String.Format("You were last seen (before this command) {0} on {1}. {2} ago. \"{3}\"", info.Arguments, lastSeentTime, prettyTime, lastSeentEntry.Item2));
                    else
                        SendMessage(info.Source, String.Format("Last seen {0} on {1}. {2} ago. \"{3}\"", info.Arguments, lastSeentTime, prettyTime, lastSeentEntry.Item2));
                }
                else {
                    SendMessage(info.Source, String.Format("Haven't ever seen \"{0}\" around", info.Arguments));
                }
            }
        }
Beispiel #5
0
        private void EightBall(CommandInfo info)
        {
            Random rand = new Random();

            SendMessage(info.Source, String.Format("{0}: {1}", info.Caller, EightBallResponses[rand.Next(EightBallResponses.Length)]));
        }
Beispiel #6
0
 private void Tell(CommandInfo info)
 {
     var parts = info.Arguments.Split(' ');
     var recipients = parts[0].Split(',');
     string msg = String.Join(" ", parts, 1, parts.Length - 1);
     foreach (var recip in recipients) {
         if (recip == IrcObject.IrcNick) {
             SendMessage(info.Source, "xD");
             continue;
         }
         else {
             FattyTellManager.AddTellForUser(recip, info.Caller, msg);
         }
     }
     SendMessage(info.Source, String.Format("Will tell that to {0} when they are round", parts[0]));
 }
Beispiel #7
0
 private void Shutup(CommandInfo info)
 {
     Gagger = info.Caller;
     GagTime = DateTime.Now;
     SendMessage(info.Source, String.Format("Alright {0}, I'll be quiet for you for the next 5 minutes.  I know how you hate fun and all.", info.Caller));
 }
Beispiel #8
0
        private void RunCommand(CommandInfo info)
        {
            Tuple<CommandMethod, string> meth;

            bool realCommand = this.Commands.TryGetValue(info.CommandName, out meth);
            if (info.Source[0] == '#' && IsGagged && realCommand) {
                TimeSpan timeLeft = (FiveMins - (DateTime.Now - GagTime));
                SendNotice(info.Caller, String.Format("Sorry, {0} is a spoilsport and has me gagged for the next {1} minutes and {2} seconds. These responses are only visible to you", Gagger, timeLeft.Minutes, timeLeft.Seconds));
            }
            else if (realCommand) {
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("{0} used command called \"{1}\" from {2} with arguments \"{3}\"", info.Caller, info.Source, info.CommandName, info.Arguments);
                Console.ResetColor();
                meth.Item1.Invoke(info);
            }
        }
Beispiel #9
0
        private void ExecuteCommands(string message, string ircUser, string messageSource, SourceType messageSourceType)
        {
            if (message[0] != CommandSymbol)
                return;

            string command = message.Substring(1);
            int separatorPosition = command.IndexOf(' ');
            string commandName;
            string commandArgs;
            if (separatorPosition > -1) {
                commandName = command.Substring(0, separatorPosition);
                commandArgs = command.Substring(separatorPosition + 1);
            }
            else {
                commandName = command;
                commandArgs = "";
            }
            try {
                CommandInfo info = new CommandInfo(ircUser, commandArgs, messageSource, commandName, messageSourceType);
                RunCommand(info);
            }
            catch (Exception ex) {
                SendMessage(messageSource, ex.ToString());
            }
        }
Beispiel #10
0
        public void Math(CommandInfo info)
        {
            //cull old messages
            TimeSpan anHour = new TimeSpan(1, 0, 0);
            for (int i = RecentMathInvocations.Count - 1; i >= 0; --i) {
                if ((DateTime.Now - RecentMathInvocations[i]) > anHour)
                    RecentMathInvocations.RemoveAt(i);
            }

            if (RecentMathInvocations.Count > MaxCallsPerHour) {
                TimeSpan nextInvoke = anHour - (DateTime.Now - RecentMathInvocations[0]);
                FattyBot.SendMessage(info.Source, String.Format("Sorry {0}, rate limit on this command exceeded, you can use it again in {2} minutes", info.Caller, nextInvoke.Minutes));
                return;
            }

            string args = info.Arguments.Replace("+", "%2B");
            string searchURL = "http://api.wolframalpha.com/v2/query?input=" + args + "&appid=" + WolframAlphaKey;
            HttpWebRequest searchRequest = HttpWebRequest.Create(searchURL) as HttpWebRequest;
            //string butts = searchRequest.RequestUri.IsWellFormedOriginalString();
            HttpWebResponse searchResponse = searchRequest.GetResponse() as HttpWebResponse;
            StreamReader reader = new StreamReader(searchResponse.GetResponseStream());

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(reader);
            StringBuilder messageAccumulator = new StringBuilder();
            int messageOverhead = FattyBot.GetMessageOverhead(info.Source);

            XmlNodeList res = xmlDoc.GetElementsByTagName("queryresult");
            if (res[0].Attributes["success"].Value == "false") {
                messageAccumulator.Append("Query failed: ");
                res = xmlDoc.GetElementsByTagName("tip");
                for (int i = 0; i < res.Count; i++) {
                    string desc = res[i].InnerText;
                    if (desc.Length + messageOverhead + messageAccumulator.Length <= 480)
                        messageAccumulator.Append(desc + ". ");
                    else
                        break;
                }
                res = xmlDoc.GetElementsByTagName("didyoumean");

                for (int i = 0; i < res.Count; i++) {
                    string desc = "";
                    if (i == 0)
                        desc += "Did you mean: ";
                    desc += res[i].InnerText + " ? ";
                    if (desc.Length + messageOverhead + messageAccumulator.Length <= 480)
                        messageAccumulator.Append(desc);
                    else
                        break;
                }
                FattyBot.SendMessage(info.Source, messageAccumulator.ToString());
            }
            else {
                res = xmlDoc.GetElementsByTagName("plaintext");

                for (int i = 0; i < res.Count; i++) {
                    string value = res[i].InnerText;
                    string description = res[i].ParentNode.ParentNode.Attributes["title"].Value;
                    if (description == "Number line")
                        continue;
                    description = description + ":" + value;
                    if (description.Length + messageOverhead + messageAccumulator.Length <= 480)
                        messageAccumulator.Append(description + " / ");
                    else
                        break;
                }
                messageAccumulator.Remove(messageAccumulator.Length - 1, 1);
                messageAccumulator.Replace("\n", " ");
                messageAccumulator.Replace("\r", " ");

                FattyBot.SendMessage(info.Source, messageAccumulator.ToString());
            }

            RecentMathInvocations.Add(DateTime.Now);
        }
Beispiel #11
0
 public void MathLimit(CommandInfo info)
 {
     //cull old messages
     TimeSpan anHour = new TimeSpan(1, 0, 0);
     for (int i = RecentMathInvocations.Count - 1; i >= 0; --i) {
         if ((DateTime.Now - RecentMathInvocations[i]) > anHour)
             RecentMathInvocations.RemoveAt(i);
     }
     FattyBot.SendMessage(info.Source, String.Format("{0} wolfram invocations have been made in the past hour. {1} left.", RecentMathInvocations.Count, 30 - RecentMathInvocations.Count));
 }
Beispiel #12
0
        public void URLShortener(CommandInfo info)
        {
            string shortURL = GetShortURL(info.Arguments);

            FattyBot.SendMessage(info.Source, shortURL);
        }
Beispiel #13
0
 public void GoogleImageSearch(CommandInfo info)
 {
     string searchURL = "https://www.googleapis.com/customsearch/v1?key=" + GoogleAPIKey + "&cx=" + GoogleCustomSearchID + "&searchType=image&q=";
     searchURL += info.Arguments;
     GoogleAPIPrinter(searchURL, info.Source);
 }