public async Task DeleteImage(int id, [Remainder] string str = "") { bool insider = Context.Guild.Id == 418900885079588884; var image = ImageDb.GetImage(id); if (image == null) { await Context.Channel.SendMessageAsync($"There is no image with id: **{id}**"); return; } if (!insider && image.GuildId != Context.Guild.Id) { await Context.Channel.SendMessageAsync($"There is no image with id **{id}** in your guild."); return; } await ImageDb.DeleteImage(id); await Context.Channel.SendMessageAsync($"Image **{id}** is gone forever. Why have you done this?"); await ImgurAPI.EditImageAsync(ImgurAPI.ParseId(image.Url), null, image.Id.ToString() + " [DELETED]"); }
// SET-UP private static void SetUp() { switch (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")) { case "Development": Development = true; Pause = true; break; default: Console.WriteLine("Entry: " + Assembly.GetEntryAssembly().Location); _ = ImgurAPI.ImgurSetup(); break; } NamikoDbContext.ConnectionString = AppSettings.ConnectionString; _ = LootboxStats.Reload(Locations.LootboxStatsJSON); Prefixes = ServerDb.GetPrefixes(); Images.ReactionImageCommands = ImageDb.GetReactionImageCommandHashSet(); Blacklist = BlacklistDb.GetAll(); Waifu.Path = AppSettings.ImageUrlPath + "waifus/"; }
public async Task All(string name, [Remainder] string str = "") { var album = Context.Guild == null ? null : ImageDb.GetAlbum(name + Context.Guild.Id); var album2 = ImageDb.GetAlbum(name); string albums = album == null ? "" : $"<{ImgurAPI.ParseAlbumLink(album.AlbumId)}>"; if (album2 != null) { albums += $"\n<{ImgurAPI.ParseAlbumLink(album2.AlbumId)}>"; } if (albums == "") { await Context.Channel.SendMessageAsync($"Album **{name}** doesn't exist."); return; } await Context.Channel.SendMessageAsync(albums); }
public async Task NewImage(string name, string url = null, [Remainder] string str = "") { await Context.Channel.TriggerTypingAsync(); bool insider = Context.Guild.Id == 418900885079588884; url ??= Context.Message.Attachments.FirstOrDefault()?.Url; if (!insider) { if (!PremiumDb.IsPremium(Context.Guild.Id, ProType.GuildPlus)) { await Context.Channel.SendMessageAsync($"This server does not have Pro Guild+. `{Program.GetPrefix(Context)}pro`"); return; } if ((await ImageDb.GetImages(name, 0)).Any()) { await Context.Channel.SendMessageAsync($"There is already a default image command called **{name}**. It will be replaced with your custom one."); } } if (url == null) { await Context.Channel.SendMessageAsync("Can't get your attachment, there probably isn't one. *Heh, dummy...*"); return; } url = url.EndsWith(".gifv") ? url.Replace(".gifv", ".gif") : url; url = url.EndsWith(".mp4") ? url.Replace(".mp4", ".gif") : url; if (ImgurAPI.RateLimit.ClientRemaining < 50) { await ReplyAsync("Not enough imgur credits to upload. Please try again later."); return; } string albumId; string albumName = insider ? name : name + Context.Guild.Id; if (!ImageDb.AlbumExists(albumName)) { albumId = (await ImgurAPI.CreateAlbumAsync(albumName)).Id; await ImageDb.CreateAlbum(albumName, albumId); } else { albumId = ImageDb.GetAlbum(albumName).AlbumId; } var iImage = await ImgurAPI.UploadImageAsync(url, albumId); var img = await ImageDb.AddImage(name.ToLower(), iImage.Link, insider? 0 : Context.Guild.Id); if (!ReactionImageCommands.Contains(name.ToLower())) { ReactionImageCommands.Add(name.ToLower()); } await ImgurAPI.EditImageAsync(iImage.Id.ToString(), null, img.Id.ToString()); var rl = ImgurAPI.RateLimit; await ImageUtil.UploadReactionImage(img, Context.Channel); await Context.Channel.SendMessageAsync($"{rl.ClientRemaining-20}/{rl.ClientLimit} imgur credits remaining.", false, ImageUtil.ToEmbed(img).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); }
public async Task WaifuImage(string name, string url = null) { var waifu = await WaifuUtil.ProcessWaifuListAndRespond(await WaifuDb.SearchWaifus(name, true), this); if (waifu == null) { return; } await Context.Channel.TriggerTypingAsync(); url ??= Context.Message.Attachments.FirstOrDefault()?.Url; if (url == null) { await Context.Channel.SendMessageAsync("Can't get your attachment, there probably isn't one. *Heh, dummy...*"); return; } 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); string old = waifu.ImageUrl; waifu.ImageUrl = iImage.Link; await WaifuUtil.UploadWaifuImage(waifu, Context.Channel); if (await WaifuDb.UpdateWaifu(waifu) > 0) { await SendWaifuUpdatedMessage(waifu, "ImageUrl", old, waifu.ImageUrl); } else { await Context.Channel.SendMessageAsync($":x: Failed to update {name}"); } await Context.Channel.TriggerTypingAsync(); await WaifuUtil.FindAndUpdateWaifuImageSource(waifu, Context.Channel); }
public async Task NewWaifu(string name, int tier, 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 = tier, ImageUrl = url, Description = null, LongName = null }; await WaifuUtil.UploadWaifuImage(waifu, Context.Channel); if (await WaifuDb.AddWaifu(waifu) > 0) { await Context.Channel.SendMessageAsync($"{name} added."); } else { await Context.Channel.SendMessageAsync($"Failed to add {name}"); } await Context.Channel.TriggerTypingAsync(); await WaifuUtil.FindAndUpdateWaifuImageSource(waifu, Context.Channel); }
public async Task SetImgurRefreshToken(string refreshToken, [Remainder] string msg = "") { ImgurAPI.SetRefreshToken(refreshToken); await Context.Channel.SendMessageAsync("Done."); }
public async Task ImgurAuth([Remainder] string msg = "") { await Context.Channel.SendMessageAsync(ImgurAPI.GetAuthorizationUrl()); }