fix: clean up some responders and commands

This commit is contained in:
sam 2024-09-02 15:06:10 +02:00
parent 9e0e53a428
commit 6e45b0f5b5
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
4 changed files with 15 additions and 10 deletions

View file

@ -39,9 +39,7 @@ public class ChannelCommands(
[DiscordDefaultMemberPermissions(DiscordPermission.ManageGuild)] [DiscordDefaultMemberPermissions(DiscordPermission.ManageGuild)]
public async Task<IResult> ConfigureChannelsAsync() public async Task<IResult> ConfigureChannelsAsync()
{ {
if (contextInjection.Context is not IInteractionCommandContext ctx) throw new CataloggerError("No context"); var (userId, guildId) = contextInjection.GetUserAndGuild();
if (!ctx.TryGetUserID(out var userId)) throw new CataloggerError("No user ID in context");
if (!ctx.TryGetGuildID(out var guildId)) throw new CataloggerError("No guild ID in context");
if (!guildCache.TryGet(guildId, out var guild)) throw new CataloggerError("Guild not in cache"); if (!guildCache.TryGet(guildId, out var guild)) throw new CataloggerError("Guild not in cache");
var guildChannels = channelCache.GuildChannels(guildId).ToList(); var guildChannels = channelCache.GuildChannels(guildId).ToList();
var guildConfig = await db.GetGuildAsync(guildId); var guildConfig = await db.GetGuildAsync(guildId);

View file

@ -66,9 +66,8 @@ public class MessageDeleteResponder(
// Check if the message is an edit trigger message. // Check if the message is an edit trigger message.
// If it is, the API will return a valid message for its ID, but the ID won't match either `Id` or `Original`. // If it is, the API will return a valid message for its ID, but the ID won't match either `Id` or `Original`.
// (We also won't have any system/member information stored for it) // (We also won't have any system/member information stored for it)
if (msg is { System: null, Member: null } && MaybePkProxyTrigger(ev.ID) && false) if (msg is { System: null, Member: null } && MaybePkProxyTrigger(ev.ID))
{ {
// TODO: remove the "false" if/when the API is updated to actually return this :neofox_woozy:
var pkMsg = await pluralkitApi.GetPluralKitMessageAsync(ev.ID.Value, ct); var pkMsg = await pluralkitApi.GetPluralKitMessageAsync(ev.ID.Value, ct);
if (pkMsg != null && pkMsg.Id != ev.ID.Value && pkMsg.Original != ev.ID.Value) if (pkMsg != null && pkMsg.Id != ev.ID.Value && pkMsg.Original != ev.ID.Value)
{ {

View file

@ -6,7 +6,7 @@ using Remora.Results;
namespace Catalogger.Backend.Bot.Responders; namespace Catalogger.Backend.Bot.Responders;
public class ReadyResponder(ILogger logger, WebhookExecutorService webhookExecutorService, Config config) public class ReadyResponder(ILogger logger, WebhookExecutorService webhookExecutorService)
: IResponder<IReady> : IResponder<IReady>
{ {
private readonly ILogger _logger = logger.ForContext<ReadyResponder>(); private readonly ILogger _logger = logger.ForContext<ReadyResponder>();
@ -17,10 +17,6 @@ public class ReadyResponder(ILogger logger, WebhookExecutorService webhookExecut
_logger.Information("Ready as {User} on shard {ShardId} / {ShardCount}", gatewayEvent.User.Tag(), shardId.Item1, _logger.Information("Ready as {User} on shard {ShardId} / {ShardCount}", gatewayEvent.User.Tag(), shardId.Item1,
shardId.Item2); shardId.Item2);
if (shardId.Item1 == 0) webhookExecutorService.SetSelfUser(gatewayEvent.User); if (shardId.Item1 == 0) webhookExecutorService.SetSelfUser(gatewayEvent.User);
// Sanity check
var appId = gatewayEvent.Application.ID.ToUlong();
_logger.Debug("Application ID is {ApplicationId}, is same as config? {SameAsConfig}", appId,
appId == config.Discord.ApplicationId);
return Task.FromResult(Result.Success); return Task.FromResult(Result.Success);
} }

View file

@ -3,6 +3,9 @@ using OneOf;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Rest; using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.API.Objects; using Remora.Discord.API.Objects;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Extensions;
using Remora.Discord.Commands.Services;
using Remora.Rest.Core; using Remora.Rest.Core;
using Remora.Results; using Remora.Results;
@ -70,5 +73,14 @@ public static class DiscordExtensions
public static string ToPrettyString(this IDiscordPermissionSet permissionSet) => public static string ToPrettyString(this IDiscordPermissionSet permissionSet) =>
string.Join(", ", permissionSet.GetPermissions().Select(p => p.Humanize(LetterCasing.Title))); string.Join(", ", permissionSet.GetPermissions().Select(p => p.Humanize(LetterCasing.Title)));
public static (Snowflake, Snowflake) GetUserAndGuild(this ContextInjectionService contextInjectionService)
{
if (contextInjectionService.Context is not IInteractionCommandContext ctx)
throw new CataloggerError("No context");
if (!ctx.TryGetUserID(out var userId)) throw new CataloggerError("No user ID in context");
if (!ctx.TryGetGuildID(out var guildId)) throw new CataloggerError("No guild ID in context");
return (userId, guildId);
}
public class DiscordRestException(string message) : Exception(message); public class DiscordRestException(string message) : Exception(message);
} }