private async Task HandleCommand(SocketSlashCommand command)
        {
            if (command.CommandName != "randomimage")
            {
                return;
            }
            SocketTextChannel channel = command.Channel as SocketTextChannel;

            if (channel != null && !_whitelist.ObjectOK("randomimage", channel.Id))
            {
                await command.RespondAsync("You can only use this command in the allowed channels", ephemeral : true);

                return;
            }
            if (command.Data.Options.Count == 0)
            {
                await command.RespondAsync("You must select a channel");

                return;
            }
            SocketSlashCommandDataOption option = command.Data.Options.First <SocketSlashCommandDataOption>();
            SocketTextChannel            stc    = option.Value as SocketTextChannel;

            if (stc == null)
            {
                await command.RespondAsync("This command only works in text channels", ephemeral : true);

                return;
            }
            if (!channel.IsNsfw && stc.IsNsfw)
            {
                await command.RespondAsync("You can only show sfw images in sfw channels!", ephemeral : true);

                return;
            }
            await PostImage(command, stc.Id);
        }
Esempio n. 2
0
 public override Task <TypeConverterResult> ReadAsync(IInteractionCommandContext context, SocketSlashCommandDataOption option, IServiceProvider services)
 {
     if (Enum.TryParse <T>((string)option.Value, out var result))
     {
         return(Task.FromResult(TypeConverterResult.FromSuccess(result)));
     }
     else
     {
         return(Task.FromResult(TypeConverterResult.FromError(InteractionCommandError.ConvertFailed, $"Value {option.Value} cannot be converted to {nameof(T)}")));
     }
 }