feat: member add logs, improve meta command

This commit is contained in:
sam 2024-08-21 17:31:39 +02:00
parent f0cb5a9d03
commit 8f39d85486
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
12 changed files with 73 additions and 15 deletions

View file

@ -1,9 +1,11 @@
using Catalogger.Backend.Cache;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Database;
using Catalogger.Backend.Database.Queries;
using Catalogger.Backend.Extensions;
using Catalogger.Backend.Services;
using Humanizer;
using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Abstractions.Rest;
using Remora.Discord.API.Objects;
@ -17,6 +19,7 @@ public class GuildMemberAddResponder(
ILogger logger,
DatabaseContext db,
IMemberCache memberCache,
UserCache userCache,
WebhookExecutorService webhookExecutor,
IDiscordRestGuildAPI guildApi,
PluralkitApiService pluralkitApi) : IResponder<IGuildMemberAdd>
@ -43,13 +46,14 @@ public class GuildMemberAddResponder(
if (guildRes.IsSuccess)
builder.Description += $"\n{guildRes.Entity.ApproximateMemberCount.Value.Ordinalize()} to join";
builder.Description += $"\ncreated <t:{user.ID.Timestamp.ToUnixTimeSeconds()}>";
builder.Description +=
$"\ncreated {user.ID.Timestamp.Prettify()} ago\n<t:{user.ID.Timestamp.ToUnixTimeSeconds()}:F>";
var pkSystem = await pluralkitApi.GetPluralKitSystemAsync(user.ID.Value, ct);
if (pkSystem != null)
{
var createdAt = pkSystem.Created != null
? $"<t:{pkSystem.Created.Value.ToUnixTimeSeconds()}>"
? $"{pkSystem.Created.Value.Prettify()} ago (<t:{pkSystem.Created.Value.ToUnixTimeSeconds()}:F>)"
: "*(unknown)*";
builder.AddField("PluralKit system", $"""
**ID:** {pkSystem.Id} (`{pkSystem.Uuid}`)
@ -65,8 +69,28 @@ public class GuildMemberAddResponder(
if (user.ID.Timestamp > DateTimeOffset.Now - NewAccountThreshold)
{
embeds.Add(new EmbedBuilder().WithTitle("New account")
.WithDescription($"\u26a0\ufe0f Created <t:{user.ID.Timestamp.ToUnixTimeSeconds()}:R>").Build()
embeds.Add(new EmbedBuilder()
.WithTitle("New account")
.WithColour(DiscordUtils.Orange)
.WithDescription($"\u26a0\ufe0f Created {user.ID.Timestamp.Prettify()} ago")
.Build()
.GetOrThrow());
}
var watchlist = await db.GetWatchlistEntryAsync(member.GuildID, user.ID, ct);
if (watchlist != null)
{
var moderator = await userCache.GetUserAsync(DiscordSnowflake.New(watchlist.ModeratorId));
var mod = moderator != null ? $"{moderator.Tag()} (<@{moderator.ID}>)" : $"<@{watchlist.ModeratorId}>";
embeds.Add(new EmbedBuilder()
.WithTitle("⚠️ User on watchlist")
.WithColour(DiscordUtils.Red)
.WithDescription($"**{user.Tag()}** is on this server's watch list.\n\n{watchlist.Reason}")
.WithFooter($"ID: {user.ID} | Added")
.WithTimestamp(watchlist.AddedAt.ToDateTimeOffset())
.AddField("Moderator", mod).GetOrThrow()
.Build()
.GetOrThrow());
}