Example #1
0
        public async Task EnableLimits()
        {
            var hasLimitChannels = await _limits.GetLimitsAsync(Context.Guild.Id);

            if (hasLimitChannels.Count == 0)
            {
                await Context.Channel.TriggerTypingAsync();

                await Context.Channel.SendErrorAsync("Channel Limits", "There has not been any limit channel(s)!\nTo prevent lockouts, add some limit channels using the addlimit command!");

                return;
            }
            await Context.Channel.TriggerTypingAsync();

            await _servers.ModifyHasLimitAsync(Context.Guild.Id);

            var fetchedServerLimit = await _servers.GetHasLimitAsync(Context.Guild.Id);

            await _serverHelper.SendLogAsync(Context.Guild, "Situation Log", $"{Context.User.Mention} enabled limited mode!");

            await Context.Channel.SendSuccessAsync("Channel Limits", $"Successfully set the bot's channel limits to {fetchedServerLimit.ToString()}");
        }
Example #2
0
        private async Task OnMessageReceived(SocketMessage arg)
        {
            var guild = (arg.Channel as SocketTextChannel)?.Guild;

            if (!(arg is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }

            var firstTask = new Task(async() => await HandleAutomatedResponse(arg));

            firstTask.Start();

            var    argPos = 0;
            string prefix = "!";

            if (guild != null)
            {
                try {
                    var guildHasFilter = _servers.GetFilterAsync(guild.Id).Result;
                    if (guildHasFilter == true)
                    {
                        var newTask = new Task(async() => await HandleFilter(arg));
                        newTask.Start();
                    }
                }
                catch (Exception)
                {
                    await _servers.ClearFilterAsync(guild.Id);

                    await message.Channel.SendErrorAsync("Error", "Something went wrong, please try again, if the bot is unresponsive, contact Ribs#8205 on discord.");
                }
                try
                {
                    var guildHasLimit = _servers.GetHasLimitAsync(guild.Id).Result;
                    if (guildHasLimit == true)
                    {
                        var limits = await _limits.GetLimitsAsync(guild.Id);

                        if (!limits.Exists(x => x.ChannelId == arg.Channel.Id))
                        {
                            return;
                        }
                    }
                }
                catch (Exception)
                {
                    //await _servers.ClearHasLimitAsync(guild.Id);
                    await message.Channel.SendErrorAsync("Error", "Something went wrong, please try again, if the bot is unresponsive, contact Ribs#8205 on discord.");
                }

                prefix = await _servers.GetGuildPrefix((message.Channel as SocketGuildChannel).Guild.Id) ?? "!";

                if (!message.HasStringPrefix(prefix, ref argPos) && !message.HasMentionPrefix(_client.CurrentUser, ref argPos))
                {
                    return;
                }

                var context = new SocketCommandContext(_client, message);
                await _service.ExecuteAsync(context, argPos, _provider);
            }
            if ((message.Channel as IDMChannel) != null)
            {
                if (!message.HasStringPrefix(prefix, ref argPos) && !message.HasMentionPrefix(_client.CurrentUser, ref argPos))
                {
                    return;
                }

                var context = new SocketCommandContext(_client, message);
                await _service.ExecuteAsync(context, argPos, _provider);
            }
        }