Compare commits

...

3 commits

3 changed files with 55 additions and 65 deletions
src/EllieBot
Db/Models/anti
Modules
Administration/Protection
Xp

View file

@ -2,6 +2,8 @@
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
using LinqToDB.Mapping;
using DataType = LinqToDB.DataType;
namespace EllieBot.Db.Models; namespace EllieBot.Db.Models;

View file

@ -27,7 +27,6 @@ public class ProtectionService : IReadyExecutor, IEService
private readonly UserPunishService _punishService; private readonly UserPunishService _punishService;
private readonly INotifySubscriber _notifySub; private readonly INotifySubscriber _notifySub;
private readonly ShardData _shardData; private readonly ShardData _shardData;
private readonly Channel<PunishQueueItem> _punishUserQueue = private readonly Channel<PunishQueueItem> _punishUserQueue =
Channel.CreateUnbounded<PunishQueueItem>(new() Channel.CreateUnbounded<PunishQueueItem>(new()
{ {
@ -276,25 +275,23 @@ public class ProtectionService : IReadyExecutor, IEService
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow.GetTable<AntiRaidSetting>() await uow.GetTable<AntiRaidSetting>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = guildId, GuildId = guildId,
Action = action, Action = action,
Seconds = seconds, Seconds = seconds,
UserThreshold = userThreshold, UserThreshold = userThreshold,
PunishDuration = minutesDuration PunishDuration = minutesDuration
}, }, _ => new()
_ => new() {
{ Action = action,
Action = action, Seconds = seconds,
Seconds = seconds, UserThreshold = userThreshold,
UserThreshold = userThreshold, PunishDuration = minutesDuration
PunishDuration = minutesDuration }, () => new()
}, {
() => new() GuildId = guildId
{ });
GuildId = guildId
});
return stats; return stats;
@ -365,25 +362,23 @@ public class ProtectionService : IReadyExecutor, IEService
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow.GetTable<AntiSpamSetting>() await uow.GetTable<AntiSpamSetting>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = guildId, GuildId = guildId,
Action = stats.AntiSpamSettings.Action, Action = stats.AntiSpamSettings.Action,
MessageThreshold = stats.AntiSpamSettings.MessageThreshold, MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MuteTime = stats.AntiSpamSettings.MuteTime, MuteTime = stats.AntiSpamSettings.MuteTime,
RoleId = stats.AntiSpamSettings.RoleId RoleId = stats.AntiSpamSettings.RoleId
}, }, (old) => new()
(old) => new() {
{ GuildId = guildId,
GuildId = guildId, Action = stats.AntiSpamSettings.Action,
Action = stats.AntiSpamSettings.Action, MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
MessageThreshold = stats.AntiSpamSettings.MessageThreshold, MuteTime = stats.AntiSpamSettings.MuteTime,
MuteTime = stats.AntiSpamSettings.MuteTime, RoleId = stats.AntiSpamSettings.RoleId
RoleId = stats.AntiSpamSettings.RoleId }, () => new()
}, {
() => new() GuildId = guildId
{ });
GuildId = guildId
});
return stats; return stats;
} }
@ -464,24 +459,22 @@ public class ProtectionService : IReadyExecutor, IEService
await uow.GetTable<AntiAltSetting>() await uow.GetTable<AntiAltSetting>()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
GuildId = guildId, GuildId = guildId,
Action = action, Action = action,
ActionDurationMinutes = actionDurationMinutes, ActionDurationMinutes = actionDurationMinutes,
MinAge = TimeSpan.FromMinutes(minAgeMinutes), MinAge = TimeSpan.FromMinutes(minAgeMinutes),
RoleId = roleId RoleId = roleId
}, }, _ => new()
_ => new() {
{ Action = action,
Action = action, ActionDurationMinutes = actionDurationMinutes,
ActionDurationMinutes = actionDurationMinutes, MinAge = TimeSpan.FromMinutes(minAgeMinutes),
MinAge = TimeSpan.FromMinutes(minAgeMinutes), RoleId = roleId
RoleId = roleId }, () => new()
}, {
() => new() GuildId = guildId
{ });
GuildId = guildId
});
_antiAltGuilds[guildId] = new(new() _antiAltGuilds[guildId] = new(new()
{ {
@ -509,9 +502,9 @@ public class ProtectionService : IReadyExecutor, IEService
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var gids = _client.GetGuildIds();
var configs = await uow.Set<AntiAltSetting>() var configs = await uow.Set<AntiAltSetting>()
.AsNoTracking() .Where(x => gids.Contains(x.GuildId))
.Where(x => x.GuildId / 4194304 % (ulong)_shardData.TotalShards == (ulong)_shardData.ShardId)
.ToListAsyncEF(); .ToListAsyncEF();
foreach (var config in configs) foreach (var config in configs)
@ -532,7 +525,7 @@ public class ProtectionService : IReadyExecutor, IEService
var spamConfigs = await uow.GetTable<AntiSpamSetting>() var spamConfigs = await uow.GetTable<AntiSpamSetting>()
.AsNoTracking() .AsNoTracking()
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId)) .Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
.ToListAsyncEF(); .ToListAsyncLinqToDB();
foreach (var config in spamConfigs) foreach (var config in spamConfigs)
{ {

View file

@ -227,11 +227,6 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
var oldStats = new LevelStats(u.Xp - data.Xp); var oldStats = new LevelStats(u.Xp - data.Xp);
var newStats = new LevelStats(u.Xp); var newStats = new LevelStats(u.Xp);
Log.Information("User {User} xp updated from {OldLevel} to {NewLevel}",
u.UserId,
oldStats.TotalXp,
newStats.TotalXp);
if (oldStats.Level < newStats.Level) if (oldStats.Level < newStats.Level)
{ {
await _levelUpQueue.EnqueueAsync(NotifyUser(u.GuildId, await _levelUpQueue.EnqueueAsync(NotifyUser(u.GuildId,