private async Task PrintImagesAsync(DiscordChannel channel, IEnumerable <IGalleryItem> results, int num) { if (!results.Any()) { await channel.InformOfFailureAsync("No results..."); return; } try { foreach (var im in results) { if (im.GetType().Name == "GalleryImage") { var img = ((GalleryImage)im); if (!(img.Nsfw is 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 is 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.InformOfFailureAsync("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.InformOfFailureAsync("Alright, aborting..."); } return(false); }
public static async Task <bool> WaitForBoolReplyAsync(this CommandContext ctx, string question, DiscordChannel channel = null, bool reply = true) { channel = channel ?? ctx.Channel; await ctx.RespondAsync(embed : new DiscordEmbedBuilder { Description = $"{StaticDiscordEmoji.Question} {question} (y/n)", Color = DiscordColor.Yellow }); if (await ctx.Client.GetInteractivity().WaitForBoolReplyAsync(ctx)) { return(true); } if (reply) { await channel.InformOfFailureAsync("Alrighty, aboring..."); } return(false); }