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); } }
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"); }
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()); }
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)); } } }
private void EightBall(CommandInfo info) { Random rand = new Random(); SendMessage(info.Source, String.Format("{0}: {1}", info.Caller, EightBallResponses[rand.Next(EightBallResponses.Length)])); }
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])); }
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)); }
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); } }
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()); } }
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); }
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)); }
public void URLShortener(CommandInfo info) { string shortURL = GetShortURL(info.Arguments); FattyBot.SendMessage(info.Source, shortURL); }
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); }