From 96a5f781d5b3d879226b9041ae6f9918a5418138 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Wed, 16 Oct 2024 13:50:40 +0200 Subject: [PATCH 01/23] First part of Remote Bwoinking --- Content.Server/Administration/ServerApi.cs | 37 +++++++++++++++++++ .../Administration/Systems/BwoinkSystem.cs | 3 +- Content.Server/Discord/WebhookPayload.cs | 3 ++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index f964e8961ce..2e800915bad 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -13,6 +13,7 @@ using Content.Server.Maps; using Content.Server.RoundEnd; using Content.Shared.Administration.Managers; +using Content.Shared.Administration; using Content.Shared.CCVar; using Content.Shared.GameTicking.Components; using Content.Shared.Prototypes; @@ -81,6 +82,7 @@ void IPostInjectInit.PostInject() RegisterActorHandler(HttpMethod.Post, "/admin/actions/force_preset", ActionForcePreset); RegisterActorHandler(HttpMethod.Post, "/admin/actions/set_motd", ActionForceMotd); RegisterActorHandler(HttpMethod.Patch, "/admin/actions/panic_bunker", ActionPanicPunker); + RegisterActorHandler(HttpMethod.Post, "/admin/actions/send_bwoink", ActionSendBwoink); } public void Initialize() @@ -393,6 +395,35 @@ await RunOnMainThread(async () => _sawmill.Info($"Forced instant round restart by {FormatLogActor(actor)}"); await RespondOk(context); }); + } + #endregion + + #region Frontier + + private async Task ActionSendBwoink(IStatusHandlerContext context, Actor actor) + { + var body = await ReadJson(context); + if (body == null) + return; + + await RunOnMainThread(async () => + { + if (!_playerManager.TryGetSessionById(new NetUserId(body.Guid), out var player)) + { + await RespondError( + context, + ErrorCode.PlayerNotFound, + HttpStatusCode.UnprocessableContent, + "Player not found"); + return; + } + + var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); + + + }); + + } #endregion @@ -631,6 +662,12 @@ private sealed class MotdActionBody public required string Motd { get; init; } } + private sealed class BwoinkActionBody + { + public required string Text { get; init; } + public required Guid Guid { get; init; } + } + #endregion #region Responses diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 893de4aba5b..c2b5c5777d3 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -429,6 +429,7 @@ private async void ProcessQueue(NetUserId userId, Queue messages) var payload = GeneratePayload(existingEmbed.description, existingEmbed.username, + userId.UserId, existingEmbed.characterName); // If there is no existing embed, create a new one @@ -478,7 +479,7 @@ private async void ProcessQueue(NetUserId userId, Queue messages) _processingChannels.Remove(userId); } - private WebhookPayload GeneratePayload(string messages, string username, string? characterName = null) + private WebhookPayload GeneratePayload(string messages, string username, Guid userId, string? characterName = null) { // Add character name if (characterName != null) diff --git a/Content.Server/Discord/WebhookPayload.cs b/Content.Server/Discord/WebhookPayload.cs index fdf5f48444a..bea6550497e 100644 --- a/Content.Server/Discord/WebhookPayload.cs +++ b/Content.Server/Discord/WebhookPayload.cs @@ -8,6 +8,9 @@ public struct WebhookPayload /// /// The message to send in the webhook. Maximum of 2000 characters. /// + [JsonPropertyName("UserID")] + public Guid? UserID { get; set; } + [JsonPropertyName("content")] public string? Content { get; set; } From 780ce086e8a79ddaf243f75d5b572d19b6dd942b Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 04:32:10 +0200 Subject: [PATCH 02/23] This should technically work --- Content.Server/Administration/ServerApi.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 2e800915bad..0f886933cfb 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -420,6 +420,11 @@ await RespondError( var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); + _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); + _sawmill.Debug($"Sent Bwoink to player {player.Name} by {FormatLogActor(actor)}"); + + + await RespondOk(context); }); From bdf791bc072bfe3e1601d09a7df7e9baf4703766 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 05:45:47 +0200 Subject: [PATCH 03/23] No Actoring --- Content.Server/Administration/ServerApi.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 0f886933cfb..c9d94473432 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -82,7 +82,8 @@ void IPostInjectInit.PostInject() RegisterActorHandler(HttpMethod.Post, "/admin/actions/force_preset", ActionForcePreset); RegisterActorHandler(HttpMethod.Post, "/admin/actions/set_motd", ActionForceMotd); RegisterActorHandler(HttpMethod.Patch, "/admin/actions/panic_bunker", ActionPanicPunker); - RegisterActorHandler(HttpMethod.Post, "/admin/actions/send_bwoink", ActionSendBwoink); + + RegisterHandler(HttpMethod.Post, "/admin/actions/send_bwoink", ActionSendBwoink); } public void Initialize() @@ -400,7 +401,7 @@ await RunOnMainThread(async () => #region Frontier - private async Task ActionSendBwoink(IStatusHandlerContext context, Actor actor) + private async Task ActionSendBwoink(IStatusHandlerContext context) { var body = await ReadJson(context); if (body == null) @@ -421,8 +422,7 @@ await RespondError( var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); - _sawmill.Debug($"Sent Bwoink to player {player.Name} by {FormatLogActor(actor)}"); - + //_sawmill.Debug($"Sent Bwoink to player {player.Name} by {FormatLogActor(actor)}"); await RespondOk(context); From 432c3efa13e72f08f81d4afa674c1588c1a4ef22 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 06:23:51 +0200 Subject: [PATCH 04/23] Fixes Guid not sending over --- Content.Server/Administration/Systems/BwoinkSystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index c2b5c5777d3..1f8aa00eaa9 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -505,6 +505,7 @@ private WebhookPayload GeneratePayload(string messages, string username, Guid us return new WebhookPayload { Username = username, + UserID = userId, AvatarUrl = string.IsNullOrWhiteSpace(_avatarUrl) ? null : _avatarUrl, Embeds = new List { From ce6f09897e4a1145bfefd8719e2048f957a2a4eb Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 06:54:53 +0200 Subject: [PATCH 05/23] Making it work for the final. --- Content.Server/Administration/ServerApi.cs | 29 +++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index c9d94473432..2a37c274c18 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -7,6 +7,7 @@ using System.Text.Json.Nodes; using System.Threading.Tasks; using Content.Server.Administration.Systems; +using Content.Server.Administration.Managers; using Content.Server.GameTicking; using Content.Server.GameTicking.Presets; using Content.Server.GameTicking.Rules.Components; @@ -83,7 +84,7 @@ void IPostInjectInit.PostInject() RegisterActorHandler(HttpMethod.Post, "/admin/actions/set_motd", ActionForceMotd); RegisterActorHandler(HttpMethod.Patch, "/admin/actions/panic_bunker", ActionPanicPunker); - RegisterHandler(HttpMethod.Post, "/admin/actions/send_bwoink", ActionSendBwoink); + RegisterHandler(HttpMethod.Post, "/admin/actions/send_bwoink", ActionSendBwoink); // Frontier - Discord Ahelp Reply } public void Initialize() @@ -400,6 +401,7 @@ await RunOnMainThread(async () => #endregion #region Frontier + // Creating a region here incase more actions are added in the future private async Task ActionSendBwoink(IStatusHandlerContext context) { @@ -409,6 +411,7 @@ private async Task ActionSendBwoink(IStatusHandlerContext context) await RunOnMainThread(async () => { + // Player not online or wrong Guid if (!_playerManager.TryGetSessionById(new NetUserId(body.Guid), out var player)) { await RespondError( @@ -419,11 +422,30 @@ await RespondError( return; } + // Message is parsed by the bot itself, we only need to make it a right component var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); - _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); - //_sawmill.Debug($"Sent Bwoink to player {player.Name} by {FormatLogActor(actor)}"); + // If we want to only send the message to the player + if (body.useronly) + { + // Get the required admin manager + IAdminManager aManager = default!; + // Get all Online admins with the adminhelp flag + var adminList = aManager.ActiveAdmins + .Where(p => _adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false) + .Select(p => p.Channel) + .ToList(); + + // Send the message to all online admins, so they also see it. + foreach (var admin in adminList) + { + _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, admin); + } + } + // Send the message to the player + _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); + // Respond with OK await RespondOk(context); }); @@ -671,6 +693,7 @@ private sealed class BwoinkActionBody { public required string Text { get; init; } public required Guid Guid { get; init; } + public bool useronly { get; init; } } #endregion From 977e5130736dfbe0d0392706f89521cfb32fca9e Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 07:09:13 +0200 Subject: [PATCH 06/23] Fixes for api --- Content.Server/Administration/ServerApi.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 2a37c274c18..d3b3d87c328 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -51,6 +51,7 @@ public sealed partial class ServerApi : IPostInjectInit [Dependency] private readonly IConfigurationManager _config = default!; [Dependency] private readonly ISharedPlayerManager _playerManager = default!; [Dependency] private readonly ISharedAdminManager _adminManager = default!; + [Dependency] private readonly IAdminManager _serverAdminManager = default!; [Dependency] private readonly IGameMapManager _gameMapManager = default!; [Dependency] private readonly IServerNetManager _netManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -426,13 +427,10 @@ await RespondError( var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); // If we want to only send the message to the player - if (body.useronly) + if (!body.useronly) { - // Get the required admin manager - IAdminManager aManager = default!; - // Get all Online admins with the adminhelp flag - var adminList = aManager.ActiveAdmins + var adminList = _serverAdminManager.ActiveAdmins .Where(p => _adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false) .Select(p => p.Channel) .ToList(); From 551da03dbebf7f6f59ba04add03ad647f8de4126 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 07:41:17 +0200 Subject: [PATCH 07/23] Moar Commants! Just more Comments to mark Frontier changes. --- Content.Server/Administration/Systems/BwoinkSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 1f8aa00eaa9..aa99997b45e 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -429,7 +429,7 @@ private async void ProcessQueue(NetUserId userId, Queue messages) var payload = GeneratePayload(existingEmbed.description, existingEmbed.username, - userId.UserId, + userId.UserId, // Frontier, this is used to identify the players in the webhook existingEmbed.characterName); // If there is no existing embed, create a new one @@ -505,7 +505,7 @@ private WebhookPayload GeneratePayload(string messages, string username, Guid us return new WebhookPayload { Username = username, - UserID = userId, + UserID = userId, // Frontier, this is used to identify the players in the webhook AvatarUrl = string.IsNullOrWhiteSpace(_avatarUrl) ? null : _avatarUrl, Embeds = new List { From 78c8252250a805ea3dfd9978f93e3f84eac3c212 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 07:44:38 +0200 Subject: [PATCH 08/23] comment --- Content.Server/Discord/WebhookPayload.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Discord/WebhookPayload.cs b/Content.Server/Discord/WebhookPayload.cs index bea6550497e..d70a221117e 100644 --- a/Content.Server/Discord/WebhookPayload.cs +++ b/Content.Server/Discord/WebhookPayload.cs @@ -8,7 +8,7 @@ public struct WebhookPayload /// /// The message to send in the webhook. Maximum of 2000 characters. /// - [JsonPropertyName("UserID")] + [JsonPropertyName("UserID")] // Frontier, this is used to identify the players in the webhook public Guid? UserID { get; set; } [JsonPropertyName("content")] From a7276e79e25a68912db10da0cf7867c549cfba5a Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 07:45:57 +0200 Subject: [PATCH 09/23] wops --- Content.Server/Discord/WebhookPayload.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Content.Server/Discord/WebhookPayload.cs b/Content.Server/Discord/WebhookPayload.cs index d70a221117e..8d587e0bd14 100644 --- a/Content.Server/Discord/WebhookPayload.cs +++ b/Content.Server/Discord/WebhookPayload.cs @@ -5,12 +5,11 @@ namespace Content.Server.Discord; // https://discord.com/developers/docs/resources/channel#message-object-message-structure public struct WebhookPayload { + [JsonPropertyName("UserID")] // Frontier, this is used to identify the players in the webhook + public Guid? UserID { get; set; } /// /// The message to send in the webhook. Maximum of 2000 characters. /// - [JsonPropertyName("UserID")] // Frontier, this is used to identify the players in the webhook - public Guid? UserID { get; set; } - [JsonPropertyName("content")] public string? Content { get; set; } From 83c724475c0f6564e058d6d2ee8184d92fb2dac1 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 08:02:44 +0200 Subject: [PATCH 10/23] Fixes Naming Rules --- Content.Server/Administration/ServerApi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index d3b3d87c328..778fbf544d1 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -691,7 +691,7 @@ private sealed class BwoinkActionBody { public required string Text { get; init; } public required Guid Guid { get; init; } - public bool useronly { get; init; } + public bool UserOnly { get; init; } } #endregion From 6a78daf02bc54654394c39fb5eceab3e25768928 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 19 Oct 2024 08:08:49 +0200 Subject: [PATCH 11/23] I Should also fix the naming in the actually code... --- Content.Server/Administration/ServerApi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 778fbf544d1..48f73f7f59e 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -427,7 +427,7 @@ await RespondError( var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); // If we want to only send the message to the player - if (!body.useronly) + if (!body.UserOnly) { // Get all Online admins with the adminhelp flag var adminList = _serverAdminManager.ActiveAdmins From a968075452597343d6ac1f734eb8884bfbdbb410 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Wed, 23 Oct 2024 01:52:35 +0200 Subject: [PATCH 12/23] Testing some new code --- Content.Server/Administration/ServerApi.cs | 19 ++++++++++++++++++- .../Administration/Systems/BwoinkSystem.cs | 10 ++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 48f73f7f59e..640960eed32 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -61,6 +61,7 @@ public sealed partial class ServerApi : IPostInjectInit [Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly ILocalizationManager _loc = default!; + [Dependency] private readonly BwoinkSystem _serverBwoinkSystem = default!; private string _token = string.Empty; private ISawmill _sawmill = default!; @@ -426,6 +427,7 @@ await RespondError( // Message is parsed by the bot itself, we only need to make it a right component var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); + // If we want to only send the message to the player if (!body.UserOnly) { @@ -443,9 +445,24 @@ await RespondError( } // Send the message to the player _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); + + var ticker = _entitySystemManager.GetEntitySystem(); + var queue = _serverBwoinkSystem._messageQueues.GetOrNew(player.UserId); + + var FormattedMessage = new AHelpMessageParams( + player.Name, + body.Text, + true, + ticker.RoundDuration().ToString("hh\\:mm\\:ss"), + ticker.RunLevel, + true, + isDiscord: true + ); + + var FinalMessage = BwoinkSystem.GenerateAHelpMessage(FormattedMessage); + queue.Enqueue(FinalMessage); // Respond with OK await RespondOk(context); - }); diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index aa99997b45e..b2a775fb140 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -59,7 +59,7 @@ private readonly lastRunLevel)> _relayMessages = new(); private Dictionary _oldMessageIds = new(); - private readonly Dictionary> _messageQueues = new(); + public readonly Dictionary> _messageQueues = new(); // Frontier - Changed to Public private readonly HashSet _processingChannels = new(); private readonly Dictionary _typingUpdateTimestamps = new(); private string _overrideClientName = string.Empty; @@ -704,7 +704,7 @@ private IList GetTargetAdmins() .ToList(); } - private static string GenerateAHelpMessage(AHelpMessageParams parameters) + public static string GenerateAHelpMessage(AHelpMessageParams parameters) // Frontier - Changed to Public { var stringbuilder = new StringBuilder(); @@ -722,6 +722,9 @@ private static string GenerateAHelpMessage(AHelpMessageParams parameters) if (!parameters.PlayedSound) stringbuilder.Append(" **(S)**"); + if (parameters.IsDiscord ?? false) // Frontier - Discord Indicator + stringbuilder.Append(" **(DC)**"); + if (parameters.Icon == null) stringbuilder.Append($" **{parameters.Username}:** "); else @@ -740,6 +743,7 @@ public sealed class AHelpMessageParams public GameRunLevel RoundState { get; set; } public bool PlayedSound { get; set; } public bool NoReceivers { get; set; } + public bool? IsDiscord { get; set; } // Frontier public string? Icon { get; set; } public AHelpMessageParams( @@ -749,6 +753,7 @@ public AHelpMessageParams( string roundTime, GameRunLevel roundState, bool playedSound, + bool isDiscord = false, // Frontier bool noReceivers = false, string? icon = null) { @@ -757,6 +762,7 @@ public AHelpMessageParams( IsAdmin = isAdmin; RoundTime = roundTime; RoundState = roundState; + IsDiscord = isDiscord; // Frontier PlayedSound = playedSound; NoReceivers = noReceivers; Icon = icon; From 992e8df0e485678a8093cce57c7ea8c06d70b7d9 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Wed, 23 Oct 2024 02:20:48 +0200 Subject: [PATCH 13/23] Naming rule and dependency fix (hopefully) --- Content.Server/Administration/ServerApi.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 640960eed32..43ff7439f97 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -61,7 +61,6 @@ public sealed partial class ServerApi : IPostInjectInit [Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; [Dependency] private readonly ILocalizationManager _loc = default!; - [Dependency] private readonly BwoinkSystem _serverBwoinkSystem = default!; private string _token = string.Empty; private ISawmill _sawmill = default!; @@ -447,9 +446,10 @@ await RespondError( _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); var ticker = _entitySystemManager.GetEntitySystem(); + var _serverBwoinkSystem = _entitySystemManager.GetEntitySystem(); var queue = _serverBwoinkSystem._messageQueues.GetOrNew(player.UserId); - var FormattedMessage = new AHelpMessageParams( + var formattedMessage = new AHelpMessageParams( player.Name, body.Text, true, @@ -459,8 +459,8 @@ await RespondError( isDiscord: true ); - var FinalMessage = BwoinkSystem.GenerateAHelpMessage(FormattedMessage); - queue.Enqueue(FinalMessage); + var finalMessage = BwoinkSystem.GenerateAHelpMessage(formattedMessage); + queue.Enqueue(finalMessage); // Respond with OK await RespondOk(context); }); From 3ae3bbf35e273a79f9cc6db1cde8041d8901bf37 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Wed, 23 Oct 2024 03:29:04 +0200 Subject: [PATCH 14/23] Serverside Webhook update on external sent ahelp messages --- Content.Server/Administration/ServerApi.cs | 32 +++++++++++++++++-- .../Administration/Systems/BwoinkSystem.cs | 10 ++++-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 48f73f7f59e..0e69db65811 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -424,7 +424,8 @@ await RespondError( } // Message is parsed by the bot itself, we only need to make it a right component - var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); + var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.TextFormatted); + // If we want to only send the message to the player if (!body.UserOnly) @@ -443,9 +444,32 @@ await RespondError( } // Send the message to the player _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); + + + // This saves me a headache of making the bot remembering every message it send and adding it to the embed. + // So i just let the existing system handle it + if (body.webhookupdate) + { + var ticker = _entitySystemManager.GetEntitySystem(); + var serverBwoinkSystem = _entitySystemManager.GetEntitySystem(); + var queue = serverBwoinkSystem._messageQueues.GetOrNew(player.UserId); + + var formattedMessage = new AHelpMessageParams( + player.Name, + body.TextRaw, + true, + ticker.RoundDuration().ToString("hh\\:mm\\:ss"), + ticker.RunLevel, + true, + isDiscord: true + ); + + var finalMessage = BwoinkSystem.GenerateAHelpMessage(formattedMessage); + queue.Enqueue(finalMessage); + + } // Respond with OK await RespondOk(context); - }); @@ -689,9 +713,11 @@ private sealed class MotdActionBody private sealed class BwoinkActionBody { - public required string Text { get; init; } + public required string TextRaw { get; init; } + public required string TextFormatted { get; init; } public required Guid Guid { get; init; } public bool UserOnly { get; init; } + public required bool webhookupdate { get; init; } } #endregion diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index aa99997b45e..b2a775fb140 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -59,7 +59,7 @@ private readonly lastRunLevel)> _relayMessages = new(); private Dictionary _oldMessageIds = new(); - private readonly Dictionary> _messageQueues = new(); + public readonly Dictionary> _messageQueues = new(); // Frontier - Changed to Public private readonly HashSet _processingChannels = new(); private readonly Dictionary _typingUpdateTimestamps = new(); private string _overrideClientName = string.Empty; @@ -704,7 +704,7 @@ private IList GetTargetAdmins() .ToList(); } - private static string GenerateAHelpMessage(AHelpMessageParams parameters) + public static string GenerateAHelpMessage(AHelpMessageParams parameters) // Frontier - Changed to Public { var stringbuilder = new StringBuilder(); @@ -722,6 +722,9 @@ private static string GenerateAHelpMessage(AHelpMessageParams parameters) if (!parameters.PlayedSound) stringbuilder.Append(" **(S)**"); + if (parameters.IsDiscord ?? false) // Frontier - Discord Indicator + stringbuilder.Append(" **(DC)**"); + if (parameters.Icon == null) stringbuilder.Append($" **{parameters.Username}:** "); else @@ -740,6 +743,7 @@ public sealed class AHelpMessageParams public GameRunLevel RoundState { get; set; } public bool PlayedSound { get; set; } public bool NoReceivers { get; set; } + public bool? IsDiscord { get; set; } // Frontier public string? Icon { get; set; } public AHelpMessageParams( @@ -749,6 +753,7 @@ public AHelpMessageParams( string roundTime, GameRunLevel roundState, bool playedSound, + bool isDiscord = false, // Frontier bool noReceivers = false, string? icon = null) { @@ -757,6 +762,7 @@ public AHelpMessageParams( IsAdmin = isAdmin; RoundTime = roundTime; RoundState = roundState; + IsDiscord = isDiscord; // Frontier PlayedSound = playedSound; NoReceivers = noReceivers; Icon = icon; From 3939f30d9647b5dc587a86816e4a40d8784aef97 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Sat, 2 Nov 2024 13:21:12 +0100 Subject: [PATCH 15/23] Still get data from custom URL's, even if it dosent match a discord webhook --- .../Administration/Systems/BwoinkSystem.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index b2a775fb140..209507d719e 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -318,6 +318,7 @@ private async void OnWebhookChanged(string url) { // TODO: Ideally, CVar validation during setting should be better integrated Log.Warning("Webhook URL does not appear to be valid. Using anyways..."); + await SetWebhookData(url); // Frontier - Support for Custom URLS, we still want to see if theres Webhook data available return; } @@ -327,22 +328,19 @@ private async void OnWebhookChanged(string url) return; } - var webhookId = match.Groups[1].Value; - var webhookToken = match.Groups[2].Value; - // Fire and forget - await SetWebhookData(webhookId, webhookToken); + await SetWebhookData(url); // Frontier - Support for Custom URLS } - private async Task SetWebhookData(string id, string token) + private async Task SetWebhookData(string url) // Frontier - Support for Custom URLS { - var response = await _httpClient.GetAsync($"https://discord.com/api/v10/webhooks/{id}/{token}"); + var response = await _httpClient.GetAsync(url); var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { _sawmill.Log(LogLevel.Error, - $"Discord returned bad status code when trying to get webhook data (perhaps the webhook URL is invalid?): {response.StatusCode}\nResponse: {content}"); + $"Webhook returned bad status code when trying to get webhook data (perhaps the webhook URL is invalid?): {response.StatusCode}\nResponse: {content}"); return; } From c98e41726a7cf637f293e8ab1cdb067b1ab00c31 Mon Sep 17 00:00:00 2001 From: Myzumi <34660019+Myzumi@users.noreply.github.com> Date: Wed, 6 Nov 2024 23:39:48 +0100 Subject: [PATCH 16/23] Apply suggestions from code review (Part 1) Co-authored-by: Whatstone <166147148+whatston3@users.noreply.github.com> --- Content.Server/Administration/ServerApi.cs | 2 +- Content.Server/Administration/Systems/BwoinkSystem.cs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 45af5603fbe..1397236904c 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -717,7 +717,7 @@ private sealed class BwoinkActionBody public required string TextFormatted { get; init; } public required Guid Guid { get; init; } public bool UserOnly { get; init; } - public required bool webhookupdate { get; init; } + public required bool WebhookUpdate { get; init; } } #endregion diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 209507d719e..edaafb83303 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -477,7 +477,7 @@ private async void ProcessQueue(NetUserId userId, Queue messages) _processingChannels.Remove(userId); } - private WebhookPayload GeneratePayload(string messages, string username, Guid userId, string? characterName = null) + private WebhookPayload GeneratePayload(string messages, string username, Guid userId, string? characterName = null) // Frontier: added Guid { // Add character name if (characterName != null) @@ -720,7 +720,7 @@ public static string GenerateAHelpMessage(AHelpMessageParams parameters) // Fron if (!parameters.PlayedSound) stringbuilder.Append(" **(S)**"); - if (parameters.IsDiscord ?? false) // Frontier - Discord Indicator + if (parameters.IsDiscord) // Frontier - Discord Indicator stringbuilder.Append(" **(DC)**"); if (parameters.Icon == null) @@ -741,7 +741,7 @@ public sealed class AHelpMessageParams public GameRunLevel RoundState { get; set; } public bool PlayedSound { get; set; } public bool NoReceivers { get; set; } - public bool? IsDiscord { get; set; } // Frontier + public bool IsDiscord { get; set; } // Frontier public string? Icon { get; set; } public AHelpMessageParams( From 0cfe2493de2566b04952d00a41b30ce9c77d4175 Mon Sep 17 00:00:00 2001 From: Myzumi Date: Thu, 7 Nov 2024 00:10:38 +0100 Subject: [PATCH 17/23] Apply suggestions from code review (Part 2) --- Content.Server/Administration/ServerApi.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 1397236904c..121b85e7138 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -50,8 +50,7 @@ public sealed partial class ServerApi : IPostInjectInit [Dependency] private readonly IStatusHost _statusHost = default!; [Dependency] private readonly IConfigurationManager _config = default!; [Dependency] private readonly ISharedPlayerManager _playerManager = default!; - [Dependency] private readonly ISharedAdminManager _adminManager = default!; - [Dependency] private readonly IAdminManager _serverAdminManager = default!; + [Dependency] private readonly IAdminManager _adminManager = default!; // Frontier: ISharedAdminManager [Dependency] private readonly IGameMapManager _gameMapManager = default!; [Dependency] private readonly IServerNetManager _netManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; @@ -432,7 +431,7 @@ await RespondError( if (!body.UserOnly) { // Get all Online admins with the adminhelp flag - var adminList = _serverAdminManager.ActiveAdmins + var adminList = _adminManager.ActiveAdmins .Where(p => _adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false) .Select(p => p.Channel) .ToList(); @@ -448,7 +447,7 @@ await RespondError( // This saves me a headache of making the bot remembering every message it send and adding it to the embed. // So i just let the existing system handle it - if (body.webhookupdate) + if (body.WebhookUpdate) { var ticker = _entitySystemManager.GetEntitySystem(); var serverBwoinkSystem = _entitySystemManager.GetEntitySystem(); From edb1cf93f0149d8caef6efec4d8c41965bdf962f Mon Sep 17 00:00:00 2001 From: Whatstone Date: Thu, 21 Nov 2024 16:56:22 -0500 Subject: [PATCH 18/23] Bwoink system suggsetions --- Content.Server/Administration/ServerApi.cs | 53 ++----------- .../Administration/Systems/BwoinkSystem.cs | 79 ++++++++++++++----- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/Content.Server/Administration/ServerApi.cs b/Content.Server/Administration/ServerApi.cs index 121b85e7138..2653bca0dec 100644 --- a/Content.Server/Administration/ServerApi.cs +++ b/Content.Server/Administration/ServerApi.cs @@ -422,51 +422,10 @@ await RespondError( return; } - // Message is parsed by the bot itself, we only need to make it a right component - var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.TextFormatted); + var serverBwoinkSystem = _entitySystemManager.GetEntitySystem(); + var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text); + serverBwoinkSystem.OnWebhookBwoinkTextMessage(message, body); - - - // If we want to only send the message to the player - if (!body.UserOnly) - { - // Get all Online admins with the adminhelp flag - var adminList = _adminManager.ActiveAdmins - .Where(p => _adminManager.GetAdminData(p)?.HasFlag(AdminFlags.Adminhelp) ?? false) - .Select(p => p.Channel) - .ToList(); - - // Send the message to all online admins, so they also see it. - foreach (var admin in adminList) - { - _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, admin); - } - } - // Send the message to the player - _entityManager.EntityNetManager?.SendSystemNetworkMessage(message, player.Channel); - - // This saves me a headache of making the bot remembering every message it send and adding it to the embed. - // So i just let the existing system handle it - if (body.WebhookUpdate) - { - var ticker = _entitySystemManager.GetEntitySystem(); - var serverBwoinkSystem = _entitySystemManager.GetEntitySystem(); - var queue = serverBwoinkSystem._messageQueues.GetOrNew(player.UserId); - - var formattedMessage = new AHelpMessageParams( - player.Name, - body.TextRaw, - true, - ticker.RoundDuration().ToString("hh\\:mm\\:ss"), - ticker.RunLevel, - true, - isDiscord: true - ); - - var finalMessage = BwoinkSystem.GenerateAHelpMessage(formattedMessage); - queue.Enqueue(finalMessage); - - } // Respond with OK await RespondOk(context); }); @@ -710,10 +669,10 @@ private sealed class MotdActionBody public required string Motd { get; init; } } - private sealed class BwoinkActionBody + public sealed class BwoinkActionBody { - public required string TextRaw { get; init; } - public required string TextFormatted { get; init; } + public required string Text { get; init; } + public required string Username { get; init; } public required Guid Guid { get; init; } public bool UserOnly { get; init; } public required bool WebhookUpdate { get; init; } diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index edaafb83303..5d51296aaa3 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -541,10 +541,20 @@ public override void Update(float frameTime) } } + // Frontier: webhook text messages + public void OnWebhookBwoinkTextMessage(BwoinkTextMessage message, ServerApi.BwoinkActionBody body) + { + // Note for forks: + AdminData webhookAdminData = new(); + + // TODO: fix args + OnBwoinkInternal(message, SystemUserId, webhookAdminData, body.Username, null, body.UserOnly, body.WebhookUpdate, true); + } + protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySessionEventArgs eventArgs) { base.OnBwoinkTextMessage(message, eventArgs); - _activeConversations[message.UserId] = DateTime.Now; + var senderSession = eventArgs.SenderSession; // TODO: Sanitize text? @@ -562,6 +572,23 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes if (_rateLimit.CountAction(eventArgs.SenderSession, RateLimitKey) != RateLimitStatus.Allowed) return; + OnBwoinkInternal(message, eventArgs.SenderSession.UserId, senderAdmin, eventArgs.SenderSession.Name, eventArgs.SenderSession.Channel, false, true, false); + } + + /// + /// Sends a bwoink. Common to both internal messages (sent via the ahelp or admin interface) and webhook messages (sent through the webhook, e.g. via Discord) + /// + /// The message being sent. + /// The network GUID of the person sending the message. + /// The admin privileges of the person sending the message. + /// The name of the person sending the message. + /// The channel to send a message to, e.g. in case of failure to send + /// If true, message should be sent off through the webhook if possible + /// Message originated from a webhook (e.g. Discord) + private void OnBwoinkInternal(BwoinkTextMessage message, NetUserId senderId, AdminData? senderAdmin, string senderName, INetChannel? senderChannel, bool userOnly, bool sendWebhook, bool fromWebhook) + { + _activeConversations[message.UserId] = DateTime.Now; + var escapedText = FormattedMessage.EscapeText(message.Text); string bwoinkText; @@ -577,31 +604,37 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes senderAdmin.Flags == AdminFlags.Adminhelp) // Mentor. Not full admin. That's why it's colored differently. { - bwoinkText = $"[color=purple]{adminPrefix}{senderSession.Name}[/color]"; + bwoinkText = $"[color=purple]{adminPrefix}{senderName}[/color]"; } - else if (senderAdmin is not null && senderAdmin.HasFlag(AdminFlags.Adminhelp)) + else if (fromWebhook || senderAdmin is not null && senderAdmin.HasFlag(AdminFlags.Adminhelp)) // Frontier: anything sent via webhooks are from an admin. { - bwoinkText = $"[color=red]{adminPrefix}{senderSession.Name}[/color]"; + bwoinkText = $"[color=red]{adminPrefix}{senderName}[/color]"; } else { - bwoinkText = $"{senderSession.Name}"; + bwoinkText = $"{senderName}"; } + if (fromWebhook) + bwoinkText = $"(DC) {bwoinkText}"; + bwoinkText = $"{(message.PlaySound ? "" : "(S) ")}{bwoinkText}: {escapedText}"; // If it's not an admin / admin chooses to keep the sound then play it. - var playSound = !senderAHelpAdmin || message.PlaySound; - var msg = new BwoinkTextMessage(message.UserId, senderSession.UserId, bwoinkText, playSound: playSound); + var playSound = senderAdmin == null || message.PlaySound; + var msg = new BwoinkTextMessage(message.UserId, senderId, bwoinkText, playSound: playSound); LogBwoink(msg); var admins = GetTargetAdmins(); // Notify all admins - foreach (var channel in admins) + if (!userOnly) { - RaiseNetworkEvent(msg, channel); + foreach (var channel in admins) + { + RaiseNetworkEvent(msg, channel); + } } string adminPrefixWebhook = ""; @@ -633,13 +666,16 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes } else { - overrideMsgText = $"{senderSession.Name}"; // Not an admin, name is not overridden. + overrideMsgText = $"{senderName}"; // Not an admin, name is not overridden. } + if (fromWebhook) + overrideMsgText = $"(DC) {overrideMsgText}"; + overrideMsgText = $"{(message.PlaySound ? "" : "(S) ")}{overrideMsgText}: {escapedText}"; RaiseNetworkEvent(new BwoinkTextMessage(message.UserId, - senderSession.UserId, + senderId, overrideMsgText, playSound: playSound), session.Channel); @@ -650,13 +686,13 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes } var sendsWebhook = _webhookUrl != string.Empty; - if (sendsWebhook) + if (sendsWebhook && sendWebhook) { if (!_messageQueues.ContainsKey(msg.UserId)) _messageQueues[msg.UserId] = new Queue(); var str = message.Text; - var unameLength = senderSession.Name.Length; + var unameLength = senderName.Length; if (unameLength + str.Length + _maxAdditionalChars > DescriptionMax) { @@ -665,12 +701,13 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes var nonAfkAdmins = GetNonAfkAdmins(); var messageParams = new AHelpMessageParams( - senderSession.Name, + senderName, str, - !personalChannel, + senderId != message.UserId, _gameTicker.RoundDuration().ToString("hh\\:mm\\:ss"), _gameTicker.RunLevel, playedSound: playSound, + isDiscord: fromWebhook, noReceivers: nonAfkAdmins.Count == 0 ); _messageQueues[msg.UserId].Enqueue(GenerateAHelpMessage(messageParams)); @@ -680,10 +717,14 @@ protected override void OnBwoinkTextMessage(BwoinkTextMessage message, EntitySes return; // No admin online, let the player know - var systemText = Loc.GetString("bwoink-system-starmute-message-no-other-users"); - var starMuteMsg = new BwoinkTextMessage(message.UserId, SystemUserId, systemText); - RaiseNetworkEvent(starMuteMsg, senderSession.Channel); + if (senderChannel != null) + { + var systemText = Loc.GetString("bwoink-system-starmute-message-no-other-users"); + var starMuteMsg = new BwoinkTextMessage(message.UserId, SystemUserId, systemText); + RaiseNetworkEvent(starMuteMsg, senderChannel); + } } + // End Frontier: private IList GetNonAfkAdmins() { @@ -702,7 +743,7 @@ private IList GetTargetAdmins() .ToList(); } - public static string GenerateAHelpMessage(AHelpMessageParams parameters) // Frontier - Changed to Public + private static string GenerateAHelpMessage(AHelpMessageParams parameters) // Frontier - Changed to Public { var stringbuilder = new StringBuilder(); From 2dee7fa51039676e2f206da7e78236078115aadc Mon Sep 17 00:00:00 2001 From: Whatstone Date: Thu, 21 Nov 2024 17:09:44 -0500 Subject: [PATCH 19/23] missing BwoinkSystem changes --- Content.Server/Administration/Systems/BwoinkSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 5d51296aaa3..6be594a8bd1 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -743,7 +743,7 @@ private IList GetTargetAdmins() .ToList(); } - private static string GenerateAHelpMessage(AHelpMessageParams parameters) // Frontier - Changed to Public + private static string GenerateAHelpMessage(AHelpMessageParams parameters) { var stringbuilder = new StringBuilder(); From f20cb90c166d7a423cbe45c276e295cafca346a1 Mon Sep 17 00:00:00 2001 From: Whatstone Date: Thu, 21 Nov 2024 17:12:11 -0500 Subject: [PATCH 20/23] Change access on BwoinkSystem._messageQueues --- Content.Server/Administration/Systems/BwoinkSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 6be594a8bd1..421f655aad9 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -59,7 +59,7 @@ private readonly lastRunLevel)> _relayMessages = new(); private Dictionary _oldMessageIds = new(); - public readonly Dictionary> _messageQueues = new(); // Frontier - Changed to Public + private readonly Dictionary> _messageQueues = new(); private readonly HashSet _processingChannels = new(); private readonly Dictionary _typingUpdateTimestamps = new(); private string _overrideClientName = string.Empty; From 124f73750eb022073c84ee6a2f35d985fd2fbb3e Mon Sep 17 00:00:00 2001 From: Myzumi Date: Tue, 26 Nov 2024 15:34:10 +0100 Subject: [PATCH 21/23] Updates the Regex to support other Discord Clients (beta, alpha) --- Content.Server/Administration/Systems/BwoinkSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 421f655aad9..4b6a9fa4d73 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -43,7 +43,7 @@ public sealed partial class BwoinkSystem : SharedBwoinkSystem [Dependency] private readonly IServerDbManager _dbManager = default!; [Dependency] private readonly PlayerRateLimitManager _rateLimit = default!; - [GeneratedRegex(@"^https://discord\.com/api/webhooks/(\d+)/((?!.*/).*)$")] + [GeneratedRegex(@"^https://(?:(?:canary|ptb).)?discord\.com/api/webhooks/(\d+)/((?!.*/).*)$")] private static partial Regex DiscordRegex(); private ISawmill _sawmill = default!; From 3e4f125c81d7b19dadb7484980241ff81cdc323c Mon Sep 17 00:00:00 2001 From: Myzumi Date: Tue, 26 Nov 2024 15:55:46 +0100 Subject: [PATCH 22/23] Merge Fixes --- Content.Server/Administration/Systems/BwoinkSystem.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index 6e9da9e395f..c397d83028b 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -142,7 +142,7 @@ private async void OnCallChanged(string url) var webhookId = match.Groups[1].Value; var webhookToken = match.Groups[2].Value; - _onCallData = await GetWebhookData(webhookId, webhookToken); + _onCallData = await GetWebhookData(url); } private void PlayerRateLimitedAction(ICommonSession obj) @@ -351,7 +351,7 @@ private async void OnWebhookChanged(string url) { // TODO: Ideally, CVar validation during setting should be better integrated Log.Warning("Webhook URL does not appear to be valid. Using anyways..."); - await SetWebhookData(url); // Frontier - Support for Custom URLS, we still want to see if theres Webhook data available + await GetWebhookData(url); // Frontier - Support for Custom URLS, we still want to see if theres Webhook data available return; } @@ -362,7 +362,7 @@ private async void OnWebhookChanged(string url) } // Fire and forget - await SetWebhookData(url); // Frontier - Support for Custom URLS + await GetWebhookData(url); // Frontier - Support for Custom URLS } private async Task GetWebhookData(string url) @@ -545,7 +545,7 @@ private async void ProcessQueue(NetUserId userId, Queue mess $"**[Go to ahelp](https://discord.com/channels/{guildId}/{channelId}/{existingEmbed.Id})**"); } - payload = GeneratePayload(message.ToString(), existingEmbed.Username, existingEmbed.CharacterName); + payload = GeneratePayload(message.ToString(), existingEmbed.Username, userId, existingEmbed.CharacterName); var request = await _httpClient.PostAsync($"{_onCallUrl}?wait=true", new StringContent(JsonSerializer.Serialize(payload), Encoding.UTF8, "application/json")); From f9ae1f4fd99d5b43cd4a5c4ad0ed780aeba3680f Mon Sep 17 00:00:00 2001 From: Whatstone Date: Tue, 26 Nov 2024 11:51:34 -0500 Subject: [PATCH 23/23] BwoinkSystem: explicitly match "canary."/"ptb." --- Content.Server/Administration/Systems/BwoinkSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Server/Administration/Systems/BwoinkSystem.cs b/Content.Server/Administration/Systems/BwoinkSystem.cs index c397d83028b..a3440aad53d 100644 --- a/Content.Server/Administration/Systems/BwoinkSystem.cs +++ b/Content.Server/Administration/Systems/BwoinkSystem.cs @@ -44,7 +44,7 @@ public sealed partial class BwoinkSystem : SharedBwoinkSystem [Dependency] private readonly IServerDbManager _dbManager = default!; [Dependency] private readonly PlayerRateLimitManager _rateLimit = default!; - [GeneratedRegex(@"^https://(?:(?:canary|ptb).)?discord\.com/api/webhooks/(\d+)/((?!.*/).*)$")] + [GeneratedRegex(@"^https://(?:(?:canary|ptb)\.)?discord\.com/api/webhooks/(\d+)/((?!.*/).*)$")] private static partial Regex DiscordRegex(); private string _webhookUrl = string.Empty;