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

@ -6,6 +6,7 @@ using System.Web;
using Catalogger.Backend.Cache.InMemoryCache;
using Catalogger.Backend.Extensions;
using Humanizer;
using Humanizer.Localisation;
using Remora.Commands.Attributes;
using Remora.Commands.Groups;
using Remora.Discord.API.Abstractions.Objects;
@ -60,8 +61,14 @@ public class MetaCommands(
true);
embed.AddField("Numbers",
$"{CataloggerMetrics.MessagesStored.Value:N0} messages from {guildCache.Size:N0} servers\nCached {channelCache.Size:N0} channels",
inline: false);
$"{CataloggerMetrics.MessagesStored.Value:N0} messages " +
$"from {guildCache.Size:N0} servers\nCached {channelCache.Size:N0} channels",
true);
embed.AddField("Uptime",
$"{(CataloggerMetrics.Startup - clock.GetCurrentInstant()).Prettify(TimeUnit.Second)}\n" +
$"since <t:{CataloggerMetrics.Startup.ToUnixTimeSeconds()}:F>",
true);
IEmbed[] embeds = [embed.Build().GetOrThrow()];
@ -80,9 +87,7 @@ public class MetaCommands(
resp.EnsureSuccessStatusCode();
var data = await resp.Content.ReadFromJsonAsync<PrometheusResponse>();
_logger.Debug("Raw json: {Data}", JsonSerializer.Serialize(data));
var rawNumber = (data?.data.result[0].value[1] as JsonElement?)?.GetString();
_logger.Debug("Raw data: {Raw}", rawNumber);
return double.TryParse(rawNumber, out var rate) ? rate : null;
}
catch (Exception e)

View file

@ -12,4 +12,5 @@ public static class DiscordUtils
public static readonly Color Purple = Color.FromArgb(155, 89, 182);
public static readonly Color Green = Color.FromArgb(46, 204, 113);
public static readonly Color Blue = Color.FromArgb(52, 152, 219);
public static readonly Color Orange = Color.FromArgb(230, 126, 34);
}

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());
}