示例#1
0
文件: Images.cs 项目: ta1H3n/Namiko
        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);
        }
示例#2
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);
        }