feat: role delete logging, used invite logging, also some random changes
This commit is contained in:
parent
4f54077c68
commit
c906a4d6b6
18 changed files with 386 additions and 76 deletions
|
|
@ -0,0 +1,71 @@
|
|||
using Catalogger.Backend.Cache.InMemoryCache;
|
||||
using Catalogger.Backend.Database;
|
||||
using Catalogger.Backend.Database.Queries;
|
||||
using Catalogger.Backend.Extensions;
|
||||
using Catalogger.Backend.Services;
|
||||
using Remora.Discord.API.Abstractions.Gateway.Events;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Gateway.Responders;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Catalogger.Backend.Bot.Responders.Roles;
|
||||
|
||||
public class RoleDeleteResponder(
|
||||
ILogger logger,
|
||||
DatabaseContext db,
|
||||
RoleCache roleCache,
|
||||
WebhookExecutorService webhookExecutor
|
||||
) : IResponder<IGuildRoleDelete>
|
||||
{
|
||||
private readonly ILogger _logger = logger.ForContext<RoleDeleteResponder>();
|
||||
|
||||
public async Task<Result> RespondAsync(IGuildRoleDelete evt, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!roleCache.TryGet(evt.RoleID, out var role))
|
||||
{
|
||||
_logger.Information(
|
||||
"Received role delete event for {RoleId} but it wasn't cached, ignoring",
|
||||
evt.RoleID
|
||||
);
|
||||
return Result.Success;
|
||||
}
|
||||
|
||||
var guildConfig = await db.GetGuildAsync(evt.GuildID, ct);
|
||||
|
||||
var embed = new EmbedBuilder()
|
||||
.WithTitle($"Role \"{role.Name}\" deleted")
|
||||
.WithColour(DiscordUtils.Red)
|
||||
.WithFooter($"ID: {role.ID}")
|
||||
.WithCurrentTimestamp()
|
||||
.WithDescription(
|
||||
$"""
|
||||
**Name:** {role.Name}
|
||||
**Colour:** {role.Colour.ToPrettyString()}
|
||||
**Mentionable:** {role.IsMentionable}
|
||||
**Shown separately:** {role.IsHoisted}
|
||||
**Position:** {role.Position}
|
||||
Created <t:{role.ID.Timestamp.ToUnixTimeSeconds()}> ({role.ID.Timestamp.Prettify()} ago)
|
||||
"""
|
||||
);
|
||||
|
||||
if (!role.Permissions.Value.IsZero)
|
||||
{
|
||||
embed.AddField("Permissions", role.Permissions.ToPrettyString());
|
||||
}
|
||||
|
||||
webhookExecutor.QueueLog(
|
||||
guildConfig,
|
||||
LogChannelType.GuildRoleDelete,
|
||||
embed.Build().GetOrThrow()
|
||||
);
|
||||
}
|
||||
finally
|
||||
{
|
||||
roleCache.Remove(evt.RoleID, evt.GuildID, out _);
|
||||
}
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue