mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Merge branch 'warnpatch' into 'v3'
Weighted warnings now properly apply punishments See merge request Kwoth/nadekobot!198
This commit is contained in:
@@ -8,6 +8,6 @@
|
|||||||
public bool Forgiven { get; set; }
|
public bool Forgiven { get; set; }
|
||||||
public string ForgivenBy { get; set; }
|
public string ForgivenBy { get; set; }
|
||||||
public string Moderator { get; set; }
|
public string Moderator { get; set; }
|
||||||
public int Weight { get; set; }
|
public long Weight { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -63,27 +63,29 @@ namespace NadekoBot.Modules.Administration.Services
|
|||||||
Weight = weight,
|
Weight = weight,
|
||||||
};
|
};
|
||||||
|
|
||||||
int warnings = 1;
|
long previousCount;
|
||||||
List<WarningPunishment> ps;
|
List<WarningPunishment> ps;
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments))
|
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments))
|
||||||
.WarnPunishments;
|
.WarnPunishments;
|
||||||
|
|
||||||
warnings += uow
|
previousCount = uow.Warnings.ForId(guildId, userId)
|
||||||
.Warnings
|
.Where(w => !w.Forgiven && w.UserId == userId)
|
||||||
.ForId(guildId, userId)
|
.Sum(x => x.Weight);
|
||||||
.Where(w => !w.Forgiven && w.UserId == userId)
|
|
||||||
.Sum(x => x.Weight);
|
|
||||||
|
|
||||||
uow.Warnings.Add(warn);
|
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);
|
var user = await guild.GetUserAsync(userId).ConfigureAwait(false);
|
||||||
if (user is null)
|
if (user is null)
|
||||||
|
Reference in New Issue
Block a user