OOC Relay experiment (#821)
This commit is contained in:
@@ -64,6 +64,7 @@ internal sealed partial class ChatManager : IChatManager
|
||||
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
||||
|
||||
RegisterRateLimits();
|
||||
CP14InitializeOOCRelay(); //CP14 OOC Relay
|
||||
}
|
||||
|
||||
private void OnOocEnabledChanged(bool val)
|
||||
@@ -259,6 +260,7 @@ internal sealed partial class ChatManager : IChatManager
|
||||
//TODO: player.Name color, this will need to change the structure of the MsgChatMessage
|
||||
ChatMessageToAll(ChatChannel.OOC, message, wrappedMessage, EntityUid.Invalid, hideChat: false, recordReplay: true, colorOverride: colorOverride, author: player.UserId);
|
||||
_mommiLink.SendOOCMessage(player.Name, message.Replace("@", "\\@").Replace("<", "\\<").Replace("/", "\\/")); // @ and < are both problematic for discord due to pinging. / is sanitized solely to kneecap links to murder embeds via blunt force
|
||||
CP14SendOOCInDiscord(player, message); //CP14 OOC Relay
|
||||
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"OOC from {player:Player}: {message}");
|
||||
}
|
||||
|
||||
|
||||
55
Content.Server/_CP14/Discord/ChatManager.OOCRelay.cs
Normal file
55
Content.Server/_CP14/Discord/ChatManager.OOCRelay.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using Content.Server.Discord;
|
||||
using Content.Shared.CCVar;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Player;
|
||||
using Serilog;
|
||||
|
||||
namespace Content.Server.Chat.Managers;
|
||||
|
||||
/// <summary>
|
||||
/// OOC Relay module
|
||||
/// </summary>
|
||||
internal sealed partial class ChatManager
|
||||
{
|
||||
[Dependency] private readonly DiscordWebhook _discord = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
|
||||
|
||||
private WebhookIdentifier? _OOCwebhook;
|
||||
|
||||
private void CP14InitializeOOCRelay()
|
||||
{
|
||||
var webhookUrl = _cfgManager.GetCVar(CCVars.DiscordRoundUpdateWebhook);
|
||||
|
||||
if (webhookUrl == string.Empty)
|
||||
return;
|
||||
|
||||
_discord.GetWebhook(webhookUrl,
|
||||
data =>
|
||||
{
|
||||
_OOCwebhook = data.ToIdentifier();
|
||||
});
|
||||
}
|
||||
|
||||
private async void CP14SendOOCInDiscord(ICommonSession player, string message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_OOCwebhook == null)
|
||||
return;
|
||||
|
||||
var name = player.Name;
|
||||
var content =
|
||||
message.Replace("@", "\\@")
|
||||
.Replace("<", "\\<")
|
||||
.Replace("/",
|
||||
"\\/"); // @ and < are both problematic for discord due to pinging. / is sanitized solely to kneecap links to murder embeds via blunt force
|
||||
|
||||
var payload = new WebhookPayload {Content = $"**`{name}`**: {content}"};
|
||||
await _discord.CreateMessage(_OOCwebhook.Value, payload);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"Error while sending discord OOC message:\n{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user