Exemple #1
0
        public async Task OnCommandExecutedAsync(Optional <CommandInfo> command, ICommandContext ctx, IResult result)
        {
            try
            {
                CustomCommandContext context = (CustomCommandContext)ctx;
                if (!result.IsSuccess && command.IsSpecified)
                {
                    await BabResult(command.Value, context, result);
                }
                else
                {
                    if (context.guildSettings != null)
                    {
                        context.guildSettings.activityScore++;
                        context.guildSettings.SaveSettings();
                    }

                    if (Program.data != null && Program.data.activity != null)
                    {
                        Program.data.activity.Activity(ctx.User.Id);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogS(e);
            }

            running.Remove(ctx.User.Id);
        }
Exemple #2
0
        public async Task <IUserMessage> StartBlackJack(CustomCommandContext context, InteractiveBase interactiveBase, ICriterion <SocketReaction> criterion)
        {
            var callback = new ReactionResponseCallback(this, interactiveBase, context, criterion, _blackJackService);
            await callback.DisplayAsync().ConfigureAwait(false);

            return(callback.Message);
        }
Exemple #3
0
        private async Task HandleCommandAsync(SocketMessage s)
        {
            if (Program.CurrentState == Program.State.Booting || Program.CurrentState == Program.State.Exiting || s.Author.IsBot)
            {
                return;
            }

            GuildSettings guildSet = GuildSettings.Load(s);

            if (!(s is SocketUserMessage msg) || (guildSet != null && guildSet.Ignore))
            {
                return;
            }

            CustomCommandContext context = new CustomCommandContext(_client, msg)
            {
                guildSettings = guildSet
            };

            string prefix = guildSet == null ? "" : guildSet.prefix == null || guildSet.prefix.Length < 1 ? defaultPrefix : guildSet.prefix;

            if (MessageIsApproved(msg, prefix, out int argPosition) && await GameMaster.VerifyChannel(context, guildSet))
            {
                switch (Program.CurrentState)
                {
                case Program.State.Paused:
                    if (s.Author.Id != 201875246091993088)
                    {
                        DUtils.DeleteMessage(await context.Channel.SendMessageAsync(
                                                 "Server under maintenance, please refer to the support server for more information."));
                        return;
                    }
                    break;

                case Program.State.Ready: break;

                case Program.State.Updating:
                    DUtils.DeleteMessage(await context.Channel.SendMessageAsync("Leaving for tea break soon. [Incoming Update]"));
                    break;
                }

                if (!RunUser(s.Author.Id))
                {
                    return;
                }

                _ = context.BotUser;
                _ = Task.Run(async() =>
                {
                    try
                    {
                        await _command.ExecuteAsync(context, argPosition, null);
                    }
                    catch (Exception e)
                    {
                        Log.LogS(e);
                    }
                });
            }
        }
        public async Task MessageRecivedAsync(CustomCommandContext baseContext, string message)
        {
            if (baseContext.Prefix is null || baseContext.Prefix == "")
            {
                throw new NullPrefixException("Prefix cannont be null or blank.");
            }

            if (message[0] == '#')
            {
                var rest = message[1..];
Exemple #5
0
        public async Task <IUserMessage> ReplyAndDeleteAsync(CustomCommandContext context, string content, bool isTts = false, Embed embed = null, TimeSpan?timeout = null, RequestOptions options = null)
        {
            timeout = timeout ?? _defaultTimeout;
            var message = await context.Channel.SendMessageAsync(content, isTts, embed, options).ConfigureAwait(false);

            await Task.Delay(timeout.Value)
            .ContinueWith(_ => message.DeleteAsync().ConfigureAwait(false))
            .ConfigureAwait(false);

            return(message);
        }
 public PaginatedMessageCallback(InteractiveService interactive,
                                 CustomCommandContext sourceContext,
                                 PaginatedMessage pager,
                                 ICriterion <SocketReaction> criterion = null)
 {
     Interactive = interactive;
     Context     = sourceContext;
     Criterion   = criterion ?? new EmptyCriterion <SocketReaction>();
     _pager      = pager;
     _pages      = _pager.Pages.Count();
 }
        public async Task <bool> JudgeAsync(CustomCommandContext sourceContext, T parameter)
        {
            foreach (var criterion in _critiera)
            {
                var result = await criterion.JudgeAsync(sourceContext, parameter).ConfigureAwait(false);

                if (!result)
                {
                    return(false);
                }
            }
            return(true);
        }
 public ReactionResponseCallback(InteractiveService interactive,
                                 InteractiveBase interactiveBase,
                                 CustomCommandContext sourceContext,
                                 ICriterion <SocketReaction> criterion = null,
                                 BlackJackService blackJackService     = null)
 {
     InteractiveBase  = interactiveBase;
     Timeout          = TimeSpan.FromSeconds(30);
     Interactive      = interactive;
     Context          = sourceContext;
     Criterion        = criterion ?? new EmptyCriterion <SocketReaction>();
     BlackJackService = blackJackService;
 }
Exemple #9
0
        public Task <SocketMessage> NextMessageAsync(CustomCommandContext context, bool fromSourceUser = true, bool inSourceChannel = true, TimeSpan?timeout = null)
        {
            var criterion = new Criteria <SocketMessage>();

            if (fromSourceUser)
            {
                criterion.AddCriterion(new EnsureSourceUserCriterion());
            }
            if (inSourceChannel)
            {
                criterion.AddCriterion(new EnsureSourceChannelCriterion());
            }
            return(NextMessageAsync(context, criterion, timeout));
        }
Exemple #10
0
        internal void RecordCommand(CommandInfo command, CustomCommandContext context)
        {
            if (command == null)
            {
                return;
            }
            var profile = _guildhelper.GetProfile(context.Guild.Id, context.User.Id);

            if (!profile.Commands.ContainsKey(command.Name))
            {
                profile.Commands.Add(command.Name, 0);
            }
            profile.Commands[command.Name]++;
            _guildhelper.SaveProfile(context.Guild.Id, context.User.Id, profile);
        }
Exemple #11
0
        public async Task MessageReceived(SlackMessage message)
        {
            if (message.User.IsBot)
            {
                return;
            }

            if (!CommandUtilities.HasPrefix(message.Text, $"<@{_connection.Self.Id}> ", out var output))
            {
                return;
            }

            var context = new CustomCommandContext(message, _connection);

            await _commandService.ExecuteAsync(output, context, _serviceProvider);
        }
Exemple #12
0
        public ChessMatchModel AcceptChallenge(CustomCommandContext context, IUser player)
        {
            var challenge = _chessHelper.GetChallenge(context.Guild.Id, context.Channel.Id, player.Id, true);

            if (challenge == null)
            {
                throw new ChessException("No challenge exists for you to accept.");
            }

            if (_chessHelper.CheckPlayerInMatch(context.Guild.Id, challenge.ChallengeeId))
            {
                throw new ChessException(string.Format("{0} is currently in a game.",
                                                       context.Guild.GetUser(challenge.ChallengeeId)));
            }

            var challengee = context.Client.GetUser(challenge.ChallengeeId);
            var challenger = context.Client.GetUser(challenge.ChallengerId);

            var blackUrl = challengee.GetAvatarUrl() ?? challengee.GetDefaultAvatarUrl();
            var whiteUrl = challenger.GetAvatarUrl() ?? challenger.GetDefaultAvatarUrl();

            return(_chessHelper.AcceptChallenge(challenge, blackUrl, whiteUrl));
        }
Exemple #13
0
        internal static async Task <bool> CommandErrorType(CommandInfo method, CustomCommandContext context, IResult result)
        {
            switch (result.Error)
            {
            case CommandError.Exception: return(false);

            case CommandError.UnknownCommand: await context.Channel.SendMessageAsync("Hmm?"); return(true);

            case CommandError.ParseFailed:
            case CommandError.BadArgCount:
            {
                await context.Channel.SendMessageAsync($"`{result.ErrorReason}` {Environment.NewLine}" +
                                                       $"Type `{context.Prefix}chelp {method.Name}` for more details",
                                                       embed : new AMI.CommandsHandler.CommandInfoEmbed(method, context.Prefix, true).Embed);
            }
                return(true);

            default:
                await context.Channel.SendMessageAsync($"Muo, something went wrong. `{result.ErrorReason}`");

                Log.LogS(result.ErrorReason);
                return(true);
            }
        }
 private static string GetPrefix(CustomCommandContext context)
 => context.Server.Prefix;
Exemple #15
0
        public Task <bool> JudgeAsync(CustomCommandContext sourceContext, SocketMessage parameter)
        {
            bool ok = int.TryParse(parameter.Content, out _);

            return(Task.FromResult(ok));
        }
Exemple #16
0
        internal async Task CommandHandlerAsync(SocketMessage message)
        {
            if (!(message is SocketUserMessage msg))
            {
                return;
            }
            var argPos = 0;

            var context = new CustomCommandContext(_discord, msg, _provider);

            if (context.Config.Blacklist.Contains(msg.Author.Id) || _guildhelper.GetProfile(context.Guild.Id, context.User.Id).IsBlacklisted ||
                msg.Author.IsBot || context.Server.BlackListedChannels.Contains(context.Channel.Id))
            {
                return;
            }


            if (!(msg.HasStringPrefix(context.Server.Prefix, ref argPos) || msg.HasMentionPrefix(context.Client.CurrentUser, ref argPos)) ||
                msg.Source != MessageSource.User)
            {
                return;
            }
            if (msg.Content == context.Server.Prefix)
            {
                await _commands.ExecuteAsync(context, "?", _provider);

                return;
            }
            var result = await _commands.ExecuteAsync(context, argPos, _provider, MultiMatchHandling.Best);

            var search  = _commands.Search(context, argPos);
            var command = search.IsSuccess ? search.Commands.FirstOrDefault().Command : null;

            switch (result.Error)
            {
            case CommandError.Exception:
                PrettyConsole.Log(LogSeverity.Error, "Exception", result.ErrorReason);
                break;

            case CommandError.UnmetPrecondition:
                if (!result.ErrorReason.Contains("SendMessages"))
                {
                    await context.Channel.SendMessageAsync(embed : new EmbedBuilder().WithErrorColor()
                                                           .WithDescription(result.ErrorReason).Build());
                }
                break;

            case CommandError.UnknownCommand:
                break;

            case CommandError.ParseFailed:
                break;

            case CommandError.BadArgCount:
                break;

            case CommandError.ObjectNotFound:
                await context.Channel.SendMessageAsync(embed : new EmbedBuilder().WithErrorColor()
                                                       .WithDescription(result.ErrorReason).Build());

                break;

            case CommandError.MultipleMatches:
                break;

            case CommandError.Unsuccessful:
                break;
            }
            await Task.Run(() => RecordCommand(command, context));
        }
Exemple #17
0
        async Task BabResult(CommandInfo method, CustomCommandContext context, IResult result)
        {
            if (await CommandErrorType(method, context, result))
            {
                return;
            }

            var exception = ((ExecuteResult)result).Exception;

            if (!NeitsilliaError.Is(exception, NeitsilliaError.NeitsilliaErrorType.CharacterDoesNotExist))
            {
                string prefix = context.Prefix;
                await context.Channel.SendMessageAsync(
                    $"Character was not found, please load a character `{prefix}load charnamehere` from your characters list `{prefix}List Characters`" +
                    $" OR create a new character `{prefix}new char charnamehere`");
            }
            else if (exception is Discord.Net.HttpException httpException)
            {
                switch (httpException.HttpCode)
                {
                case System.Net.HttpStatusCode.Forbidden:
                {
                    string requiredPerms = null;

                    var client = (IGuildUser)await context.Channel.GetUserAsync(Program.clientCopy.CurrentUser.Id);

                    var chanPerms = client.GetPermissions((IGuildChannel)context.Channel);
                    if (!chanPerms.Has(ChannelPermission.EmbedLinks))
                    {
                        requiredPerms += "Embed Links" + Environment.NewLine;
                    }
                    if (!chanPerms.Has(ChannelPermission.AddReactions))
                    {
                        requiredPerms += "Add Reactions" + Environment.NewLine;
                    }
                    if (!chanPerms.Has(ChannelPermission.ReadMessageHistory))
                    {
                        requiredPerms += "Read Message History" + Environment.NewLine;
                    }
                    if (!chanPerms.Has(ChannelPermission.AttachFiles))
                    {
                        requiredPerms += "Attach Files" + Environment.NewLine;
                    }
                    if (!chanPerms.Has(ChannelPermission.UseExternalEmojis))
                    {
                        requiredPerms += "Use External Emojis" + Environment.NewLine;
                    }

                    if (requiredPerms != null)
                    {
                        requiredPerms = " | Required Permissions: " + Environment.NewLine + requiredPerms;
                    }
                    else
                    {
                        requiredPerms = " | Unknown permission missing";
                    }

                    await context.Channel.SendMessageAsync(httpException.Reason + requiredPerms);
                }
                break;

                case System.Net.HttpStatusCode.BadRequest:
                {
                    await UniqueChannels.Instance.SendToLog(httpException.ToString());
                } break;

                default:
                    await context.Channel.SendMessageAsync(httpException.ToString());

                    break;
                }

                return;
            }

            bool log = true;

            try
            {
                log = !await NeitsilliaError.SpecialExceptions(exception, context.Channel, context.BotUser);
            }
            catch (Exception e)
            {
                string info = result.ErrorReason;
                try { info += " ||" + e.StackTrace; }
                catch (Exception b)
                {
                    Log.LogS(b.Message + " => " + b.StackTrace);
                }
                var er = $"Exception Type: {NeitsilliaError.GetType(e)}" + Environment.NewLine +
                         $" =>  {info} ";
                Log.LogS(er);
                await AMI.Handlers.UniqueChannels.Instance.SendToLog(e, null, context.Channel);
            }
            if (log)
            {
                string info = result.ErrorReason;
                try { info += " ||" + exception.StackTrace; }
                catch (Exception e)
                {
                    Log.LogS(e.Message + " => " + e.StackTrace);
                }
                string er = $"Exception Type: {NeitsilliaError.GetType(exception)}" + Environment.NewLine +
                            $" Guild: {(context.Guild != null ? context.Guild.Id.ToString() : "DMs")} | Channel: {context.Channel.Id}" +
                            $" | ''{context.Message.Content}''  =>  {info} ";
                Log.LogS(er);
                await UniqueChannels.Instance.SendToLog(er);
            }
        }
        public Task <bool> JudgeAsync(CustomCommandContext sourceContext, SocketReaction parameter)
        {
            bool ok = parameter.UserId == sourceContext.User.Id;

            return(Task.FromResult(ok));
        }
Exemple #19
0
        public Task <bool> JudgeAsync(CustomCommandContext sourceContext, IMessage parameter)
        {
            var ok = sourceContext.User.Id == parameter.Author.Id;

            return(Task.FromResult(ok));
        }
 public Task <bool> JudgeAsync(CustomCommandContext sourceContext, T parameter)
 => Task.FromResult(true);