예제 #1
0
파일: Server.cs 프로젝트: ta1H3n/Namiko
        public async Task BlacklistChannel(ulong channelId = 0)
        {
            if (channelId == 0)
            {
                channelId = Context.Channel.Id;
            }

            else if (Context.Guild.GetChannel(channelId) == null)
            {
                await Context.Channel.SendMessageAsync("Can't find channel.");

                return;
            }

            if (BlacklistedChannelDb.IsBlacklisted(channelId))
            {
                await BlacklistedChannelDb.DeleteBlacklistedChannel(channelId);

                await Context.Channel.SendMessageAsync("Channel unblacklisted.");

                return;
            }

            await BlacklistedChannelDb.UpdateBlacklistedChannel(new BlacklistedChannel { ChannelId = channelId });

            await Context.Channel.SendMessageAsync($"Channel blacklisted. Use `{Program.GetPrefix(Context)}blch [channel_id]` in another channel to undo.\n The ID of this channel is `{Context.Channel.Id}`.");
        }
예제 #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);
        }