feat: watchlist repository, remove ef core from all bot code

This commit is contained in:
sam 2024-10-28 02:14:41 +01:00
parent da4dfae27c
commit f0511a560c
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
19 changed files with 155 additions and 97 deletions

View file

@ -16,8 +16,7 @@
using System.ComponentModel;
using Catalogger.Backend.Cache;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Database;
using Catalogger.Backend.Database.Queries;
using Catalogger.Backend.Database.Dapper.Repositories;
using Catalogger.Backend.Extensions;
using Catalogger.Backend.Services;
using Remora.Commands.Attributes;
@ -38,7 +37,7 @@ namespace Catalogger.Backend.Bot.Commands;
[DiscordDefaultMemberPermissions(DiscordPermission.ManageGuild)]
public class IgnoreChannelCommands(
ILogger logger,
DatabaseContext db,
GuildRepository guildRepository,
IMemberCache memberCache,
GuildCache guildCache,
ChannelCache channelCache,
@ -66,7 +65,7 @@ public class IgnoreChannelCommands(
)
{
var (_, guildId) = contextInjection.GetUserAndGuild();
var guildConfig = await db.GetGuildAsync(guildId);
var guildConfig = await guildRepository.GetAsync(guildId);
if (guildConfig.Channels.IgnoredChannels.Contains(channel.ID.Value))
return await feedbackService.ReplyAsync(
@ -75,8 +74,7 @@ public class IgnoreChannelCommands(
);
guildConfig.Channels.IgnoredChannels.Add(channel.ID.Value);
db.Update(guildConfig);
await db.SaveChangesAsync();
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig.Channels);
return await feedbackService.ReplyAsync(
$"Successfully added {(channel.Type == ChannelType.GuildCategory ? channel.Name : $"<#{channel.ID}>")} to the list of ignored channels."
@ -90,7 +88,7 @@ public class IgnoreChannelCommands(
)
{
var (_, guildId) = contextInjection.GetUserAndGuild();
var guildConfig = await db.GetGuildAsync(guildId);
var guildConfig = await guildRepository.GetAsync(guildId);
if (!guildConfig.Channels.IgnoredChannels.Contains(channel.ID.Value))
return await feedbackService.ReplyAsync(
@ -99,8 +97,7 @@ public class IgnoreChannelCommands(
);
guildConfig.Channels.IgnoredChannels.Remove(channel.ID.Value);
db.Update(guildConfig);
await db.SaveChangesAsync();
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig.Channels);
return await feedbackService.ReplyAsync(
$"Successfully removed {(channel.Type == ChannelType.GuildCategory ? channel.Name : $"<#{channel.ID}>")} from the list of ignored channels."
@ -116,7 +113,7 @@ public class IgnoreChannelCommands(
throw new CataloggerError("Guild not in cache");
var guildChannels = channelCache.GuildChannels(guildId).ToList();
var guildConfig = await db.GetGuildAsync(guildId);
var guildConfig = await guildRepository.GetAsync(guildId);
var member = await memberCache.TryGetAsync(guildId, userId);
if (member == null)