chore(backend): update dependencies

This commit is contained in:
sam 2025-03-14 20:11:00 +01:00
parent db3e6fa7b0
commit cb43ac1a50
Signed by: sam
GPG key ID: 5F3C3C1B3166639D
8 changed files with 21 additions and 64 deletions

View file

@ -3,14 +3,14 @@
"isRoot": true, "isRoot": true,
"tools": { "tools": {
"csharpier": { "csharpier": {
"version": "0.30.1", "version": "0.30.6",
"commands": [ "commands": [
"dotnet-csharpier" "dotnet-csharpier"
], ],
"rollForward": false "rollForward": false
}, },
"husky": { "husky": {
"version": "0.7.1", "version": "0.7.2",
"commands": [ "commands": [
"husky" "husky"
], ],

View file

@ -77,7 +77,7 @@ public class MessageCreateResponder(
return Result.Success; return Result.Success;
} }
await messageRepository.SaveMessageAsync(msg, ct); await messageRepository.SaveMessageAsync(msg, msg.GuildID, ct);
return Result.Success; return Result.Success;
} }
} }

View file

@ -20,7 +20,6 @@ using Catalogger.Backend.Services;
using Remora.Discord.API; using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Abstractions.Objects; using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Gateway.Events;
using Remora.Discord.API.Objects; using Remora.Discord.API.Objects;
using Remora.Discord.Extensions.Embeds; using Remora.Discord.Extensions.Embeds;
using Remora.Discord.Gateway.Responders; using Remora.Discord.Gateway.Responders;
@ -40,13 +39,9 @@ public class MessageUpdateResponder(
{ {
private readonly ILogger _logger = logger.ForContext<MessageUpdateResponder>(); private readonly ILogger _logger = logger.ForContext<MessageUpdateResponder>();
public async Task<Result> RespondAsync(IMessageUpdate evt, CancellationToken ct = default) public async Task<Result> RespondAsync(IMessageUpdate msg, CancellationToken ct = default)
{ {
using var _ = LogUtils.Enrich(evt); using var _ = LogUtils.Enrich(msg);
// Discord only *very* recently changed message update events to have all fields,
// so we convert the event to a MessageCreate to avoid having to unwrap every single field
var msg = ConvertToMessageCreate(evt);
if (!msg.GuildID.IsDefined()) if (!msg.GuildID.IsDefined())
{ {
@ -134,7 +129,7 @@ public class MessageUpdateResponder(
if (oldMessage is { System: not null, Member: not null }) if (oldMessage is { System: not null, Member: not null })
{ {
embedBuilder.WithTitle($"Message by {msg.Author.Username} edited"); embedBuilder.WithTitle($"Message by {msg.Author.Username} edited");
embedBuilder.AddField("\u200b", "**PluralKit information**", false); embedBuilder.AddField("\u200b", "**PluralKit information**");
embedBuilder.AddField("System ID", oldMessage.System, true); embedBuilder.AddField("System ID", oldMessage.System, true);
embedBuilder.AddField("Member ID", oldMessage.Member, true); embedBuilder.AddField("Member ID", oldMessage.Member, true);
} }
@ -174,7 +169,7 @@ public class MessageUpdateResponder(
) )
{ {
if ( if (
!await messageRepository.SaveMessageAsync(msg, ct) !await messageRepository.SaveMessageAsync(msg, msg.GuildID, ct)
&& msg.ApplicationID.Is(DiscordUtils.PkUserId) && msg.ApplicationID.Is(DiscordUtils.PkUserId)
) )
{ {
@ -196,44 +191,6 @@ public class MessageUpdateResponder(
} }
} }
private static MessageCreate ConvertToMessageCreate(IMessageUpdate evt) =>
new(
evt.GuildID,
evt.Member,
evt.Mentions.GetOrThrow(),
evt.ID.GetOrThrow(),
evt.ChannelID.GetOrThrow(),
evt.Author.GetOrThrow(),
evt.Content.GetOrThrow(),
evt.Timestamp.GetOrThrow(),
evt.EditedTimestamp.GetOrThrow(),
IsTTS: false,
evt.MentionsEveryone.GetOrThrow(),
evt.MentionedRoles.GetOrThrow(),
evt.MentionedChannels,
evt.Attachments.GetOrThrow(),
evt.Embeds.GetOrThrow(),
evt.Reactions,
evt.Nonce,
evt.IsPinned.GetOrThrow(),
evt.WebhookID,
evt.Type.GetOrThrow(),
evt.Activity,
evt.Application,
evt.ApplicationID,
evt.MessageReference,
evt.Flags,
evt.ReferencedMessage,
evt.Interaction,
evt.Thread,
evt.Components,
evt.StickerItems,
evt.Position,
evt.Resolved,
evt.InteractionMetadata,
evt.Poll
);
private static IEnumerable<string> ChunksUpTo(string str, int maxChunkSize) private static IEnumerable<string> ChunksUpTo(string str, int maxChunkSize)
{ {
for (var i = 0; i < str.Length; i += maxChunkSize) for (var i = 0; i < str.Length; i += maxChunkSize)

View file

@ -234,6 +234,7 @@ internal record RedisMember(
User.ToRemoraUser(), User.ToRemoraUser(),
Nickname, Nickname,
Avatar != null ? new ImageHash(Avatar) : null, Avatar != null ? new ImageHash(Avatar) : null,
Banner: null,
Roles.Select(DiscordSnowflake.New).ToList(), Roles.Select(DiscordSnowflake.New).ToList(),
JoinedAt, JoinedAt,
PremiumSince, PremiumSince,

View file

@ -21,18 +21,18 @@
<PackageReference Include="Humanizer.Core" Version="2.14.1"/> <PackageReference Include="Humanizer.Core" Version="2.14.1"/>
<PackageReference Include="LazyCache" Version="2.4.0"/> <PackageReference Include="LazyCache" Version="2.4.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" /> <PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3"/> <PackageReference Include="Newtonsoft.Json" Version="13.0.3"/>
<PackageReference Include="NodaTime" Version="3.2.0" /> <PackageReference Include="NodaTime" Version="3.2.0" />
<PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.2.0"/> <PackageReference Include="NodaTime.Serialization.SystemTextJson" Version="1.2.0"/>
<PackageReference Include="Npgsql" Version="9.0.0" /> <PackageReference Include="Npgsql" Version="9.0.0" />
<PackageReference Include="Npgsql.NodaTime" Version="9.0.0" /> <PackageReference Include="Npgsql.NodaTime" Version="9.0.0" />
<PackageReference Include="Polly.Core" Version="8.5.0" /> <PackageReference Include="Polly.Core" Version="8.5.2" />
<PackageReference Include="Polly.RateLimiting" Version="8.5.0" /> <PackageReference Include="Polly.RateLimiting" Version="8.5.0" />
<PackageReference Include="prometheus-net" Version="8.2.1"/> <PackageReference Include="prometheus-net" Version="8.2.1"/>
<PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1"/> <PackageReference Include="prometheus-net.AspNetCore" Version="8.2.1"/>
<PackageReference Include="Remora.Sdk" Version="3.1.2"/> <PackageReference Include="Remora.Sdk" Version="3.1.2"/>
<PackageReference Include="Remora.Discord" Version="2024.3.0-github11168366508"/> <PackageReference Include="Remora.Discord" Version="2025.1.0" />
<PackageReference Include="Serilog" Version="4.1.0" /> <PackageReference Include="Serilog" Version="4.1.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.3" /> <PackageReference Include="Serilog.AspNetCore" Version="8.0.3" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0"/> <PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0"/>

View file

@ -18,6 +18,7 @@ using Catalogger.Backend.Extensions;
using Dapper; using Dapper;
using Remora.Discord.API; using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Gateway.Events; using Remora.Discord.API.Abstractions.Gateway.Events;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Rest.Core; using Remora.Rest.Core;
namespace Catalogger.Backend.Database.Repositories; namespace Catalogger.Backend.Database.Repositories;
@ -63,7 +64,11 @@ public class MessageRepository(
/// <summary> /// <summary>
/// Adds a new message. If the message is already in the database, updates the existing message instead. /// Adds a new message. If the message is already in the database, updates the existing message instead.
/// </summary> /// </summary>
public async Task<bool> SaveMessageAsync(IMessageCreate msg, CancellationToken ct = default) public async Task<bool> SaveMessageAsync(
IMessage msg,
Optional<Snowflake> guildId,
CancellationToken ct = default
)
{ {
var content = await Task.Run( var content = await Task.Run(
() => () =>
@ -107,7 +112,9 @@ public class MessageRepository(
Id = msg.ID.Value, Id = msg.ID.Value,
UserId = msg.Author.ID.Value, UserId = msg.Author.ID.Value,
ChannelId = msg.ChannelID.Value, ChannelId = msg.ChannelID.Value,
GuildId = msg.GuildID.Map(s => s.Value).OrDefault(), GuildId = guildId.IsDefined(out var guildIdValue)
? guildIdValue.Value
: (ulong?)null,
Content = content, Content = content,
Username = username, Username = username,
Metadata = metadata, Metadata = metadata,

View file

@ -66,8 +66,7 @@ builder
| GatewayIntents.GuildMessages | GatewayIntents.GuildMessages
| GatewayIntents.GuildWebhooks | GatewayIntents.GuildWebhooks
| GatewayIntents.MessageContents | GatewayIntents.MessageContents
// Actually GUILD_EXPRESSIONS | GatewayIntents.GuildExpressions;
| GatewayIntents.GuildEmojisAndStickers;
// Set a default status for all shards. This is updated to a shard-specific one in StatusUpdateService. // Set a default status for all shards. This is updated to a shard-specific one in StatusUpdateService.
g.Presence = new UpdatePresence( g.Presence = new UpdatePresence(

View file

@ -10,13 +10,6 @@ Command-line tools for this project can be installed with `dotnet tool restore`.
- We use [CSharpier][csharpier] for formatting .NET code. - We use [CSharpier][csharpier] for formatting .NET code.
It can be called with `dotnet csharpier .`, but is automatically run by Husky pre-commit. It can be called with `dotnet csharpier .`, but is automatically run by Husky pre-commit.
### Nuget
We currently use Remora's GitHub packages as the releases on nuget.org are missing some key features.
Add these with `dotnet nuget add source --username <githubUsername> --password <githubToken> --store-password-in-clear-text --name Remora "https://nuget.pkg.github.com/Remora/index.json"`
You must generate a personal access token (classic) [here](personal-access-token). Only give it the `read:packages` permission.
## Deploying Catalogger yourself ## Deploying Catalogger yourself
The bot itself should run on any server with .NET 8 and PostgreSQL 15 or later. The bot itself should run on any server with .NET 8 and PostgreSQL 15 or later.