예제 #1
0
        public async Task Enable(string type)
        {
            var success   = new List <bool>(0);
            var blocktype = ParseBlockType(type);

            switch (blocktype)
            {
            case BlockType.InstantInvite:
                success.Add(await AntiAds.TryEnableGuild(BlockType.InstantInvite, Context.Guild.Id));
                break;

            case BlockType.YoutubeLink:
                success.Add(await AntiAds.TryEnableGuild(BlockType.YoutubeLink, Context.Guild.Id));
                break;

            case BlockType.TwitchStream:
                success.Add(await AntiAds.TryEnableGuild(BlockType.TwitchStream, Context.Guild.Id));
                break;

            case BlockType.TwitchVideo:
                success.Add(await AntiAds.TryEnableGuild(BlockType.TwitchVideo, Context.Guild.Id));
                break;

            case BlockType.TwitchClip:
                success.Add(await AntiAds.TryEnableGuild(BlockType.TwitchClip, Context.Guild.Id));
                break;

            case BlockType.All:
                success.Add(await AntiAds.TryEnableGuild(BlockType.InstantInvite, Context.Guild.Id));
                success.Add(await AntiAds.TryEnableGuild(BlockType.YoutubeLink, Context.Guild.Id));
                success.Add(await AntiAds.TryEnableGuild(BlockType.TwitchStream, Context.Guild.Id));
                success.Add(await AntiAds.TryEnableGuild(BlockType.TwitchVideo, Context.Guild.Id));
                success.Add(await AntiAds.TryEnableGuild(BlockType.TwitchClip, Context.Guild.Id));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (success.All(f => f))
            {
                await ReplyAsync(
                    $"Now blocking {blocktype}. Please ensure that the bot has the 'Manage Messages' permission in the required channels.");

                await _logChannelService.LogMessageAsync(_client, Context.Client, Emote.Parse("<:Action:333712615731888129>"),
                                                         $"{Context.User} enabled {blocktype} in {Context.Guild}").ConfigureAwait(false);
            }
            else
            {
                await ReplyAsync("Some settings were already enabled.");
            }
        }
예제 #2
0
        public async Task EnableAll()
        {
            var sb = new StringBuilder();

            foreach (BlockType type in Enum.GetValues(typeof(BlockType)))
            {
                sb.AppendLine(!_adsService.TryEnableGuild(Context.Guild, type)
                    ? $":exclamation: Failed to enable `{type}`. Already enabled!"
                    : $":white_check_mark: Enabled `{type}`.");
            }
            sb.AppendLine($"Please ensure that the bot has `MANAGE_MESSAGES` permission in the required channels");
            await ReplyAsync(sb.ToString());

            await _logChannelService.LogMessageAsync(_client, Context.Client, Emote.Parse("<:Action:333712615731888129>"),
                                                     $"{Context.User} enabled All Blocks in {Context.Guild}").ConfigureAwait(false);
        }
예제 #3
0
        private static Task ReadyLogger()
        {
            foreach (var shard in _client.Shards.OrderBy(socketClient => socketClient.ShardId))
            {
                async Task Handler()
                {
                    _logger.LogInformation(new EventId(100), $"Shard {shard.ShardId} Ready");
                    await _channellogger.LogMessageAsync(_client, shard, Emote.Parse("<:Science:330479610812956672>"),
                                                         $"Ready `G:{shard.Guilds.Count}, U:{shard.Guilds.Sum(g => g.MemberCount)}`");

                    shard.Ready -= Handler;
                }

                shard.Ready += Handler;
            }

            return(Task.CompletedTask);
        }
예제 #4
0
        public static Task StartHandlers(DiscordShardedClient client)
        {
            _client = client;

            foreach (var shard in _client.Shards.OrderBy(socketClient => socketClient.ShardId))
            {
                async Task Handler()
                {
                    Logger.Info($"Shard {shard.ShardId} Ready");
                    await _logger.LogMessageAsync(_client, shard, Emote.Parse("<:Science:330479610812956672>"),
                                                  $"Ready `G:{shard.Guilds.Count}, U:{shard.Guilds.Sum(g => g.Users.Count)}`");

                    shard.Ready -= Handler;
                }

                shard.Ready += Handler;
            }

            _client.Log += ClientLogger;
            return(Task.CompletedTask);
        }
예제 #5
0
        private async Task ExecutePenalty(ICommandContext context, Violator violator, BlockType blockType)
        {
            var penalties = (await _unit.Penalties.GetOrCreateAllAsync(context.Guild)).ToList();
            var stats     = await _unit.Statistics.GetOrCreateAsync(context.Guild);

            stats.Blocks++;

            foreach (var penalty in penalties.OrderBy(p => p.RequiredPoints))
            {
                if (violator.Points != penalty.RequiredPoints)
                {
                    continue;
                }
                var message = penalty.Message ?? GetDefaultMessage(penalty.PenaltyType);

                string logresponse;
                switch (penalty.PenaltyType)
                {
                case PenaltyType.Nothing:
                    await MessagePenalty.SendWithEmoteAsync(_factory, context, message, GetTrigger(blockType),
                                                            autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Nothing {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:NoAds:330796107540201472>"), logresponse);

                    break;

                case PenaltyType.Warn:
                    await MessagePenalty.SendWithEmoteAsync(_factory, context, message, GetTrigger(blockType),
                                                            Emote.Parse("<:Warn:330799457371160579>"), penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Warn {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Warn:330799457371160579>"), logresponse);

                    stats.Warns++;
                    break;

                case PenaltyType.Kick:
                    await KickPenalty.KickAsync(_factory, context, message, GetTrigger(blockType),
                                                autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Kick {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Kick:330793607919566852>"), logresponse);

                    stats.Kicks++;
                    break;

                case PenaltyType.Ban:
                    await BanPenalty.BanAsync(_factory, context, message, GetTrigger(blockType),
                                              autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.Id} (Ban {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    _logger.LogInformation(new EventId(200), logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Ban:330793436309487626>"), logresponse);

                    stats.Bans++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            if (violator.Points >= penalties.Max(p => p.RequiredPoints))
            {
                _unit.Violators.Remove(violator);
                _logger.LogInformation(new EventId(200), $"{context.User} reached the last penalty in {context.Guild}, dropping from Database.");
            }
        }
예제 #6
0
        private static async Task ExecutePenalty(ICommandContext context, Violator violator, BlockType blockType)
        {
            var penalties = await _mongo.GetCollection <Penalty>(_client).GetPenaltiesAsync(violator.GuildId);

            var collection = _mongo.GetCollection <Stats>(_client);
            var stats      = await collection.GetGuildStatsAsync(context.Guild);

            stats.Blocks++;

            foreach (var penalty in penalties.OrderBy(p => p.RequiredPoints))
            {
                if (violator.Points != penalty.RequiredPoints)
                {
                    continue;
                }
                var message = penalty.Message ?? GetDefaultMessage(penalty.PenaltyType);


                string logresponse;
                switch (penalty.PenaltyType)
                {
                case PenaltyType.Nothing:
                    await MessagePenalty.SendWithEmoteAsync(context, message, GetTrigger(blockType),
                                                            autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Nothing {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:NoAds:330796107540201472>"), logresponse);

                    break;

                case PenaltyType.Warn:
                    await MessagePenalty.SendWithEmoteAsync(context, message, GetTrigger(blockType),
                                                            Emote.Parse("<:Warn:330799457371160579>"), penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Warn {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}.";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Warn:330799457371160579>"), logresponse);

                    stats.Warns++;
                    break;

                case PenaltyType.Kick:
                    await KickPenalty.KickAsync(context, message, GetTrigger(blockType),
                                                autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Kick {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Kick:330793607919566852>"), logresponse);

                    stats.Kicks++;
                    break;

                case PenaltyType.Ban:
                    await BanPenalty.BanAsync(context, message, GetTrigger(blockType),
                                              autoDelete : penalty.AutoDelete);

                    logresponse =
                        $"{context.User} reached Penalty {penalty.PenaltyId} (Ban {penalty.RequiredPoints}p) in {context.Guild}/{context.Channel}";
                    Logger.Info(logresponse);
                    await _logChannelService.LogMessageAsync(_client, _client.GetShardFor(context.Guild),
                                                             Emote.Parse("<:Ban:330793436309487626>"), logresponse);

                    stats.Bans++;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            await stats.SaveAsync();

            if (violator.Points >= penalties.Max(p => p.RequiredPoints))
            {
                await violator.DeleteAsync();

                Logger.Info($"{context.User} reached the last penalty in {context.Guild}, dropping from Database.");
            }
        }