Exemplo n.º 1
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            if (!(s is SocketUserMessage msg) || msg.Author.IsBot || msg.Channel is SocketDMChannel)
            {
                return;
            }

            var clientPrefix = false;
            var argPos       = 0;
            var context      = new CommandContextWithPrefix(_client, msg);
            var guild        = await _guild.GetGuild(context.Guild.Id);

            context.Prefix = guild.Prefix;

            await _points.GivePoints(context.User.Id, context.Guild.Id).ConfigureAwait(false);

            if (!(msg.HasStringPrefix(guild.Prefix, ref argPos) ||
                  (clientPrefix = msg.HasMentionPrefix(_client.CurrentUser, ref argPos))))
            {
                return;
            }

            await s.Channel.TriggerTypingAsync();

            var result = await _service.ExecuteAsync(context, argPos, _provider);

            if (!result.IsSuccess)
            {
                await HandleResultAsync(result, context, guild, clientPrefix);
            }
        }
Exemplo n.º 2
0
        private async Task <bool> HandleCustomCommandAsync(CommandContextWithPrefix context, AppGuild guild, bool clientPrefix)
        {
            if (!guild.CustomCommands.Any())
            {
                return(false);
            }
            var command = guild.CustomCommands.FirstOrDefault(f => f.Command == GetCommandFromMessage(context, clientPrefix));

            if (command == null)
            {
                return(false);
            }
            await context.Channel.SendMessageAsync(command.Message);

            return(true);
        }
Exemplo n.º 3
0
        private async Task HandleResultAsync(IResult result, CommandContextWithPrefix context, AppGuild guild, bool clientPrefix)
        {
            switch (result.Error)
            {
            case CommandError.UnmetPrecondition:
                await context.Channel.SendMessageAsync("You don't have the required permissions to use this command");

                return;

            case CommandError.UnknownCommand:
                if (await HandleCustomCommandAsync(context, guild, clientPrefix))
                {
                    return;
                }
                await context.Channel.SendMessageAsync($"Unknown command, for list of commands try using {context.Prefix}help");

                return;

            case CommandError.ParseFailed:
            case CommandError.BadArgCount:
                await context.Channel.SendMessageAsync($"Command wasn't used properly, try using {context.Prefix}help {GetCommandFromMessage(context, clientPrefix)}");

                return;

            case CommandError.Unsuccessful:
            case CommandError.Exception:
                await context.Channel.SendMessageAsync($"Command threw an exception, try reporting it using {context.Prefix}report <message>");

                return;

            default:
                await context.Channel.SendMessageAsync(result.ErrorReason);

                return;
            }
        }
Exemplo n.º 4
0
 private string GetCommandFromMessage(CommandContextWithPrefix context, bool clientPrefix) =>
 context.Message.Content.Replace(!clientPrefix ? context.Prefix : _client.CurrentUser.Mention.Replace("!", "") + " ", "").Split(' ')[0];