Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discord AHelp Replies #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion Content.Server/Administration/ServerApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
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;
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;
Expand Down Expand Up @@ -48,7 +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 _adminManager = default!; // Frontier: ISharedAdminManager<IAdminManager>
[Dependency] private readonly IGameMapManager _gameMapManager = default!;
[Dependency] private readonly IServerNetManager _netManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
Expand Down Expand Up @@ -81,6 +83,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);

RegisterHandler(HttpMethod.Post, "/admin/actions/send_bwoink", ActionSendBwoink); // Frontier - Discord Ahelp Reply
}

public void Initialize()
Expand Down Expand Up @@ -393,6 +397,40 @@ await RunOnMainThread(async () =>
_sawmill.Info($"Forced instant round restart by {FormatLogActor(actor)}");
await RespondOk(context);
});
}
#endregion

#region Frontier
// Creating a region here incase more actions are added in the future

private async Task ActionSendBwoink(IStatusHandlerContext context)
{
var body = await ReadJson<BwoinkActionBody>(context);
if (body == null)
return;

await RunOnMainThread(async () =>
{
// Player not online or wrong Guid
if (!_playerManager.TryGetSessionById(new NetUserId(body.Guid), out var player))
{
await RespondError(
context,
ErrorCode.PlayerNotFound,
HttpStatusCode.UnprocessableContent,
"Player not found");
return;
}

var serverBwoinkSystem = _entitySystemManager.GetEntitySystem<BwoinkSystem>();
var message = new SharedBwoinkSystem.BwoinkTextMessage(player.UserId, SharedBwoinkSystem.SystemUserId, body.Text);
serverBwoinkSystem.OnWebhookBwoinkTextMessage(message, body);
Comment on lines +425 to +427
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of making a new system each time, just resolve it and run the respective method in the main thread.


// Respond with OK
await RespondOk(context);
});


}

#endregion
Expand Down Expand Up @@ -631,6 +669,17 @@ private sealed class MotdActionBody
public required string Motd { get; init; }
}

public sealed class BwoinkActionBody
{
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; }
public required string RoleName { get; init; }
public required string RoleColor { get; init; }
}

#endregion

#region Responses
Expand Down
Loading
Loading