コード例 #1
0
        public async Task <AntiRaidStats> StartAntiRaidAsync(ulong guildId, int userThreshold, int seconds, PunishmentAction action)
        {
            var g = _client.GetGuild(guildId);
            await _mute.GetMuteRole(g).ConfigureAwait(false);

            var stats = new AntiRaidStats()
            {
                AntiRaidSettings = new AntiRaidSetting()
                {
                    Action        = action,
                    Seconds       = seconds,
                    UserThreshold = userThreshold,
                }
            };

            _antiRaidGuilds.AddOrUpdate(guildId, stats, (key, old) => stats);

            using (var uow = _db.UnitOfWork)
            {
                var gc = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.AntiRaidSetting));

                gc.AntiRaidSetting = stats.AntiRaidSettings;
                await uow.CompleteAsync().ConfigureAwait(false);
            }

            return(stats);
        }
コード例 #2
0
ファイル: ProtectionService.cs プロジェクト: Nielk1/NadekoBot
        public async Task <AntiRaidStats> StartAntiRaidAsync(ulong guildId, int userThreshold, int seconds,
                                                             PunishmentAction action, int minutesDuration)
        {
            var g = _client.GetGuild(guildId);
            await _mute.GetMuteRole(g).ConfigureAwait(false);

            if (action == PunishmentAction.AddRole)
            {
                return(null);
            }

            if (!IsDurationAllowed(action))
            {
                minutesDuration = 0;
            }

            var stats = new AntiRaidStats()
            {
                AntiRaidSettings = new AntiRaidSetting()
                {
                    Action         = action,
                    Seconds        = seconds,
                    UserThreshold  = userThreshold,
                    PunishDuration = minutesDuration
                }
            };

            _antiRaidGuilds.AddOrUpdate(guildId, stats, (key, old) => stats);

            using (var uow = _db.GetDbContext())
            {
                var gc = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.AntiRaidSetting));

                gc.AntiRaidSetting = stats.AntiRaidSettings;
                await uow.SaveChangesAsync();
            }

            return(stats);
        }