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

@ -14,8 +14,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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.Discord.API.Abstractions.Objects;
@ -24,7 +23,6 @@ using Remora.Discord.API.Objects;
using Remora.Discord.Commands.Attributes;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Extensions;
using Remora.Discord.Commands.Feedback.Messages;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Commands.Services;
using Remora.Discord.Interactivity;
@ -36,7 +34,7 @@ namespace Catalogger.Backend.Bot.Commands;
public class ChannelCommandsComponents(
ILogger logger,
DatabaseContext db,
GuildRepository guildRepository,
GuildCache guildCache,
ChannelCache channelCache,
ContextInjectionService contextInjection,
@ -62,7 +60,7 @@ public class ChannelCommandsComponents(
if (!guildCache.TryGet(guildId, out var guild))
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 result = await dataService.LeaseDataAsync(msg.ID);
await using var lease = result.GetOrThrow();
@ -166,8 +164,7 @@ public class ChannelCommandsComponents(
throw new ArgumentOutOfRangeException();
}
db.Update(guildConfig);
await db.SaveChangesAsync();
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig.Channels);
goto case "return";
case "return":
var (e, c) = ChannelCommands.BuildRootMenu(guildChannels, guild, guildConfig);
@ -260,7 +257,7 @@ public class ChannelCommandsComponents(
throw new CataloggerError("No guild ID in context");
if (!guildCache.TryGet(guildId, out var guild))
throw new CataloggerError("Guild not in cache");
var guildConfig = await db.GetGuildAsync(guildId);
var guildConfig = await guildRepository.GetAsync(guildId);
var channelId = channels[0].ID.ToUlong();
var result = await dataService.LeaseDataAsync(msg.ID);
@ -354,8 +351,7 @@ public class ChannelCommandsComponents(
throw new ArgumentOutOfRangeException();
}
db.Update(guildConfig);
await db.SaveChangesAsync();
await guildRepository.UpdateChannelConfigAsync(guildId, guildConfig.Channels);
List<IEmbed> embeds =
[