]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
New Discord integration fixes (#37793)
authorPieter-Jan Briers <pieterjan.briers+git@gmail.com>
Sat, 24 May 2025 21:27:12 +0000 (23:27 +0200)
committerGitHub <noreply@github.com>
Sat, 24 May 2025 21:27:12 +0000 (23:27 +0200)
Fix admin chat relay.

Fix leaked task instance.

Fix warning about gateway intents on startup.

Fix packaging.

Content.Packaging/ServerPackaging.cs
Content.Server/Discord/DiscordLink/DiscordChatLink.cs
Content.Server/Discord/DiscordLink/DiscordLink.cs
Content.Shared/Chat/ChatChannel.cs

index 3ca53225dedd5ef091177a9487ec24a19364de3e..947a12601c537c2b05383538fa23fc863b19f900 100644 (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()
index 5460c9e274a2bd755d4f95a4ced81c9d16024c06..5a2c064e4d8ecf8ae3234aa60c7b36373b10eb28 100644 (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");
     }
 }
index a9172c98f7c330bd1bc6fffa538eb2d06101ef31..abf3189a993a0373bbc025508336eef46e185403 100644 (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;
index 88218c0bfada0e19c5b9f6cf2fea086c54a97142..faed544b82ac5dc4aac15416683e8f9e730b6bab 100644 (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)
             };
         }