Пример #1
0
        public async Task ToggleModule([Remainder] string name)
        {
            var cmdService = Program.GetCommands();
            var module     = cmdService.Modules.SingleOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            if (module == null)
            {
                await ReplyAsync($":x: There is no module called `{name}`");

                return;
            }

            if (module.Name.Equals("Server") || module.Name.Equals("Basic"))
            {
                await ReplyAsync($":x: The **{module.Name}** module can't be disabled.");

                return;
            }

            if (await DisabledCommandHandler.AddNew(module.Name, Context.Guild.Id, DisabledCommandType.Module))
            {
                await ReplyAsync($":star: Module **{module.Name}** disabled... Use the same command again to re-enable");

                return;
            }
            else
            {
                await DisabledCommandHandler.Remove(module.Name, Context.Guild.Id, DisabledCommandType.Module);
                await ReplyAsync($":star: Module **{module.Name}** re-enabled.");

                return;
            }
        }
Пример #2
0
        public async Task ToggleReactionImages([Remainder] string name = "")
        {
            if (await DisabledCommandHandler.AddNew(name, Context.Guild.Id, DisabledCommandType.Images))
            {
                await ReplyAsync($":star: **Reaction images** disabled... Use the same command again to re-enable");

                return;
            }
            else
            {
                await DisabledCommandHandler.Remove(name, Context.Guild.Id, DisabledCommandType.Images);
                await ReplyAsync($":star: **Reaction images** re-enabled.");

                return;
            }
        }
Пример #3
0
        public async Task <bool> SendRandomImage(ICommandContext Context)
        {
            if (Context.Guild != null && DisabledCommandHandler.IsDisabled("", Context.Guild.Id, DisabledCommandType.Images))
            {
                return(false);
            }

            string text = Context.Message.Content;

            text = text.Replace(Program.GetPrefix(Context.Guild), "");
            text = text.Split(' ')[0];

            if (!ReactionImageCommands.Contains(text))
            {
                return(false);
            }

            text = text.ToLower();
            var image = Context.Guild == null ? null : ImageDb.GetRandomImage(text, Context.Guild.Id);

            if (image == null)
            {
                image = ImageDb.GetRandomImage(text);
                if (image == null)
                {
                    return(false);
                }
            }

            if (!RateLimit.CanExecute(Context.Channel.Id))
            {
                await Context.Channel.SendMessageAsync($"Woah there, Senpai, calm down! I locked this channel for **{RateLimit.InvokeLockoutPeriod.Seconds}** seconds <:MeguExploded:627470499278094337>\n" +
                                                       $"You can only use **{RateLimit.InvokeLimit}** commands per **{RateLimit.InvokeLimitPeriod.Seconds}** seconds per channel.");

                return(false);
            }

            var embed = ImageUtil.ToEmbed(image).Build();
            await Context.Channel.SendMessageAsync("", false, embed);

            return(true);
        }
Пример #4
0
        public async Task ToggleCommand([Remainder] string name)
        {
            var cmdService = Program.GetCommands();
            var command    = cmdService.Commands.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

            if (command == null)
            {
                await ReplyAsync($":x: There is no command called `{name}`");

                return;
            }

            if (command.Name.Equals("ToggleModule") ||
                command.Name.Equals("ToggleCommand") ||
                command.Name.Equals("ToggleReactionImages") ||
                command.Name.Equals("ListDisabledCommands"))
            {
                await ReplyAsync($":x: The **{command.Name}** command can't be disabled.");

                return;
            }

            if (await DisabledCommandHandler.AddNew(command.Name, Context.Guild.Id, DisabledCommandType.Command))
            {
                await ReplyAsync($":star: Command **{command.Name}** disabled... Use the same command again to re-enable");

                return;
            }
            else
            {
                await DisabledCommandHandler.Remove(command.Name, Context.Guild.Id, DisabledCommandType.Command);
                await ReplyAsync($":star: Command **{command.Name}** re-enabled.");

                return;
            }
        }
Пример #5
0
        // COMMANDS

        private async Task Client_ReadCommand(SocketMessage MessageParam)
        {
            if (Client == null)
            {
                return;
            }

            if (!(MessageParam is SocketUserMessage Message))
            {
                return;
            }

            var    Context = new ShardedCommandContext(Client, Message);
            string prefix  = GetPrefix(Context);

            if (Blacklist.Contains(Context.User.Id) || (Context.Guild != null && Blacklist.Contains(Context.Guild.Id)) || (Context.Channel != null && Blacklist.Contains(Context.Channel.Id)))
            {
                return;
            }
            if (Context.User.IsBot)
            {
                return;
            }
            if (Context.Message == null || Context.Message.Content == "")
            {
                return;
            }
            if (BlacklistedChannelDb.IsBlacklisted(Context.Channel.Id))
            {
                return;
            }
            if (RateLimit.InvokeLockout.TryGetValue(Context.Channel.Id, out var time) && time > DateTime.Now)
            {
                return;
            }

            await SpecialModeResponse(Context);
            await SpecialResponse(Message);

            int  ArgPos     = 0;
            bool isPrefixed = Message.HasStringPrefix(prefix, ref ArgPos) || Message.HasMentionPrefix(Client.CurrentUser, ref ArgPos);

            if (!isPrefixed && !Pause)
            {
                await Blackjack.BlackjackInput(Context);

                return;
            }

            if (!isPrefixed)
            {
                return;
            }

            var cmds = Commands.Search(Context, ArgPos);

            if (cmds.IsSuccess)
            {
                if (Context.Guild != null && cmds.Commands.Any(x => DisabledCommandHandler.IsDisabled(x.Command.Name, Context.Guild.Id, DisabledCommandType.Command)))
                {
                    return;
                }
                else if (Context.Guild != null && cmds.Commands.Any(x => DisabledCommandHandler.IsDisabled(x.Command.Module.Name, Context.Guild.Id, DisabledCommandType.Module)))
                {
                    return;
                }

                else if (!RateLimit.CanExecute(Context.Channel.Id))
                {
                    await Context.Channel.SendMessageAsync($"Woah there, Senpai, calm down! I locked this channel for **{RateLimit.InvokeLockoutPeriod.Seconds}** seconds <:MeguExploded:627470499278094337>\n" +
                                                           $"You can only use **{RateLimit.InvokeLimit}** commands per **{RateLimit.InvokeLimitPeriod.Seconds}** seconds per channel.");

                    return;
                }

                else if (Pause && Context.User.Id != AppSettings.OwnerId)
                {
                    await Context.Channel.SendMessageAsync("Commands disabled temporarily. Try again later.");

                    return;
                }

                else if (Context.Channel is SocketTextChannel ch &&
                         (!ch.Guild.CurrentUser.GetPermissions(ch).Has(ChannelPermission.SendMessages) || !ch.Guild.CurrentUser.GetPermissions(ch).Has(ChannelPermission.EmbedLinks)))
                {
                    var dm = await Context.User.CreateDMChannelAsync();

                    await dm.SendMessageAsync(embed : new EmbedBuilderPrepared(Context.Guild.CurrentUser)
                                              .WithDescription($"I don't have permission to reply to you in **{ch.Name}**.\n" +
                                                               $"Make sure I have a role that allows me to send messages and embed links in the channels you want to use me in.")
                                              .WithImageUrl("https://i.imgur.com/lrPHjyt.png")
                                              .Build());

                    return;
                }
            }

            _ = Commands.ExecuteAsync(Context, ArgPos, Services);
        }