New Discord integration fixes (#37793)

Fix admin chat relay.

Fix leaked task instance.

Fix warning about gateway intents on startup.

Fix packaging.
This commit is contained in:
Pieter-Jan Briers
2025-05-24 23:27:12 +02:00
committed by GitHub
parent d56c0d0610
commit ec3edb7264
4 changed files with 25 additions and 5 deletions

View File

@@ -47,6 +47,7 @@ public static class ServerPackaging
// Python script had Npgsql. though we want Npgsql.dll as well soooo
"Npgsql",
"Microsoft",
"Discord",
};
private static readonly List<string> ServerNotExtraAssemblies = new()

View File

@@ -8,12 +8,15 @@ using Robust.Shared.Configuration;
namespace Content.Server.Discord.DiscordLink;
public sealed class DiscordChatLink
public sealed class DiscordChatLink : IPostInjectInit
{
[Dependency] private readonly DiscordLink _discordLink = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
[Dependency] private readonly IChatManager _chatManager = default!;
[Dependency] private readonly ITaskManager _taskManager = default!;
[Dependency] private readonly ILogManager _logManager = default!;
private ISawmill _sawmill = default!;
private ulong? _oocChannelId;
private ulong? _adminChannelId;
@@ -73,7 +76,7 @@ public sealed class DiscordChatLink
}
}
public async Task SendMessage(string message, string author, ChatChannel channel)
public async void SendMessage(string message, string author, ChatChannel channel)
{
var channelId = channel switch
{
@@ -91,6 +94,18 @@ public sealed class DiscordChatLink
// @ and < are both problematic for discord due to pinging. / is sanitized solely to kneecap links to murder embeds via blunt force
message = message.Replace("@", "\\@").Replace("<", "\\<").Replace("/", "\\/");
await _discordLink.SendMessageAsync(channelId.Value, $"**{channel.GetString()}**: `{author}`: {message}");
try
{
await _discordLink.SendMessageAsync(channelId.Value, $"**{channel.GetString()}**: `{author}`: {message}");
}
catch (Exception e)
{
_sawmill.Error($"Error while sending Discord message: {e}");
}
}
void IPostInjectInit.PostInject()
{
_sawmill = _logManager.GetSawmill("discord.chat");
}
}

View File

@@ -103,7 +103,11 @@ public sealed class DiscordLink : IPostInjectInit
_client = new DiscordSocketClient(new DiscordSocketConfig()
{
GatewayIntents = GatewayIntents.All
GatewayIntents = GatewayIntents.Guilds
| GatewayIntents.GuildMembers
| GatewayIntents.GuildMessages
| GatewayIntents.MessageContent
| GatewayIntents.DirectMessages,
});
_client.Log += Log;
_client.MessageReceived += OnCommandReceivedInternal;

View File

@@ -107,7 +107,7 @@ namespace Content.Shared.Chat
return channel switch
{
ChatChannel.OOC => Loc.GetString("chat-channel-humanized-ooc"),
ChatChannel.Admin => Loc.GetString("chat-channel-humanized-admin"),
ChatChannel.AdminChat => Loc.GetString("chat-channel-humanized-admin"),
_ => throw new ArgumentOutOfRangeException(nameof(channel), channel, null)
};
}