move classes around, name caches more consistently, add more caches

This commit is contained in:
sam 2024-08-19 16:12:28 +02:00
parent e86b37ce2a
commit e17dcf90a1
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
30 changed files with 443 additions and 51 deletions

View file

@ -1,8 +1,10 @@
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text.Json;
using App.Metrics;
using Catalogger.Backend.Cache;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Database;
using Catalogger.Backend.Extensions;
using Humanizer;
@ -11,7 +13,11 @@ using Remora.Commands.Attributes;
using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.API.Objects;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Extensions;
using Remora.Discord.Commands.Feedback.Services;
using Remora.Discord.Commands.Services;
using Remora.Discord.Extensions.Embeds;
using Remora.Discord.Gateway;
using Remora.Results;
@ -26,8 +32,10 @@ public class MetaCommands(
IMetrics metrics,
DiscordGatewayClient client,
IFeedbackService feedbackService,
GuildCacheService guildCache,
ChannelCacheService channelCache,
ContextInjectionService contextInjection,
IInviteCache inviteCache,
GuildCache guildCache,
ChannelCache channelCache,
IDiscordRestChannelAPI channelApi) : CommandGroup
{
[Command("ping")]
@ -65,4 +73,17 @@ public class MetaCommands(
return (Result)await channelApi.EditMessageAsync(msg.ChannelID, msg.ID, content: "", embeds: embeds);
}
[Command("debug-invites")]
[Description("Show a representation of this server's invites")]
public async Task<IResult> DebugInvitesAsync()
{
if (contextInjection.Context is not IInteractionCommandContext ctx) throw new CataloggerError("No context");
if (!ctx.TryGetGuildID(out var guildId)) throw new CataloggerError("No guild ID in context");
var invites = await inviteCache.TryGetAsync(guildId);
var text = invites.Select(i => $"{i.Code} in {i.Channel?.ID.Value}");
return await feedbackService.SendContextualAsync(string.Join("\n", text));
}
}