Compare commits
2 commits
1cd02222b9
...
ba1f5afa01
Author | SHA1 | Date | |
---|---|---|---|
ba1f5afa01 | |||
8fa6b0c999 |
3 changed files with 87 additions and 84 deletions
src/EllieBot/Modules
Administration/Protection
Gambling/PlantPick
Games/ChatterBot
|
@ -27,6 +27,7 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
private readonly UserPunishService _punishService;
|
||||
private readonly INotifySubscriber _notifySub;
|
||||
private readonly ShardData _shardData;
|
||||
|
||||
private readonly Channel<PunishQueueItem> _punishUserQueue =
|
||||
Channel.CreateUnbounded<PunishQueueItem>(new()
|
||||
{
|
||||
|
@ -275,23 +276,25 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
await using var uow = _db.GetDbContext();
|
||||
|
||||
await uow.GetTable<AntiRaidSetting>()
|
||||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = action,
|
||||
Seconds = seconds,
|
||||
UserThreshold = userThreshold,
|
||||
PunishDuration = minutesDuration
|
||||
}, _ => new()
|
||||
{
|
||||
Action = action,
|
||||
Seconds = seconds,
|
||||
UserThreshold = userThreshold,
|
||||
PunishDuration = minutesDuration
|
||||
}, () => new()
|
||||
{
|
||||
GuildId = guildId
|
||||
});
|
||||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = action,
|
||||
Seconds = seconds,
|
||||
UserThreshold = userThreshold,
|
||||
PunishDuration = minutesDuration
|
||||
},
|
||||
_ => new()
|
||||
{
|
||||
Action = action,
|
||||
Seconds = seconds,
|
||||
UserThreshold = userThreshold,
|
||||
PunishDuration = minutesDuration
|
||||
},
|
||||
() => new()
|
||||
{
|
||||
GuildId = guildId
|
||||
});
|
||||
|
||||
|
||||
return stats;
|
||||
|
@ -362,23 +365,25 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
await using var uow = _db.GetDbContext();
|
||||
await uow.GetTable<AntiSpamSetting>()
|
||||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = stats.AntiSpamSettings.Action,
|
||||
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
|
||||
MuteTime = stats.AntiSpamSettings.MuteTime,
|
||||
RoleId = stats.AntiSpamSettings.RoleId
|
||||
}, (old) => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = stats.AntiSpamSettings.Action,
|
||||
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
|
||||
MuteTime = stats.AntiSpamSettings.MuteTime,
|
||||
RoleId = stats.AntiSpamSettings.RoleId
|
||||
}, () => new()
|
||||
{
|
||||
GuildId = guildId
|
||||
});
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = stats.AntiSpamSettings.Action,
|
||||
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
|
||||
MuteTime = stats.AntiSpamSettings.MuteTime,
|
||||
RoleId = stats.AntiSpamSettings.RoleId
|
||||
},
|
||||
(old) => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = stats.AntiSpamSettings.Action,
|
||||
MessageThreshold = stats.AntiSpamSettings.MessageThreshold,
|
||||
MuteTime = stats.AntiSpamSettings.MuteTime,
|
||||
RoleId = stats.AntiSpamSettings.RoleId
|
||||
},
|
||||
() => new()
|
||||
{
|
||||
GuildId = guildId
|
||||
});
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
@ -459,22 +464,24 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
|
||||
await uow.GetTable<AntiAltSetting>()
|
||||
.InsertOrUpdateAsync(() => new()
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = action,
|
||||
ActionDurationMinutes = actionDurationMinutes,
|
||||
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
|
||||
RoleId = roleId
|
||||
}, _ => new()
|
||||
{
|
||||
Action = action,
|
||||
ActionDurationMinutes = actionDurationMinutes,
|
||||
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
|
||||
RoleId = roleId
|
||||
}, () => new()
|
||||
{
|
||||
GuildId = guildId
|
||||
});
|
||||
{
|
||||
GuildId = guildId,
|
||||
Action = action,
|
||||
ActionDurationMinutes = actionDurationMinutes,
|
||||
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
|
||||
RoleId = roleId
|
||||
},
|
||||
_ => new()
|
||||
{
|
||||
Action = action,
|
||||
ActionDurationMinutes = actionDurationMinutes,
|
||||
MinAge = TimeSpan.FromMinutes(minAgeMinutes),
|
||||
RoleId = roleId
|
||||
},
|
||||
() => new()
|
||||
{
|
||||
GuildId = guildId
|
||||
});
|
||||
|
||||
_antiAltGuilds[guildId] = new(new()
|
||||
{
|
||||
|
@ -502,9 +509,10 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var configs = await uow.GetTable<AntiAltSetting>()
|
||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
||||
.ToListAsyncLinqToDB();
|
||||
var configs = await uow.Set<AntiAltSetting>()
|
||||
.AsNoTracking()
|
||||
.Where(x => x.GuildId / 4194304 % (ulong)_shardData.TotalShards == (ulong)_shardData.ShardId)
|
||||
.ToListAsyncEF();
|
||||
|
||||
foreach (var config in configs)
|
||||
_antiAltGuilds[config.GuildId] = new(config);
|
||||
|
@ -522,8 +530,9 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
}
|
||||
|
||||
var spamConfigs = await uow.GetTable<AntiSpamSetting>()
|
||||
.AsNoTracking()
|
||||
.Where(x => Queries.GuildOnShard(x.GuildId, _shardData.TotalShards, _shardData.ShardId))
|
||||
.ToListAsyncLinqToDB();
|
||||
.ToListAsyncEF();
|
||||
|
||||
foreach (var config in spamConfigs)
|
||||
{
|
||||
|
|
|
@ -25,13 +25,11 @@ public class PlantPickService : IEService, IExecNoCommand, IReadyExecutor
|
|||
private readonly FontProvider _fonts;
|
||||
private readonly ICurrencyService _cs;
|
||||
private readonly CommandHandler _cmdHandler;
|
||||
private readonly EllieRandom _rng;
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly GamblingConfigService _gss;
|
||||
private readonly GamblingService _gs;
|
||||
|
||||
private ConcurrentHashSet<ulong> _generationChannels;
|
||||
private readonly SemaphoreSlim _pickLock = new(1, 1);
|
||||
private ConcurrentHashSet<ulong> _generationChannels = [];
|
||||
|
||||
public PlantPickService(
|
||||
DbService db,
|
||||
|
@ -50,13 +48,9 @@ public class PlantPickService : IEService, IExecNoCommand, IReadyExecutor
|
|||
_fonts = fonts;
|
||||
_cs = cs;
|
||||
_cmdHandler = cmdHandler;
|
||||
_rng = new();
|
||||
_client = client;
|
||||
_gss = gss;
|
||||
_gs = gs;
|
||||
|
||||
using var uow = db.GetDbContext();
|
||||
var guildIds = client.Guilds.Select(x => x.Id).ToList();
|
||||
}
|
||||
|
||||
public Task ExecOnNoCommandAsync(IGuild guild, IUserMessage msg)
|
||||
|
@ -416,7 +410,6 @@ public class PlantPickService : IEService, IExecNoCommand, IReadyExecutor
|
|||
|
||||
public async Task OnReadyAsync()
|
||||
{
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
_generationChannels = (await uow.GetTable<GCChannelId>()
|
||||
.Select(x => x.ChannelId)
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace EllieBot.Modules.Games.Services;
|
|||
|
||||
public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
||||
{
|
||||
private ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> _chatterBotGuilds;
|
||||
private ConcurrentDictionary<ulong, Lazy<IChatterBotSession>> _chatterBotGuilds = [];
|
||||
|
||||
public int Priority
|
||||
=> 1;
|
||||
|
@ -165,8 +165,8 @@ public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
|||
(inTokens) + (result.TokensOut / 2 * 3));
|
||||
|
||||
await _sender.Response(channel)
|
||||
.Confirm(result.Text)
|
||||
.SendAsync();
|
||||
.Confirm(result.Text)
|
||||
.SendAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -204,12 +204,12 @@ public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
|||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
await uow.Set<GuildConfig>()
|
||||
.ToLinqToDBTable()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync((gc) => new GuildConfig()
|
||||
{
|
||||
CleverbotEnabled = false
|
||||
});
|
||||
.ToLinqToDBTable()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync((gc) => new GuildConfig()
|
||||
{
|
||||
CleverbotEnabled = false
|
||||
});
|
||||
await uow.SaveChangesAsync();
|
||||
return false;
|
||||
}
|
||||
|
@ -219,12 +219,12 @@ public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
|||
await using (var uow = _db.GetDbContext())
|
||||
{
|
||||
await uow.Set<GuildConfig>()
|
||||
.ToLinqToDBTable()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync((gc) => new GuildConfig()
|
||||
{
|
||||
CleverbotEnabled = true
|
||||
});
|
||||
.ToLinqToDBTable()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync((gc) => new GuildConfig()
|
||||
{
|
||||
CleverbotEnabled = true
|
||||
});
|
||||
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
@ -235,12 +235,13 @@ public class ChatterBotService : IExecOnMessage, IReadyExecutor
|
|||
public async Task OnReadyAsync()
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
_chatterBotGuilds = uow.GuildConfigs
|
||||
.AsNoTracking()
|
||||
.Where(gc => gc.CleverbotEnabled)
|
||||
.AsEnumerable()
|
||||
.ToDictionary(gc => gc.GuildId,
|
||||
_ => new Lazy<IChatterBotSession>(() => CreateSession(), true))
|
||||
.ToConcurrent();
|
||||
_chatterBotGuilds = await uow.GuildConfigs
|
||||
.AsNoTracking()
|
||||
.Where(gc => gc.CleverbotEnabled)
|
||||
.ToListAsyncLinqToDB()
|
||||
.Fmap(x => x
|
||||
.ToDictionary(gc => gc.GuildId,
|
||||
_ => new Lazy<IChatterBotSession>(() => CreateSession(), true))
|
||||
.ToConcurrent());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue