done some todos
This commit is contained in:
parent
12bcae137a
commit
53179abfbb
4 changed files with 58 additions and 38 deletions
src/EllieBot/Modules
Administration
Gambling/Shop
Searches/StreamNotification
|
@ -316,7 +316,7 @@ public class MuteService : IEService, IReadyExecutor
|
|||
StartUn_Timer(guild.Id, userId, after, TimerType.Ban); // start the timer
|
||||
}
|
||||
|
||||
// todo unrole timers -> temprole
|
||||
// todo UN* unrole timers -> temprole
|
||||
|
||||
public void StartUn_Timer(
|
||||
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()
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
|
|
@ -274,7 +274,25 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -333,7 +351,7 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
}
|
||||
};
|
||||
|
||||
stats = _antiSpamGuilds.AddOrUpdate(guildId,
|
||||
_antiSpamGuilds.AddOrUpdate(guildId,
|
||||
stats,
|
||||
(_, old) =>
|
||||
{
|
||||
|
@ -371,16 +389,18 @@ public class ProtectionService : IReadyExecutor, IEService
|
|||
{
|
||||
ChannelId = channelId
|
||||
};
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
var spam = await uow.GetTable<AntiSpamSetting>()
|
||||
.Include(x => x.IgnoredChannels)
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.FirstOrDefaultAsyncEF();
|
||||
|
||||
if (spam is null)
|
||||
return null;
|
||||
|
||||
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))
|
||||
temp.AntiSpamSettings.IgnoredChannels.Add(obj); // add to local cache
|
||||
|
|
|
@ -15,9 +15,9 @@ public class ShopService : IShopService, IEService
|
|||
|
||||
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)
|
||||
.ToListAsyncLinqToDB();
|
||||
.ToListAsyncEF();
|
||||
|
||||
return items.ToIndexed();
|
||||
}
|
||||
|
@ -46,6 +46,8 @@ public class ShopService : IShopService, IEService
|
|||
if (string.IsNullOrWhiteSpace(newName))
|
||||
throw new ArgumentNullException(nameof(newName));
|
||||
|
||||
newName = newName?.TrimTo(100);
|
||||
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
var changed = await uow.GetTable<ShopEntry>()
|
||||
|
@ -71,13 +73,7 @@ public class ShopService : IShopService, IEService
|
|||
entries[index1].Index = index2;
|
||||
entries[index2].Index = index1;
|
||||
|
||||
// todo fix swap
|
||||
await uow.GetTable<ShopEntry>()
|
||||
.Where(x => x.GuildId == guildId)
|
||||
.UpdateAsync(x => new ShopEntry()
|
||||
{
|
||||
Index = x.Index == index1 ? index2 : x.Index == index2 ? index1 : x.Index,
|
||||
});
|
||||
await uow.SaveChangesAsync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -88,9 +84,16 @@ public class ShopService : IShopService, IEService
|
|||
ArgumentOutOfRangeException.ThrowIfNegative(toIndex);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,6 @@ public sealed class StreamNotificationService : IEService, IReadyExecutor
|
|||
private async Task InitStateAsync()
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
// todo check all guilds on shard for correct param order
|
||||
var notifyOffline = await uow.GetTable<GuildConfig>()
|
||||
.Where(gc => gc.NotifyStreamOffline)
|
||||
.Select(x => x.GuildId)
|
||||
|
@ -350,28 +349,26 @@ public sealed class StreamNotificationService : IEService, IReadyExecutor
|
|||
|
||||
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>()
|
||||
.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 key = followedStream.CreateKey();
|
||||
var streams = GetLocalGuildStreams(key, guild.Id);
|
||||
streams.Add(followedStream);
|
||||
PublishFollowStream(followedStream);
|
||||
}
|
||||
var key = followedStream.CreateKey();
|
||||
var streams = GetLocalGuildStreams(key, guild.Id);
|
||||
streams.Add(followedStream);
|
||||
PublishFollowStream(followedStream);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue