public async Task AutocompleteWaifu(string name, long malId) { var waifu = await WaifuDb.GetWaifu(name); if (waifu == null) { await Context.Channel.SendMessageAsync($"**{name}** doesn't exist. *BAAAAAAAAAAAAAAAAAAKA*"); return; } var mal = await WebUtil.GetWaifu(malId); waifu.LongName = $"{mal.Name} ({mal.NameKanji})"; var about = mal.About; var lines = about.Split('\n'); string desc = ""; foreach (var line in lines) { if (line.Split(' ')[0].EndsWith(':')) { continue; } if (line.StartsWith('(')) { continue; } var l = Regex.Replace(line, @"\t|\n|\r|\\n|\\t|\\r", ""); if (l != "") { desc += l + "\n\n"; } } //desc.Replace(@"\r", @"\n\n"); waifu.Description = desc; waifu.Source = mal.Animeography.FirstOrDefault() == null ? "" : mal.Animeography.FirstOrDefault().Name; await WaifuDb.UpdateWaifu(waifu); await Context.Channel.SendMessageAsync($"Autocompleted **{waifu.Name}**. Has **{mal.MemberFavorites}** favorites.", false, WaifuUtil.WaifuEmbedBuilder(waifu, Context).Build()); }
public async Task NewWaifuAutocomplete(string name, long malId, string url = null) { var exists = await WaifuDb.GetWaifu(name); if (exists != null) { await ReplyAsync($"**{exists.Name}** is already a waifu."); return; } await Context.Channel.TriggerTypingAsync(); url ??= Context.Message.Attachments.FirstOrDefault()?.Url; if (url != null) { url = url.EndsWith(".gifv") ? url.Replace(".gifv", ".gif") : url; url = url.EndsWith(".mp4") ? url.Replace(".mp4", ".gif") : url; if (ImgurAPI.RateLimit.ClientRemaining < 15) { await ReplyAsync("Not enough imgur credits to upload. Please try again later."); return; } string albumId; if (!ImageDb.AlbumExists("Waifus")) { albumId = (await ImgurAPI.CreateAlbumAsync("Waifus")).Id; await ImageDb.CreateAlbum("Waifus", albumId); } else { albumId = ImageDb.GetAlbum("Waifus").AlbumId; } var iImage = await ImgurAPI.UploadImageAsync(url, albumId, null, name); url = iImage.Link; } var waifu = new Waifu { Name = name, Tier = 404, ImageUrl = url, Description = null, LongName = null }; await WaifuUtil.UploadWaifuImage(waifu, Context.Channel); var mal = await WebUtil.GetWaifu(malId); waifu.LongName = $"{mal.Name} ({mal.NameKanji})"; var about = mal.About; var lines = about.Split('\n'); string desc = ""; foreach (var line in lines) { if (line.Split(' ')[0].EndsWith(':')) { continue; } if (line.StartsWith('(')) { continue; } var l = Regex.Replace(line, @"\t|\n|\r|\\n|\\t|\\r", ""); if (l != "") { desc += l + "\n\n"; } } waifu.Description = desc; waifu.Source = mal.Animeography.FirstOrDefault() == null ? "" : mal.Animeography.FirstOrDefault().Name; try { waifu.Tier = WaifuUtil.FavoritesToTier(mal.MemberFavorites.Value); } catch { } if (waifu.Tier == 0) { waifu.Tier = 3; await Context.Channel.SendMessageAsync($"Not enough favorites! Are you sure you wish to create this waifu? Remove - `!dw {waifu.Name}`"); } if (await WaifuDb.AddWaifu(waifu) > 0) { await Context.Channel.SendMessageAsync ( $"Autocompleted **{waifu.Name}**. Has **{mal.MemberFavorites}** favorites.", embed : WaifuUtil.WaifuEmbedBuilder(waifu, Context).Build() ); await WaifuDb.AddMalWaifu(new MalWaifu { MalId = malId, WaifuName = waifu.Name, LastUpdated = DateTime.Now, MalConfirmed = true }); } else { await Context.Channel.SendMessageAsync("Rip"); } await Context.Channel.TriggerTypingAsync(); await WaifuUtil.FindAndUpdateWaifuImageSource(waifu, Context.Channel); }