Skip to content

Commit

Permalink
Serverside Webhook update on external sent ahelp messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzumi committed Oct 23, 2024
1 parent eb8df53 commit 3ae3bbf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
32 changes: 29 additions & 3 deletions Content.Server/Administration/ServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<GameTicker>();
var serverBwoinkSystem = _entitySystemManager.GetEntitySystem<BwoinkSystem>();
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);
});


Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions Content.Server/Administration/Systems/BwoinkSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private readonly
lastRunLevel)> _relayMessages = new();

private Dictionary<NetUserId, string> _oldMessageIds = new();
private readonly Dictionary<NetUserId, Queue<string>> _messageQueues = new();
public readonly Dictionary<NetUserId, Queue<string>> _messageQueues = new(); // Frontier - Changed to Public
private readonly HashSet<NetUserId> _processingChannels = new();
private readonly Dictionary<NetUserId, (TimeSpan Timestamp, bool Typing)> _typingUpdateTimestamps = new();
private string _overrideClientName = string.Empty;
Expand Down Expand Up @@ -704,7 +704,7 @@ private IList<INetChannel> GetTargetAdmins()
.ToList();
}

private static string GenerateAHelpMessage(AHelpMessageParams parameters)
public static string GenerateAHelpMessage(AHelpMessageParams parameters) // Frontier - Changed to Public
{
var stringbuilder = new StringBuilder();

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -749,6 +753,7 @@ public AHelpMessageParams(
string roundTime,
GameRunLevel roundState,
bool playedSound,
bool isDiscord = false, // Frontier
bool noReceivers = false,
string? icon = null)
{
Expand All @@ -757,6 +762,7 @@ public AHelpMessageParams(
IsAdmin = isAdmin;
RoundTime = roundTime;
RoundState = roundState;
IsDiscord = isDiscord; // Frontier
PlayedSound = playedSound;
NoReceivers = noReceivers;
Icon = icon;
Expand Down

0 comments on commit 3ae3bbf

Please sign in to comment.