feat(bot): use discord timestamps on cv2 cards

This commit is contained in:
asleepyskye 2025-11-07 09:20:23 -05:00
parent 0983179240
commit 83f866384a
2 changed files with 8 additions and 5 deletions

View file

@ -192,7 +192,7 @@ public class EmbedService
new MessageComponent() new MessageComponent()
{ {
Type = ComponentType.Text, Type = ComponentType.Text,
Content = $"-# System ID: `{system.DisplayHid(cctx.Config)}`\n-# Created: {system.Created.FormatZoned(cctx.Zone)}", Content = $"-# System ID: `{system.DisplayHid(cctx.Config)}`\n-# Created: {DiscordUtils.InstantToTimestampString(system.Created)}",
}, },
], ],
Accessory = new MessageComponent() Accessory = new MessageComponent()
@ -469,7 +469,7 @@ public class EmbedService
new MessageComponent() new MessageComponent()
{ {
Type = ComponentType.Text, Type = ComponentType.Text,
Content = $"-# System ID: `{system.DisplayHid(ccfg)}` \u2219 Member ID: `{member.DisplayHid(ccfg)}`{(member.MetadataPrivacy.CanAccess(ctx) ? $"\n-# Created: {member.Created.FormatZoned(zone)}" : "")}", Content = $"-# System ID: `{system.DisplayHid(ccfg)}` \u2219 Member ID: `{member.DisplayHid(ccfg)}`{(member.MetadataPrivacy.CanAccess(ctx) ? $"\n-# Created: {DiscordUtils.InstantToTimestampString(member.Created)}" : "")}",
}, },
], ],
Accessory = new MessageComponent() Accessory = new MessageComponent()
@ -659,7 +659,7 @@ public class EmbedService
new MessageComponent() new MessageComponent()
{ {
Type = ComponentType.Text, Type = ComponentType.Text,
Content = $"-# System ID: `{system.DisplayHid(ctx.Config)}` \u2219 Group ID: `{target.DisplayHid(ctx.Config)}`{(target.MetadataPrivacy.CanAccess(pctx) ? $"\n-# Created: {target.Created.FormatZoned(ctx.Zone)}" : "")}", Content = $"-# System ID: `{system.DisplayHid(ctx.Config)}` \u2219 Group ID: `{target.DisplayHid(ctx.Config)}`{(target.MetadataPrivacy.CanAccess(pctx) ? $"\n-# Created: {DiscordUtils.InstantToTimestampString(target.Created)}" : "")}",
}, },
], ],
Accessory = new MessageComponent() Accessory = new MessageComponent()
@ -903,7 +903,7 @@ public class EmbedService
MessageComponent footer = new MessageComponent() MessageComponent footer = new MessageComponent()
{ {
Type = ComponentType.Text, Type = ComponentType.Text,
Content = $"-# Original Message ID: {msg.Message.OriginalMid} · <t:{DiscordUtils.SnowflakeToTimestamp(msg.Message.Mid)}:f>" Content = $"-# Original Message ID: {msg.Message.OriginalMid} · {DiscordUtils.InstantToTimestampString(DiscordUtils.SnowflakeToInstant(msg.Message.Mid))}"
}; };
return [ return [
@ -1091,7 +1091,7 @@ public class EmbedService
MessageComponent footer = new MessageComponent() MessageComponent footer = new MessageComponent()
{ {
Type = ComponentType.Text, Type = ComponentType.Text,
Content = $"-# Original Message ID: {msg.OriginalMid} · <t:{DiscordUtils.SnowflakeToTimestamp(msg.OriginalMid)}:f>" Content = $"-# Original Message ID: {msg.OriginalMid} · {DiscordUtils.InstantToTimestampString(DiscordUtils.SnowflakeToInstant(msg.OriginalMid))}"
}; };
return [ return [

View file

@ -45,6 +45,9 @@ public static class DiscordUtils
public static ulong InstantToSnowflake(Instant time) => public static ulong InstantToSnowflake(Instant time) =>
(ulong)(time - Instant.FromUtc(2015, 1, 1, 0, 0, 0)).TotalMilliseconds << 22; (ulong)(time - Instant.FromUtc(2015, 1, 1, 0, 0, 0)).TotalMilliseconds << 22;
public static string InstantToTimestampString(Instant time) =>
$"<t:{time.ToUnixTimeSeconds()}:f>";
public static async Task CreateReactionsBulk(this DiscordApiClient rest, Message msg, string[] reactions) public static async Task CreateReactionsBulk(this DiscordApiClient rest, Message msg, string[] reactions)
{ {
foreach (var reaction in reactions) foreach (var reaction in reactions)