done some todos

This commit is contained in:
Toastie 2025-01-29 23:35:43 +13:00
parent 12bcae137a
commit 53179abfbb
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
4 changed files with 58 additions and 38 deletions
src/EllieBot/Modules
Administration
Gambling/Shop
Searches/StreamNotification

View file

@ -316,7 +316,7 @@ public class MuteService : IEService, IReadyExecutor
StartUn_Timer(guild.Id, userId, after, TimerType.Ban); // start the timer StartUn_Timer(guild.Id, userId, after, TimerType.Ban); // start the timer
} }
// todo unrole timers -> temprole // todo UN* unrole timers -> temprole
public void StartUn_Timer( public void StartUn_Timer(
ulong guildId, ulong guildId,
@ -410,7 +410,7 @@ public class MuteService : IEService, IReadyExecutor
} }
// todo update to new way of tracking expiries // todo UN* update to new way of tracking expiries
public async Task OnReadyAsync() public async Task OnReadyAsync()
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();

View file

@ -274,7 +274,25 @@ public class ProtectionService : IReadyExecutor, IEService
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
// todo finish this 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
});
return stats; return stats;
} }
@ -333,7 +351,7 @@ public class ProtectionService : IReadyExecutor, IEService
} }
}; };
stats = _antiSpamGuilds.AddOrUpdate(guildId, _antiSpamGuilds.AddOrUpdate(guildId,
stats, stats,
(_, old) => (_, old) =>
{ {
@ -371,16 +389,18 @@ public class ProtectionService : IReadyExecutor, IEService
{ {
ChannelId = channelId ChannelId = channelId
}; };
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var spam = await uow.GetTable<AntiSpamSetting>() var spam = await uow.GetTable<AntiSpamSetting>()
.Include(x => x.IgnoredChannels) .Include(x => x.IgnoredChannels)
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.FirstOrDefaultAsyncEF(); .FirstOrDefaultAsyncEF();
if (spam is null) if (spam is null)
return null; return null;
var added = false; var added = false;
if (!spam.IgnoredChannels.Any(x => x.ChannelId == channelId)) if (spam.IgnoredChannels.All(x => x.ChannelId != channelId))
{ {
if (_antiSpamGuilds.TryGetValue(guildId, out var temp)) if (_antiSpamGuilds.TryGetValue(guildId, out var temp))
temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache

View file

@ -15,9 +15,9 @@ public class ShopService : IShopService, IEService
private async Task<IndexedCollection<ShopEntry>> GetEntriesInternal(DbContext uow, ulong guildId) private async Task<IndexedCollection<ShopEntry>> GetEntriesInternal(DbContext uow, ulong guildId)
{ {
var items = await uow.GetTable<ShopEntry>() var items = await uow.Set<ShopEntry>()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.ToListAsyncLinqToDB(); .ToListAsyncEF();
return items.ToIndexed(); return items.ToIndexed();
} }
@ -46,6 +46,8 @@ public class ShopService : IShopService, IEService
if (string.IsNullOrWhiteSpace(newName)) if (string.IsNullOrWhiteSpace(newName))
throw new ArgumentNullException(nameof(newName)); throw new ArgumentNullException(nameof(newName));
newName = newName?.TrimTo(100);
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var changed = await uow.GetTable<ShopEntry>() var changed = await uow.GetTable<ShopEntry>()
@ -71,13 +73,7 @@ public class ShopService : IShopService, IEService
entries[index1].Index = index2; entries[index1].Index = index2;
entries[index2].Index = index1; entries[index2].Index = index1;
// todo fix swap await uow.SaveChangesAsync();
await uow.GetTable<ShopEntry>()
.Where(x => x.GuildId == guildId)
.UpdateAsync(x => new ShopEntry()
{
Index = x.Index == index1 ? index2 : x.Index == index2 ? index1 : x.Index,
});
return true; return true;
} }
@ -88,9 +84,16 @@ public class ShopService : IShopService, IEService
ArgumentOutOfRangeException.ThrowIfNegative(toIndex); ArgumentOutOfRangeException.ThrowIfNegative(toIndex);
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = await GetEntriesInternal(uow, guildId);
// todo move if (fromIndex >= entries.Count || toIndex >= entries.Count || fromIndex == toIndex)
return false;
var entry = entries[fromIndex];
entries.RemoveAt(fromIndex);
entries.Insert(toIndex, entry);
await uow.SaveChangesAsync();
return true; return true;
} }

View file

@ -94,7 +94,6 @@ public sealed class StreamNotificationService : IEService, IReadyExecutor
private async Task InitStateAsync() private async Task InitStateAsync()
{ {
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
// todo check all guilds on shard for correct param order
var notifyOffline = await uow.GetTable<GuildConfig>() var notifyOffline = await uow.GetTable<GuildConfig>()
.Where(gc => gc.NotifyStreamOffline) .Where(gc => gc.NotifyStreamOffline)
.Select(x => x.GuildId) .Select(x => x.GuildId)
@ -350,28 +349,26 @@ public sealed class StreamNotificationService : IEService, IReadyExecutor
private async Task ClientOnJoinedGuild(SocketGuild guild) private async Task ClientOnJoinedGuild(SocketGuild guild)
{ {
await using (var uow = _db.GetDbContext()) await using var uow = _db.GetDbContext();
var fs = await uow.Set<FollowedStream>()
.Where(x => x.GuildId == guild.Id)
.ToListAsyncLinqToDB();
var notifyOffline = await uow.GetTable<GuildConfig>()
.Where(x => x.GuildId == guild.Id)
.Select(x => x.NotifyStreamOffline)
.FirstOrDefaultAsyncLinqToDB();
// todo hashset
if (notifyOffline)
_offlineNotificationServers.Add(guild.Id);
foreach (var followedStream in fs)
{ {
var fs = await uow.Set<FollowedStream>() var key = followedStream.CreateKey();
.Where(x => x.GuildId == guild.Id) var streams = GetLocalGuildStreams(key, guild.Id);
.ToListAsyncLinqToDB(); streams.Add(followedStream);
PublishFollowStream(followedStream);
var notifyOffline = await uow.GetTable<GuildConfig>()
.Where(x => x.GuildId == guild.Id)
.Select(x => x.NotifyStreamOffline)
.FirstOrDefaultAsyncLinqToDB();
// todo hashset
if (notifyOffline)
_offlineNotificationServers.Add(guild.Id);
foreach (var followedStream in fs)
{
var key = followedStream.CreateKey();
var streams = GetLocalGuildStreams(key, guild.Id);
streams.Add(followedStream);
PublishFollowStream(followedStream);
}
} }
} }