-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADMIN TOOL] adminwho posting in discord channel (#819)
## Описание PR Каждые 15 минут отправляеться справочная информация о всех админах находящихся на мрп в дискорд зачем это? для контроля администрации, объявляю: # 1984 ## Медиа ![image](https://github.com/user-attachments/assets/71e8800a-9e17-49d7-873d-d5e76efba1b7) ![image](https://github.com/user-attachments/assets/702f26cd-562a-450c-853d-7b89a41977a7) ## Требования <!-- В связи с наплывом ПР'ов нам необходимо убедиться, что ПР'ы следуют правильным рекомендациям. Пожалуйста, уделите время прочтению, если делаете пулл реквест (ПР) впервые. Отметьте поля ниже, чтобы подтвердить, что Вы действительно видели их (поставьте X в скобках, например [X]): --> - [ ] Я прочитал(а) и следую [Руководство по созданию пулл реквестов](https://docs.spacestation14.com/en/general-development/codebase-info/pull-request-guidelines.html). Я понимаю, что в противном случае мой ПР может быть закрыт по усмотрению мейнтейнера. - [ ] Я добавил скриншоты/видео к этому пулл реквесту, демонстрирующие его изменения в игре, **или** этот пулл реквест не требует демонстрации в игре ## Критические изменения <!-- Перечислите все критические изменения, включая изменения пространства имён, публичных классов/методов/полей, переименования прототипов, и предоставьте инструкции по их исправлению. --> **Чейнджлог** no cl no fun
- Loading branch information
1 parent
946cff8
commit bf5b193
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
Content.Server/ADT/Discord/Adminwho/DiscordAdminInfoSenderSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Content.Server.Discord; | ||
using Robust.Shared.Timing; | ||
using Content.Shared.ADT.CCVar; | ||
using Content.Shared.CCVar; | ||
using Robust.Shared.Configuration; | ||
using System.Text; | ||
using Content.Server.Administration.Managers; | ||
using Robust.Shared.Utility; | ||
using Content.Server.GameTicking; | ||
|
||
namespace Content.Server.ADT.Discord.Adminwho; | ||
|
||
public sealed class DiscordAdminInfoSenderSystem : EntitySystem | ||
{ | ||
[Dependency] private readonly IConfigurationManager _cfg = default!; | ||
[Dependency] private readonly DiscordWebhook _discord = default!; | ||
[Dependency] private readonly IAdminManager _adminMgr = default!; | ||
[Dependency] private readonly IGameTiming _time = default!; | ||
[Dependency] private readonly IEntitySystemManager _entitySystemManager = default!; | ||
|
||
private TimeSpan _nextSendTime = TimeSpan.MinValue; | ||
private readonly TimeSpan _delayInterval = TimeSpan.FromMinutes(15); | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
if (_time.CurTime < _nextSendTime) | ||
return; | ||
|
||
_nextSendTime = _time.CurTime + _delayInterval; | ||
SendAdminInfoToDiscord(); | ||
} | ||
|
||
private async void SendAdminInfoToDiscord() | ||
{ | ||
var webhookUrl = _cfg.GetCVar(ADTDiscordWebhookCCVars.DiscordAdminwhoWebhook); | ||
|
||
if (string.IsNullOrEmpty(webhookUrl)) | ||
return; | ||
|
||
if (await _discord.GetWebhook(webhookUrl) is not { } webhookData) | ||
return; | ||
|
||
var sb = new StringBuilder(); | ||
foreach (var admin in _adminMgr.ActiveAdmins) | ||
{ | ||
var adminData = _adminMgr.GetAdminData(admin)!; | ||
DebugTools.AssertNotNull(adminData); | ||
|
||
if (adminData.Stealth) | ||
continue; | ||
|
||
sb.Append(admin.Name); | ||
if (adminData.Title is { } title) | ||
sb.Append($": [{title}]"); | ||
|
||
sb.AppendLine(); | ||
} | ||
|
||
var serverName = _cfg.GetCVar(CCVars.GameHostName); | ||
|
||
var gameTicker = _entitySystemManager.GetEntitySystem<GameTicker>(); | ||
var round = gameTicker.RunLevel switch | ||
{ | ||
GameRunLevel.PreRoundLobby => gameTicker.RoundId == 0 | ||
? "pre-round lobby after server restart" | ||
: $"pre-round lobby for round {gameTicker.RoundId + 1}", | ||
GameRunLevel.InRound => $"round {gameTicker.RoundId}", | ||
GameRunLevel.PostRound => $"post-round {gameTicker.RoundId}", | ||
_ => throw new ArgumentOutOfRangeException(nameof(gameTicker.RunLevel), | ||
$"{gameTicker.RunLevel} was not matched."), | ||
}; | ||
|
||
var embed = new WebhookEmbed | ||
{ | ||
Title = Loc.GetString("title-embed-webhook-adminwho"), | ||
Description = sb.ToString(), | ||
Color = 0xff0080, | ||
Fields = new List<WebhookEmbedField>(), | ||
Footer = new WebhookEmbedFooter | ||
{ | ||
Text = $"{serverName} ({round})" | ||
}, | ||
}; | ||
|
||
var payload = new WebhookPayload | ||
{ | ||
Embeds = new List<WebhookEmbed> { embed }, | ||
Username = Loc.GetString("username-webhook-adminwho") | ||
}; | ||
|
||
var identifier = webhookData.ToIdentifier(); | ||
await _discord.CreateMessage(identifier, payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Robust.Shared.Configuration; | ||
using Robust.Shared; | ||
|
||
namespace Content.Shared.ADT.CCVar; | ||
|
||
[CVarDefs] | ||
public sealed class ADTDiscordWebhookCCVars : CVars | ||
{ | ||
/// <summary> | ||
/// URL of the Discord webhook which will relay adminwho info to the channel. | ||
/// </summary> | ||
public static readonly CVarDef<string> DiscordAdminwhoWebhook = | ||
CVarDef.Create("discord.adminwho_webhook", string.Empty, CVar.SERVERONLY | CVar.CONFIDENTIAL); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
username-webhook-adminwho = Cerberus AdminWho :з | ||
title-embed-webhook-adminwho = Админы на сервере: |