private async Task PrintImagesAsync(DiscordChannel channel, IEnumerable <IGalleryItem> results, int num) { if (!results.Any()) { await channel.InformFailureAsync("No results..."); return; } try { foreach (var im in results) { if (im.GetType().Name == "GalleryImage") { var img = ((GalleryImage)im); if (img.Nsfw != null && img.Nsfw == true && !channel.IsNSFW && !channel.Name.StartsWith("nsfw", StringComparison.InvariantCultureIgnoreCase)) { throw new CommandFailedException("This is not a NSFW channel!"); } await channel.SendMessageAsync(embed : new DiscordEmbedBuilder() { Color = this.ModuleColor, ImageUrl = img.Link }.Build()); } else if (im.GetType().Name == "GalleryAlbum") { var img = ((GalleryAlbum)im); if (img.Nsfw != null && img.Nsfw == true && !channel.IsNSFW && !channel.Name.StartsWith("nsfw", StringComparison.InvariantCultureIgnoreCase)) { throw new CommandFailedException("This is not a NSFW channel!"); } await channel.SendMessageAsync(embed : new DiscordEmbedBuilder() { Color = this.ModuleColor, ImageUrl = img.Link }.Build()); } else { throw new CommandFailedException("Imgur API error."); } await Task.Delay(TimeSpan.FromSeconds(1)); } } catch (ImgurException e) { throw new CommandFailedException("Imgur API error.", e); } if (results.Count() != num) { await channel.InformFailureAsync("These are all of the results returned."); } }
public static async Task <bool> WaitForBoolResponseAsync(this DiscordChannel channel, CommandContext ctx, string question, bool reply = true) { await channel.SendMessageAsync(embed : new DiscordEmbedBuilder { Description = $"{StaticDiscordEmoji.Question} {question} (y/n)", Color = DiscordColor.Yellow }); if (await ctx.Client.GetInteractivity().WaitForBoolReplyAsync(channel.Id, ctx.User.Id)) { return(true); } if (reply) { await channel.InformFailureAsync("Alright, aborting..."); } return(false); }