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:
committed by
GitHub
parent
d56c0d0610
commit
ec3edb7264
@@ -47,6 +47,7 @@ public static class ServerPackaging
|
|||||||
// Python script had Npgsql. though we want Npgsql.dll as well soooo
|
// Python script had Npgsql. though we want Npgsql.dll as well soooo
|
||||||
"Npgsql",
|
"Npgsql",
|
||||||
"Microsoft",
|
"Microsoft",
|
||||||
|
"Discord",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static readonly List<string> ServerNotExtraAssemblies = new()
|
private static readonly List<string> ServerNotExtraAssemblies = new()
|
||||||
|
|||||||
@@ -8,12 +8,15 @@ using Robust.Shared.Configuration;
|
|||||||
|
|
||||||
namespace Content.Server.Discord.DiscordLink;
|
namespace Content.Server.Discord.DiscordLink;
|
||||||
|
|
||||||
public sealed class DiscordChatLink
|
public sealed class DiscordChatLink : IPostInjectInit
|
||||||
{
|
{
|
||||||
[Dependency] private readonly DiscordLink _discordLink = default!;
|
[Dependency] private readonly DiscordLink _discordLink = default!;
|
||||||
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||||
[Dependency] private readonly IChatManager _chatManager = default!;
|
[Dependency] private readonly IChatManager _chatManager = default!;
|
||||||
[Dependency] private readonly ITaskManager _taskManager = default!;
|
[Dependency] private readonly ITaskManager _taskManager = default!;
|
||||||
|
[Dependency] private readonly ILogManager _logManager = default!;
|
||||||
|
|
||||||
|
private ISawmill _sawmill = default!;
|
||||||
|
|
||||||
private ulong? _oocChannelId;
|
private ulong? _oocChannelId;
|
||||||
private ulong? _adminChannelId;
|
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
|
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
|
// @ 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("/", "\\/");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,11 @@ public sealed class DiscordLink : IPostInjectInit
|
|||||||
|
|
||||||
_client = new DiscordSocketClient(new DiscordSocketConfig()
|
_client = new DiscordSocketClient(new DiscordSocketConfig()
|
||||||
{
|
{
|
||||||
GatewayIntents = GatewayIntents.All
|
GatewayIntents = GatewayIntents.Guilds
|
||||||
|
| GatewayIntents.GuildMembers
|
||||||
|
| GatewayIntents.GuildMessages
|
||||||
|
| GatewayIntents.MessageContent
|
||||||
|
| GatewayIntents.DirectMessages,
|
||||||
});
|
});
|
||||||
_client.Log += Log;
|
_client.Log += Log;
|
||||||
_client.MessageReceived += OnCommandReceivedInternal;
|
_client.MessageReceived += OnCommandReceivedInternal;
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ namespace Content.Shared.Chat
|
|||||||
return channel switch
|
return channel switch
|
||||||
{
|
{
|
||||||
ChatChannel.OOC => Loc.GetString("chat-channel-humanized-ooc"),
|
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)
|
_ => throw new ArgumentOutOfRangeException(nameof(channel), channel, null)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user