Esempio n. 1
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.");
            }
        }
Esempio n. 2
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.");
            }
        }