public async Task Changelog() { var db = new BotBaseContext(); var embed = new JifBotEmbedBuilder(); var totalEntries = db.ChangeLog.AsQueryable().OrderByDescending(e => e.Date); var entriesToPrint = new Dictionary <string, string>(); foreach (ChangeLog entry in totalEntries) { if (!entriesToPrint.ContainsKey(entry.Date)) { if (entriesToPrint.Count >= 3) { break; } entriesToPrint.Add(entry.Date, $"\\> {entry.Change}"); } else { entriesToPrint[entry.Date] += $"\n\\> {entry.Change}"; } } embed.Title = "Last 3 Jif Bot updates"; embed.Description = "For a list of all updates, visit https://jifbot.com/changelog.html"; foreach (var entry in entriesToPrint) { var pieces = entry.Key.Split("-"); embed.AddField($"{pieces[1]}.{pieces[2]}.{pieces[0]}", entry.Value); } await ReplyAsync("", false, embed.Build()); }
public Embed BuildReactMessage(IGuild server) { var db = new BotBaseContext(); var embed = new JifBotEmbedBuilder(); embed.Title = "React with the following emojis to receive the corresponding role. Remove the reaction to remove the role."; embed.Description = ""; var roles = db.ReactRole.AsQueryable().Where(r => r.ServerId == server.Id).DefaultIfEmpty(); var config = db.Configuration.AsQueryable().Where(c => c.Name == Program.configName).First(); if (roles.First() == null) { embed.Description = $"No emotes currently set. Use {config.Prefix}reactrole to set roles"; } else { foreach (var role in roles) { var dRole = server.GetRole(role.RoleId); embed.Description += $"{role.Emote} -- {dRole.Mention}"; if (role.Description != "") { embed.Description += $"\n {role.Description}"; } embed.Description += "\n\n"; } } return(embed.Build()); }
public async Task Commands() { var db = new BotBaseContext(); var commands = db.Command.AsQueryable().OrderBy(command => command.Category); var config = db.Configuration.AsQueryable().Where(cfg => cfg.Name == Program.configName).First(); var embed = new JifBotEmbedBuilder(); embed.Title = "All commands will begin with a " + config.Prefix + " , for more information on individual commands, use: " + config.Prefix + "help commandName"; embed.Description = "Contact Jif#3952 with any suggestions for more commands. To see all command defintions together, visit https://jifbot.com/commands.html"; string cat = commands.First().Category; string list = ""; foreach (Command command in commands) { if (command.Category != cat) { embed.AddField(cat, list.Remove(list.LastIndexOf(", "))); cat = command.Category; list = ""; } list += command.Name + ", "; } embed.AddField(cat, list.Remove(list.LastIndexOf(", "))); await ReplyAsync("", false, embed.Build()); }
public async Task Mastery(string region, [Remainder] string name) { var db = new BotBaseContext(); var embed = new JifBotEmbedBuilder(); { name = name.Replace(" ", string.Empty); System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string html = ""; try { html = await client.GetStringAsync("https://championmasterylookup.derpthemeus.com/summoner?summoner=" + name + "®ion=" + region.ToUpper()); } catch { await ReplyAsync("That summoner does not exist"); return; } html = html.Remove(0, html.IndexOf("/img/profile")); embed.ThumbnailUrl = "https://championmasterylookup.derpthemeus.com" + html.Remove(html.IndexOf("\"")); html = html.Remove(0, html.IndexOf("userName="******"Top ten mastery scores for " + (html.Remove(html.IndexOf("\"")).Replace("%20", " ")); string champ = ""; string nums = ""; int count = 0; for (int i = 1; i <= 10; i++) { if (html.IndexOf("/champion?") == html.IndexOf("/champion?champion=-1")) { break; } html = html.Remove(0, html.IndexOf("/champion?")); html = html.Remove(0, html.IndexOf(">") + 1); champ = html.Remove(html.IndexOf("<")); champ = champ.Replace("'", "'"); html = html.Remove(0, html.IndexOf("\"") + 1); nums = html.Remove(html.IndexOf("\"")); count = count + Convert.ToInt32(nums); for (int j = nums.Length - 3; j > 0; j = j - 3) { nums = nums.Remove(j) + "," + nums.Remove(0, j); } embed.AddField(i + ". " + champ, nums + " points", inline: true); } nums = Convert.ToString(count); for (int j = nums.Length - 3; j > 0; j = j - 3) { nums = nums.Remove(j) + "," + nums.Remove(0, j); } embed.Description = "Total score across top ten: " + nums; await ReplyAsync("", false, embed.Build()); } }
public async Task Movie([Remainder] string word) { var db = new BotBaseContext(); var omdbKey = db.Variable.AsQueryable().Where(v => v.Name == "omdbKey").First(); HttpClient client = new HttpClient(); client.BaseAddress = new Uri("http://www.omdbapi.com"); HttpResponseMessage response = await client.GetAsync($"?t={word}&plot=full&apikey={omdbKey.Value}"); HttpContent content = response.Content; string stuff = await content.ReadAsStringAsync(); var json = JObject.Parse(stuff); if ((string)json.SelectToken("Response") == "False") { await ReplyAsync("Movie not found"); return; } var embed = new JifBotEmbedBuilder(); string rt = (string)json.SelectToken("Ratings[1].Value"); string imdb = (string)json.SelectToken("Ratings[0].Value"); string plot = (string)json.SelectToken("Plot"); if (plot.Length > 1024) { int excess = plot.Length - 1024; plot = plot.Remove(plot.Length - excess - 3); plot += "..."; } embed.Title = (string)json.SelectToken("Title"); embed.Description = (string)json.SelectToken("Genre"); if ((string)json.SelectToken("Poster") != "N/A") { embed.ThumbnailUrl = (string)json.SelectToken("Poster"); } if (rt != null) { embed.AddField($"Rotten Tomatoes: {rt}, IMDb: {imdb}", plot); } else { embed.AddField($"IMDb Rating: {imdb}", plot); } embed.AddField("Released", (string)json.SelectToken("Released"), inline: true); embed.AddField("Run Time", (string)json.SelectToken("Runtime"), inline: true); embed.AddField("Rating", (string)json.SelectToken("Rated"), inline: true); embed.AddField("Starring", (string)json.SelectToken("Actors")); embed.AddField("Directed By", (string)json.SelectToken("Director"), inline: true); embed.WithUrl("https://www.imdb.com/title/" + (string)json.SelectToken("imdbID")); await ReplyAsync("", false, embed.Build()); }
public async Task Stats(string region, [Remainder] string name) { name = name.Replace(" ", string.Empty); string SearchText = "<meta name=\"description\" content=\""; string SearchText2 = "\"/>"; System.Net.Http.HttpClient client = new System.Net.Http.HttpClient(); string source = ""; if (region == "kr") { if (await RemoteFileExists("http://www.op.gg/summoner/userName="******"http://www.op.gg/summoner/userName="******"That is not a valid summoner name / region"); return; } } else { if (await RemoteFileExists("http://" + region + ".op.gg/summoner/userName="******"http://" + region + ".op.gg/summoner/userName="******"That is not a valid summoner name / region"); return; } } if (source.IndexOf("This summoner is not registered at OP.GG. Please check spelling.") != -1) { await ReplyAsync("That Summoner does not exist"); return; } else { var db = new BotBaseContext(); var embed = new JifBotEmbedBuilder(); string kdsource = source.Remove(0, source.IndexOf("summoner-id=\"") + 13); kdsource = kdsource.Remove(kdsource.IndexOf("\"")); if (region == "kr") { kdsource = "http://www." + "op.gg/summoner/champions/ajax/champions.most/summonerId=" + kdsource + "&season=11"; } else { kdsource = "http://" + region + ".op.gg/summoner/champions/ajax/champions.most/summonerId=" + kdsource + "&season=11"; } System.Net.Http.HttpClient client2 = new System.Net.Http.HttpClient(); kdsource = await client2.GetStringAsync(kdsource); string url = source.Remove(0, source.IndexOf("ProfileIcon")); url = url.Remove(0, url.IndexOf("<img src=\"//") + 12); url = url.Remove(url.IndexOf("\"")); url = "http://" + url; embed.ThumbnailUrl = url; Int32 start = source.IndexOf(SearchText) + SearchText.Length; source = source.Remove(0, start); Int32 end = source.IndexOf(SearchText2); source = source.Remove(end); source = source.Replace("'", "'"); if (source.IndexOf("Lv. ") == -1 && source.IndexOf("Unranked") == -1) { string def = "Information for: " + source.Remove(source.IndexOf("/")) + "\n"; source = source.Remove(0, source.IndexOf("/") + 1); embed.Title = def; def = "Current Ranking: " + source.Remove(source.IndexOf("/")) + "\n"; source = source.Remove(0, source.IndexOf("/") + 1); def = def + "Win Record: " + source.Remove(source.IndexOf("Win")) + " ("; source = source.Remove(0, source.IndexOf("o") + 1); def = def + source.Remove(source.IndexOf("/")) + ")\n\nTop 5 Champions:\n"; source = source.Remove(0, source.IndexOf("/") + 1); embed.Description = def; for (int i = 0; i < 4; i++) { if (source.IndexOf(",") != -1) { def = source.Remove(source.IndexOf("Win")) + "("; source = source.Remove(0, source.IndexOf("Win") + 9); def = def + source.Remove(source.IndexOf(",")) + " )"; def = def.Remove(def.IndexOf("-")) + def.Remove(0, def.IndexOf("-")).PadRight(30, ' '); source = source.Remove(0, source.IndexOf(",") + 1); kdsource = kdsource.Remove(0, kdsource.IndexOf("span class=\"KDA") + 17); def = def + "KDA: **" + kdsource.Remove(kdsource.IndexOf(":")) + "** ( "; kdsource = kdsource.Remove(0, kdsource.IndexOf("KDAEach")); kdsource = kdsource.Remove(0, kdsource.IndexOf("Kill") + 6); def = def + kdsource.Remove(kdsource.IndexOf("<")); kdsource = kdsource.Remove(0, kdsource.IndexOf("Death") + 7); def = def + " / " + kdsource.Remove(kdsource.IndexOf("<")); kdsource = kdsource.Remove(0, kdsource.IndexOf("Assist") + 8); def = def + " / " + kdsource.Remove(kdsource.IndexOf("<")) + " )"; embed.AddField(def.Remove(def.IndexOf("-")), def.Remove(0, def.IndexOf("-") + 1)); } } def = source.Remove(source.IndexOf("Win")) + " ("; source = source.Remove(0, source.IndexOf("Win") + 9); def = def + source + " )"; def = def.Remove(def.IndexOf("-")) + def.Remove(0, def.IndexOf("-")).PadRight(30, ' '); kdsource = kdsource.Remove(0, kdsource.IndexOf("span class=\"KDA") + 17); def = def + "KDA: **" + kdsource.Remove(kdsource.IndexOf(":")) + "** ( "; kdsource = kdsource.Remove(0, kdsource.IndexOf("KDAEach")); kdsource = kdsource.Remove(0, kdsource.IndexOf("Kill") + 6); def = def + kdsource.Remove(kdsource.IndexOf("<")); kdsource = kdsource.Remove(0, kdsource.IndexOf("Death") + 7); def = def + " / " + kdsource.Remove(kdsource.IndexOf("<")); kdsource = kdsource.Remove(0, kdsource.IndexOf("Assist") + 8); def = def + " / " + kdsource.Remove(kdsource.IndexOf("<")) + " )"; embed.AddField(def.Remove(def.IndexOf("-")), def.Remove(0, def.IndexOf("-") + 1)); } else { await ReplyAsync("That Summoner has not been placed yet this season"); return; } await ReplyAsync("", false, embed.Build()); } }
public async Task Define([Remainder] string word) { var db = new BotBaseContext(); var dictId = db.Variable.AsQueryable().Where(v => v.Name == "dictId").First(); var dictKey = db.Variable.AsQueryable().Where(v => v.Name == "dictKey").First(); bool multiple = false; HttpClient client = new HttpClient(); client.BaseAddress = new Uri("https://od-api.oxforddictionaries.com/api/v2/entries/en/"); client.DefaultRequestHeaders.Add("app_id", dictId.Value); client.DefaultRequestHeaders.Add("app_key", dictKey.Value); if (word.EndsWith(" -m")) { word = word.Replace(" -m", ""); multiple = true; } HttpResponseMessage response = await client.GetAsync(word); if (response.StatusCode.ToString() == "NotFound") { await Context.Channel.SendFileAsync("Media/damage.png"); return; } if (response.StatusCode.ToString() == "Forbidden") { await ReplyAsync("Unable to retrieve definition"); return; } HttpContent content = response.Content; string stuff = await content.ReadAsStringAsync(); var json = JObject.Parse(stuff); if (multiple) { var embed = new JifBotEmbedBuilder(); string def = "1.) " + (string)json.SelectToken("results[0].lexicalEntries[0].entries[0].senses[0].definitions[0]"); string example = (string)json.SelectToken("results[0].lexicalEntries[0].entries[0].senses[0].examples[0].text"); if (example == null) { example = "(no example available)"; } embed.AddField(def, example); for (int i = 0; i < 4; i++) { def = (string)json.SelectToken("results[0].lexicalEntries[0].entries[0].senses[0].subsenses[" + i.ToString() + "].definitions[0]"); example = (string)json.SelectToken("results[0].lexicalEntries[0].entries[0].senses[0].subsenses[" + i.ToString() + "].examples[0].text"); if (def != null) { def = (i + 2).ToString() + ".) " + def; if (example == null) { example = "(no example available)"; } embed.AddField(def, example); } } await ReplyAsync("", false, embed.Build()); } else { CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture; TextInfo textInfo = cultureInfo.TextInfo; string name = textInfo.ToTitleCase(word); var type = json.SelectToken("results[0].lexicalEntries[0].lexicalCategory.text"); string spelling = (string)json.SelectToken("results[0].lexicalEntries[0].pronunciations[0].phoneticSpelling"); string definition = (string)json.SelectToken("results[0].lexicalEntries[0].entries[0].senses[0].definitions[0]"); string example = (string)json.SelectToken("results[0].lexicalEntries[0].entries[0].senses[0].examples[0].text"); string message = name + " (" + type + ")"; if (spelling != null) { message += " /" + spelling + "/"; } message += "\n**Definition: **" + definition; if (example != null) { message += "\n**Example: **" + example; } await ReplyAsync(message); } }