private async Task SearchUrban(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string search = ""; if (string.IsNullOrWhiteSpace(args[0])) { await embedrep.Danger(msg, "Urban", "No entry to look for was given"); } else { int page = 0; if (args.Count > 1) { if (!string.IsNullOrWhiteSpace(args[1])) { if (int.TryParse(args[1].Trim(), out int temp)) { page = temp - 1; } } } search = args[0]; string body = await HTTP.Fetch("http://api.urbandictionary.com/v0/define?term=" + search, this.Log); Urban.UGlobal global = JSON.Deserialize <Urban.UGlobal>(body, this.Log); if (global == null) { await embedrep.Danger(msg, "Err", "There was no data to use for this!"); } else { if (global.list.Length == 0) { await embedrep.Danger(msg, "Arf!", "Looks like I couldn't find anything!"); } else { if (global.list.Length - 1 >= page && page >= 0) { Urban.UWord wordobj = global.list[page]; bool hasexample = string.IsNullOrWhiteSpace(wordobj.example); string smalldef = wordobj.definition.Length > 300 ? wordobj.definition.Remove(300) + "..." : wordobj.definition; await embedrep.Good(msg, "Definition #" + (page + 1), "**" + wordobj.permalink + "**\n\n" + smalldef + (!hasexample ? "\n\nExample:\n\n*" + wordobj.example + "*" : "") + "\n\n" + ":thumbsup: x" + wordobj.thumbs_up + "\t :thumbsdown: x" + wordobj.thumbs_down); } else { await embedrep.Danger(msg, "uh", "No result for definition n°" + (page + 1)); } } } } }
private async Task Ping(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { DateTimeOffset createtimestamp = msg.CreatedAt; DateTimeOffset timestamp = msg.Timestamp; int diff = timestamp.Millisecond / 10; await embedrep.Good(msg, "Pong!", ":alarm_clock: Discord: " + diff + "ms\n" + ":clock1: Bot: " + this.Handler.Client.Latency + "ms"); }
private async Task Lua(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string code = string.Join(',', args); List <Object> returns = new List <object>(); bool success = LuaEnv.Run(msg, code, out returns, out string error, this.Log); if (success) { string display = string.Join('\t', returns); if (string.IsNullOrWhiteSpace(display)) { await embedrep.Good(msg, "Lua", ":ok_hand: (nil or no value was returned)"); } else { await embedrep.Good(msg, "Lua", display); } } else { await embedrep.Danger(msg, "Lua", error); } }
private async Task EightBalls(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { if (string.IsNullOrWhiteSpace(args[0])) { await embedrep.Danger(msg, "Nope", "You didn't provide any word or sentence!"); } else { Random rand = new Random(); string[] answers = CommandsData.HeightBallAnswers; string answer = answers[rand.Next(0, answers.Length - 1)]; await embedrep.Good(msg, "8ball", answer); } }
private async Task Describe(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string[] adjs = CommandsData.Adjectives; string[] nouns = CommandsData.Nouns; SocketUser toping = msg.Author; if (!string.IsNullOrWhiteSpace(args[0]) && msg.MentionedUsers.Count > 0) { IReadOnlyList <SocketUser> users = msg.MentionedUsers as IReadOnlyList <SocketUser>; toping = users[0]; } Random random = new Random(); int times = random.Next(1, 4); string result = ""; for (int i = 0; i < times; i++) { bool of = random.Next(1, 100) > 50; if (of) { result += adjs[random.Next(0, adjs.Length)] + " "; result += nouns[random.Next(0, nouns.Length)].ToLower(); result += " of "; result += nouns[random.Next(0, nouns.Length)].ToLower(); } else { string randadj = adjs[random.Next(0, adjs.Length)]; result += randadj; } result += " "; } result += nouns[random.Next(0, nouns.Length)].ToLower(); bool isvowel = false; string[] vowels = CommandsData.Vowels; for (int i = 0; i < vowels.Length; i++) { if (result.StartsWith(vowels[i])) { isvowel = true; break; } } await embedrep.Good(msg, "Description", toping.Mention + " is " + (isvowel ? "an" : "a") + " " + result); }
private async Task Pick(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { if (string.IsNullOrWhiteSpace(args[0])) { await embedrep.Danger(msg, "Nope", "You didn't provide any/enough word(s)!"); } else { string[] answers = CommandsData.PickAnswers; Random rand = new Random(); string choice = args[rand.Next(0, args.Count - 1)].Trim(); string answer = answers[rand.Next(0, answers.Length - 1)].Replace("<answer>", choice); await embedrep.Good(msg, "Pick", answer); } }
private async Task Slap(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { Social.Action action = new Social.Action(); string result = ""; IReadOnlyList <SocketUser> users = msg.MentionedUsers as IReadOnlyList <SocketUser>; if (!string.IsNullOrWhiteSpace(args[0]) && users.Count > 0) { result = action.Slap(msg.Author, (msg.MentionedUsers as IReadOnlyList <SocketUser>)); await embedrep.Good(msg, "Slap!", result); } else { await embedrep.Danger(msg, "Aw", "You need to mention the persons you want to slap!"); } }
private async Task Alerts(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string body = await HTTP.Fetch("http://content.warframe.com/dynamic/worldState.php", this.Log); WGlobal global = JSON.Deserialize <WGlobal>(body, this.Log); if (global == null) { await embedrep.Danger(msg, "Err", "Looks like I couldn't access date for that!"); } else { for (int i = 0; i < global.Alerts.Length; i++) { WAlert alert = global.Alerts[i]; WMission minfo = alert.MissionInfo; WReward mreward = minfo.missionReward; DateTime endtime = DateTime.Now.Date.AddTicks(alert.Expiry.date.numberLong); DateTime offset = new DateTime().AddHours(5); //canada time offset (server hosted in germany) DateTime nowtime = new DateTime(DateTime.Now.Subtract(offset).Ticks); string showrewards = ""; if (mreward.items != null) { showrewards = "**Items**: \n"; for (int j = 0; j < mreward.items.Length; j++) { string[] dirs = mreward.items[j].Split("/"); string name = dirs[dirs.Length - 1]; showrewards += "\t\t" + name + "\n"; } } await embedrep.Good(msg, "Warframe Alert #" + (i + 1), "**Level**: " + minfo.minEnemyLevel + " - " + minfo.maxEnemyLevel + "\t**Type**: " + minfo.missionType.Substring(3).ToLower().Replace("_", " ") + "\t**Enemy**: " + minfo.faction.Substring(3).ToLower() + "\n" + "**Credits**: " + mreward.credits + "\t**Time Left**: " + (endtime.Subtract(nowtime).Minutes) + "mins\n" + showrewards ); } } }
private async Task Markov(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { if (!string.IsNullOrWhiteSpace(args[0])) { string sentence = string.Join(",", args.ToArray()); try { string generated = await MarkovHandler.Generate(sentence); await embedrep.Good(msg, "Markov", generated); } catch (Exception e) { await embedrep.Danger(msg, "Markov", "Something went wrong:\n" + e.ToString()); } } }
private async Task Help(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string arg = args[0]; if (!string.IsNullOrWhiteSpace(arg)) { bool retrieved = this.Handler.Commands.TryGetValue(arg.ToLower().Trim(), out Command cmd); if (retrieved) { await embedrep.Warning(msg, "Help [ " + arg + " ]", cmd.GetHelp()); } else { await embedrep.Danger(msg, "Help", "Couldn't find documentation for \"" + arg + "\""); } } else { if (!(msg.Channel is IDMChannel)) { await embedrep.Good(msg, "Help", "Check your private messages " + msg.Author.Mention); } Dictionary <string, Command> cmds = this.Handler.Commands; string result = "``"; uint count = 0; foreach (KeyValuePair <string, Command> cmd in cmds) { result += cmd.Key + ","; count++; if (count > 5) { result += "\n"; count = 0; } } result = result.Remove(result.Length - 2); result += "``"; await embedrep.RespondByDM(msg, "Help [ all ]", result, new Color()); } }
private async Task Letters(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string input = args[0]; string indicator = ":regional_indicator_"; string result = ""; for (int i = 0; i < input.Length; i++) { string letter = input[i].ToString().ToLower(); if (Regex.IsMatch(letter, @"[A-Za-z]")) { result += indicator + letter + ": "; } else if (Regex.IsMatch(letter, @"\s")) { result += "\t"; } } await embedrep.Good(msg, "Letters", result); }
private async Task Wew(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string url = string.IsNullOrWhiteSpace(args[0]) ? Handler.GetLastPictureURL((msg.Channel as SocketChannel)) : args[0]; string path = null; string maskpath = "Masks/wew.png"; if (!string.IsNullOrWhiteSpace(url)) //if getlastpicture returns nothing { path = await ImageProcess.DownloadImage(url); } if (path != null) { await embedrep.Good(msg, "WIP", "Sorry this command is under work!"); } if (path == null) { await embedrep.Danger(msg, "Ugh", "There's no valid url to use!"); } }
private async Task Say(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string tosay = string.Join(",", args.ToArray()); await embedrep.Good(msg, "Say", tosay); }
private async Task LuaReset(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { LuaEnv.Reset((msg.Channel as SocketChannel)); await embedrep.Good(msg, "LuaReset", "Lua state was reset for this channel"); }
private async Task Invite(CommandReplyEmbed embedrep, SocketMessage msg, List <string> args) { string invite = "https://discordapp.com/oauth2/authorize?client_id=" + EBotCredentials.BOT_ID_MAIN + "&scope=bot&permissions=0"; await embedrep.Good(msg, "Invite", invite); }