fix nullref in chatterbot and mapping issue in protectionservice
This commit is contained in:
parent
8fa6b0c999
commit
ba1f5afa01
2 changed files with 82 additions and 74 deletions
src/EllieBot/Modules
|
@ -27,6 +27,7 @@ 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()
|
||||||
{
|
{
|
||||||
|
@ -282,13 +283,15 @@ public class ProtectionService : IReadyExecutor, IEService
|
||||||
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
|
||||||
});
|
});
|
||||||
|
@ -368,14 +371,16 @@ public class ProtectionService : IReadyExecutor, IEService
|
||||||
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
|
||||||
});
|
});
|
||||||
|
@ -465,13 +470,15 @@ public class ProtectionService : IReadyExecutor, IEService
|
||||||
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
|
||||||
});
|
});
|
||||||
|
@ -502,9 +509,9 @@ public class ProtectionService : IReadyExecutor, IEService
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
var configs = await uow.GetTable<AntiAltSetting>()
|
var configs = await uow.Set<AntiAltSetting>()
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
.Where(x => x.GuildId / 4194304 % (ulong)_shardData.TotalShards == (ulong)_shardData.ShardId)
|
||||||
.ToListAsyncEF();
|
.ToListAsyncEF();
|
||||||
|
|
||||||
foreach (var config in configs)
|
foreach (var config in configs)
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace EllieBot.Modules.Games.Services;
|
||||||
|
|
||||||
public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
||||||
{
|
{
|
||||||
private ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> _chatterBotGuilds;
|
private ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> _chatterBotGuilds = [];
|
||||||
|
|
||||||
public int Priority
|
public int Priority
|
||||||
=> 1;
|
=> 1;
|
||||||
|
@ -235,12 +235,13 @@ public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
||||||
public async Task OnReadyAsync()
|
public async Task OnReadyAsync()
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
_chatterBotGuilds = uow.GuildConfigs
|
_chatterBotGuilds = await uow.GuildConfigs
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
.Where(gc => gc.CleverbotEnabled)
|
.Where(gc => gc.CleverbotEnabled)
|
||||||
.AsEnumerable()
|
.ToListAsyncLinqToDB()
|
||||||
|
.Fmap(x => x
|
||||||
.ToDictionary(gc => gc.GuildId,
|
.ToDictionary(gc => gc.GuildId,
|
||||||
_ => new Lazy<IChatterBotSession>(() => CreateSession(), true))
|
_ => new Lazy<IChatterBotSession>(() => CreateSession(), true))
|
||||||
.ToConcurrent();
|
.ToConcurrent());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue