feat: kick logs
This commit is contained in:
parent
6cb515c67d
commit
f524afb05b
7 changed files with 118 additions and 83 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Drawing;
|
||||
using Catalogger.Backend.Cache.InMemoryCache;
|
||||
using Humanizer;
|
||||
using OneOf;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||
|
|
@ -8,6 +9,7 @@ using Remora.Discord.API.Objects;
|
|||
using Remora.Discord.Commands.Contexts;
|
||||
using Remora.Discord.Commands.Extensions;
|
||||
using Remora.Discord.Commands.Services;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
|
||||
|
|
@ -117,26 +119,6 @@ public static class DiscordExtensions
|
|||
public static async Task<T> GetOrThrow<T>(this Task<Result<T>> result) =>
|
||||
(await result).GetOrThrow();
|
||||
|
||||
public static async Task<Result> UpdateMessageAsync(
|
||||
this IDiscordRestInteractionAPI interactionApi,
|
||||
IInteraction interaction,
|
||||
InteractionMessageCallbackData data
|
||||
) =>
|
||||
await interactionApi.CreateInteractionResponseAsync(
|
||||
interaction.ID,
|
||||
interaction.Token,
|
||||
new InteractionResponse(
|
||||
InteractionCallbackType.UpdateMessage,
|
||||
new Optional<
|
||||
OneOf<
|
||||
IInteractionMessageCallbackData,
|
||||
IInteractionAutocompleteCallbackData,
|
||||
IInteractionModalCallbackData
|
||||
>
|
||||
>(data)
|
||||
)
|
||||
);
|
||||
|
||||
public static string ToPrettyString(this IDiscordPermissionSet permissionSet) =>
|
||||
string.Join(
|
||||
", ",
|
||||
|
|
@ -172,5 +154,16 @@ public static class DiscordExtensions
|
|||
return filterByIds != null ? sorted.Where(r => filterByIds.Contains(r.ID)) : sorted;
|
||||
}
|
||||
|
||||
public static async Task<string> TryFormatModeratorAsync(
|
||||
this UserCache userCache,
|
||||
AuditLogCache.ActionData actionData
|
||||
)
|
||||
{
|
||||
var moderator = await userCache.GetUserAsync(actionData.ModeratorId);
|
||||
return moderator != null
|
||||
? $"{moderator.Tag()} <@{moderator.ID}>"
|
||||
: $"*(unknown user {actionData.ModeratorId}) <@{actionData.ModeratorId}>*";
|
||||
}
|
||||
|
||||
public class DiscordRestException(string message) : Exception(message);
|
||||
}
|
||||
|
|
|
|||
31
Catalogger.Backend/Extensions/DiscordRestExtensions.cs
Normal file
31
Catalogger.Backend/Extensions/DiscordRestExtensions.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using OneOf;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Abstractions.Rest;
|
||||
using Remora.Discord.API.Objects;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Catalogger.Backend.Extensions;
|
||||
|
||||
public static class DiscordRestExtensions
|
||||
{
|
||||
public static async Task<Result> UpdateMessageAsync(
|
||||
this IDiscordRestInteractionAPI interactionApi,
|
||||
IInteraction interaction,
|
||||
InteractionMessageCallbackData data
|
||||
) =>
|
||||
await interactionApi.CreateInteractionResponseAsync(
|
||||
interaction.ID,
|
||||
interaction.Token,
|
||||
new InteractionResponse(
|
||||
InteractionCallbackType.UpdateMessage,
|
||||
new Optional<
|
||||
OneOf<
|
||||
IInteractionMessageCallbackData,
|
||||
IInteractionAutocompleteCallbackData,
|
||||
IInteractionModalCallbackData
|
||||
>
|
||||
>(data)
|
||||
)
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue