feat: watchlist repository, remove ef core from all bot code
This commit is contained in:
parent
da4dfae27c
commit
f0511a560c
19 changed files with 155 additions and 97 deletions
|
|
@ -15,8 +15,7 @@
|
|||
|
||||
using System.ComponentModel;
|
||||
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 Remora.Commands.Attributes;
|
||||
using Remora.Commands.Groups;
|
||||
|
|
@ -33,7 +32,7 @@ namespace Catalogger.Backend.Bot.Commands;
|
|||
[Group("key-roles")]
|
||||
[DiscordDefaultMemberPermissions(DiscordPermission.ManageGuild)]
|
||||
public class KeyRoleCommands(
|
||||
DatabaseContext db,
|
||||
GuildRepository guildRepository,
|
||||
ContextInjectionService contextInjection,
|
||||
IFeedbackService feedbackService,
|
||||
GuildCache guildCache,
|
||||
|
|
@ -48,7 +47,7 @@ public class KeyRoleCommands(
|
|||
if (!guildCache.TryGet(guildId, out var guild))
|
||||
throw new CataloggerError("Guild not in cache");
|
||||
var guildRoles = roleCache.GuildRoles(guildId).ToList();
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
|
||||
if (guildConfig.KeyRoles.Length == 0)
|
||||
return await feedbackService.ReplyAsync(
|
||||
|
|
@ -85,17 +84,14 @@ public class KeyRoleCommands(
|
|||
if (role == null)
|
||||
throw new CataloggerError("Role is not cached");
|
||||
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
if (guildConfig.KeyRoles.Any(id => role.ID == id))
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
if (guildConfig.KeyRoles.Any(id => role.ID.Value == id))
|
||||
return await feedbackService.ReplyAsync(
|
||||
$"{role.Name} is already a key role.",
|
||||
isEphemeral: true
|
||||
);
|
||||
|
||||
guildConfig.KeyRoles = guildConfig.KeyRoles.Append(role.ID.Value).ToArray();
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await guildRepository.AddKeyRoleAsync(guildId, role.ID);
|
||||
return await feedbackService.ReplyAsync($"Added {role.Name} to this server's key roles!");
|
||||
}
|
||||
|
||||
|
|
@ -110,17 +106,14 @@ public class KeyRoleCommands(
|
|||
if (role == null)
|
||||
throw new CataloggerError("Role is not cached");
|
||||
|
||||
var guildConfig = await db.GetGuildAsync(guildId);
|
||||
var guildConfig = await guildRepository.GetAsync(guildId);
|
||||
if (guildConfig.KeyRoles.All(id => role.ID != id))
|
||||
return await feedbackService.ReplyAsync(
|
||||
$"{role.Name} is already not a key role.",
|
||||
isEphemeral: true
|
||||
);
|
||||
|
||||
guildConfig.KeyRoles = guildConfig.KeyRoles.Except([role.ID.Value]).ToArray();
|
||||
db.Update(guildConfig);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await guildRepository.RemoveKeyRoleAsync(guildId, role.ID);
|
||||
return await feedbackService.ReplyAsync(
|
||||
$"Removed {role.Name} from this server's key roles!"
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue