public async Task randomPastebin() { p.doAction(Context.User, Context.Guild.Id, Program.Module.GoogleShortener); if (!(Context.Channel as ITextChannel).IsNsfw) { await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id)); } else { Tuple <string, string> result = null; try { result = await getUrl(); } catch (GoogleApiException ex) { if (ex.HttpStatusCode == HttpStatusCode.Forbidden) { await ReplyAsync(Sentences.tooManyRequests(Context.Guild.Id, "goo.gl")); return; } } if (result == null) { await ReplyAsync(Sentences.nothingAfterXIterations(Context.Guild.Id, 500)); } else { await ReplyAsync("I found something, here is the short URL: " + result.Item1 + Environment.NewLine + ((result != null) ? ("It'll lead you here: " + result.Item2) : ("It will lead you nowhere since the URL was disabled..."))); } } }
public async Task playShiritori(params string[] gameName) { p.doAction(Context.User, Context.Guild.Id, Program.Module.Game); if (p.games.Any(x => x.m_chan == Context.Channel)) { await ReplyAsync(Sentences.gameAlreadyRunning(Context.Guild.Id)); } else { string finalGameName = Program.addArgs(gameName); if (finalGameName == null || (finalGameName.ToLower() != "shiritori" && finalGameName.ToLower() != "kancolle" && finalGameName.ToLower() != "booru")) { await ReplyAsync(Sentences.invalidGameName(Context.Guild.Id)); } else { if (!p.gameThread.IsAlive) { p.gameThread.Start(); } Game g = null; if (finalGameName.ToLower() == "shiritori") { await ReplyAsync(Sentences.rulesShiritori(Context.Guild.Id)); g = new Shiritori(Context.Channel, Context.Guild, Context.User); } else if (finalGameName.ToLower() == "kancolle") { await ReplyAsync(Sentences.rulesKancolle(Context.Guild.Id)); g = new Kancolle(Context.Channel, Context.Guild, Context.User); } else if (finalGameName.ToLower() == "booru") { if (!(Context.Channel as ITextChannel).IsNsfw) { await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id)); return; } await ReplyAsync(Sentences.rulesBooru(Context.Guild.Id)); g = new BooruGame(Context.Channel, Context.Guild, Context.User); } p.games.Add(g); g.Post(); } } }
public async Task malManga(params string[] mangaNameArr) // Stuck in loop ? { p.doAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga); string mangaName = Program.addArgs(mangaNameArr); if (mangaName.Length == 0) { await ReplyAsync(Sentences.animeHelp(Context.Guild.Id)); return; } try { string result = p.malClient.DownloadString("https://myanimelist.net/api/manga/search.xml?q=" + mangaName.Replace(" ", "%20")); if (!result.Contains("<entry>")) { await ReplyAsync(Sentences.mangaNotFound(Context.Guild.Id)); } else { EmbedBuilder b = parseContent(result, mangaName, (Context.Channel as ITextChannel).IsNsfw); if (b == null) { await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id)); } else { await ReplyAsync("", false, b.Build()); } } } catch (WebException ex) { HttpWebResponse code = ex.Response as HttpWebResponse; if (code.StatusCode == HttpStatusCode.Forbidden) { await ReplyAsync(Sentences.tooManyRequests(Context.Guild.Id, "MyAnimeList")); } } }
#pragma warning restore CS1998 /// <summary> /// Get an image given various informations /// </summary> /// <param name="booru">Which booru is concerned (see above)</param> /// <param name="tags">Tags that need to be contain on the image</param> /// <param name="chan">Channel the image will be post in</param> /// <param name="currName">Temporary name of the file</param> /// <param name="isSfw">Is the channel safe for work ?</param> /// <param name="isGame">If the request from Game module (doesn't count dl for stats and don't get informations about tags)</param> public static async void getImage(Booru booru, string[] tags, ITextChannel chan, string currName, bool isSfw, bool isGame) { if (!isSfw && !chan.IsNsfw) { await chan.SendMessageAsync(Sentences.chanIsNotNsfw(chan.GuildId)); return; } IGuildUser me = await chan.Guild.GetUserAsync(Sentences.myId); if (!me.GuildPermissions.AttachFiles) { await chan.SendMessageAsync(Sentences.needAttachFile(chan.GuildId)); return; } if (!isGame) { await chan.SendMessageAsync(Sentences.prepareImage(chan.GuildId)); } string url = getBooruUrl(booru, tags); if (url == null) { await chan.SendMessageAsync(Sentences.tagsNotFound(tags)); } else { using (WebClient wc = new WebClient()) { wc.Headers.Add("User-Agent: Sanara"); string json = wc.DownloadString(url); string image = booru.getFileUrl(json); string imageName = currName + "." + image.Split('.')[image.Split('.').Length - 1]; wc.Headers.Add("User-Agent: Sanara"); wc.DownloadFile(image, imageName); FileInfo file = new FileInfo(imageName); Program.p.statsMonth[(int)booru.getId()] += file.Length; if (file.Length >= 8000000) { await chan.SendMessageAsync(Sentences.fileTooBig(chan.GuildId)); } else { while (true) { try { await chan.SendFileAsync(imageName); break; } catch (RateLimitedException) { } } if (!isGame) { List <string> finalStr = getTagsInfos(json, booru); foreach (string s in finalStr) { await chan.SendMessageAsync(s); } } } File.Delete(imageName); } if (!isGame) { string finalStrModule = ""; foreach (long i in Program.p.statsMonth) { finalStrModule += i + "|"; } finalStrModule = finalStrModule.Substring(0, finalStrModule.Length - 1); File.WriteAllText("Saves/MonthModules.dat", finalStrModule + Environment.NewLine + Program.p.lastMonthSent); } } }
public async Task getNhentai(params string[] keywords) { p.doAction(Context.User, Context.Guild.Id, Program.Module.Doujinshi); if (!(Context.Channel as ITextChannel).IsNsfw) { await ReplyAsync(Sentences.chanIsNotNsfw(Context.Guild.Id)); return; } string tags = ""; if (keywords.Length != 0) { foreach (string s in keywords) { tags += s + "+"; } tags = tags.Substring(0, tags.Length - 1); } string xml; using (WebClient w = new WebClient()) { w.Encoding = Encoding.UTF8; if (keywords.Length == 0) { xml = w.DownloadString("https://nhentai.net/api/galleries/all?page=0"); } else { xml = w.DownloadString("https://nhentai.net/api/galleries/search?query=" + tags + "&page=8000"); } } int page = p.rand.Next(Convert.ToInt32(Program.getElementXml("\"num_pages\":", xml, ','))) + 1; using (WebClient w = new WebClient()) { w.Encoding = Encoding.UTF8; if (keywords.Length == 0) { xml = w.DownloadString("https://nhentai.net/api/galleries/all?page=" + page); } else { xml = w.DownloadString("https://nhentai.net/api/galleries/search?query=" + tags + "&page=" + page); } } List <string> allDoujinshi = xml.Split(new string[] { "title" }, StringSplitOptions.None).ToList(); allDoujinshi.RemoveAt(0); if (allDoujinshi.Count == 0) { string[] allTags = tags.Split(new string[] { "+" }, StringSplitOptions.RemoveEmptyEntries); await ReplyAsync(Sentences.tagsNotFound(allTags)); } else { string curr = allDoujinshi[p.rand.Next(allDoujinshi.Count)]; string[] ids = curr.Split(new string[] { "}]" }, StringSplitOptions.None); string currBlock = ""; for (int i = ids.Length - 1; i >= 0; i--) { currBlock = Program.getElementXml("id\":", ids[i], ','); if (currBlock != "") { if (keywords.Length == 0) { await ReplyAsync("https://nhentai.net/g/" + currBlock); } else { string finalOk = ""; foreach (string t in keywords) { bool isOk = false; foreach (string s in ids[i - 1].Split(new string[] { "},{" }, StringSplitOptions.None)) { if (Program.getElementXml("\"name\":\"", s, '"').Contains(t)) { isOk = true; break; } } if (!isOk) { finalOk = t; break; } } if (finalOk == "") { await ReplyAsync("https://nhentai.net/g/" + currBlock); } else { await ReplyAsync(Sentences.tagsNotFound(new string[] { finalOk })); } } break; } } } }