示例#1
0
 public override Task <PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
 {
     if (PermHandler.IsAdmin(context.User.Id))
     {
         return(Task.Run(() => PreconditionResult.FromSuccess()));
     }
     return(Task.Run(() => PreconditionResult.FromError("Not an Admin.")));
 }
示例#2
0
        private async Task HandleCommandAsync(SocketMessage messageParam)
        {
            SocketUserMessage message = messageParam as SocketUserMessage;

            if (message == null || (PermHandler.BlackListed(message.Channel as SocketTextChannel) && !PermHandler.IsAdmin(message.Author.Id)))
            {
                return;
            }
            int argPos = 0;

            if (!message.HasCharPrefix('-', ref argPos))
            {
                return;
            }
            SocketCommandContext context = new SocketCommandContext(Client, message);
            IResult result = await Commands.ExecuteAsync(context, argPos, Services);

            if (!result.IsSuccess)
            {
                switch (result.Error)
                {
                case CommandError.UnknownCommand:
                    await context.Channel.SendMessageAsync("Unknown command. Try `-help` for list of commands!");

                    break;

                case CommandError.BadArgCount:
                    await context.Channel.SendMessageAsync("Wrong input! Please try something else.");

                    break;

                case CommandError.UnmetPrecondition:
                    await context.Channel.SendMessageAsync("You can not use this command!");

                    break;

                default:
                    if (PermHandler.IsAdmin(context.Message.Author.Id))
                    {
                        await context.Message.Author.SendMessageAsync(result.ErrorReason);

                        await context.Channel.SendMessageAsync("Something went wrong! Please tell an admin! :(");
                    }
                    else
                    {
                        await context.Channel.SendMessageAsync("Something went wrong! Please tell an admin! :(");
                    }
                    break;
                }
            }
        }