diff --git a/src/NadekoBot/Db/Models/Warning.cs b/src/NadekoBot/Db/Models/Warning.cs index 0935b08a2..ce188c30d 100644 --- a/src/NadekoBot/Db/Models/Warning.cs +++ b/src/NadekoBot/Db/Models/Warning.cs @@ -8,6 +8,6 @@ public bool Forgiven { get; set; } public string ForgivenBy { get; set; } public string Moderator { get; set; } - public int Weight { get; set; } + public long Weight { get; set; } } } diff --git a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs index 8f1f9ebbb..231bb5716 100644 --- a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs @@ -63,27 +63,29 @@ namespace NadekoBot.Modules.Administration.Services Weight = weight, }; - int warnings = 1; + long previousCount; List ps; using (var uow = _db.GetDbContext()) { ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)) .WarnPunishments; - warnings += uow - .Warnings - .ForId(guildId, userId) - .Where(w => !w.Forgiven && w.UserId == userId) - .Sum(x => x.Weight); + previousCount = uow.Warnings.ForId(guildId, userId) + .Where(w => !w.Forgiven && w.UserId == userId) + .Sum(x => x.Weight); uow.Warnings.Add(warn); - uow.SaveChanges(); + await uow.SaveChangesAsync(); } - var p = ps.FirstOrDefault(x => x.Count == warnings); + var totalCount = previousCount + weight; + var p = ps.Where(x => x.Count > previousCount && x.Count <= totalCount) + .OrderByDescending(x => x.Count) + .FirstOrDefault(); - if (p != null) + + if (p is not null) { var user = await guild.GetUserAsync(userId).ConfigureAwait(false); if (user is null)