Enrich discord round notifications (#19502)
This commit is contained in:
@@ -31,7 +31,7 @@ namespace Content.Server.GameTicking
|
||||
public string? ServerName { get; private set; }
|
||||
|
||||
[ViewVariables]
|
||||
private long? DiscordRoundEndRole { get; set; }
|
||||
private string? DiscordRoundEndRole { get; set; }
|
||||
|
||||
private WebhookIdentifier? _webhookIdentifier;
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace Content.Server.GameTicking
|
||||
// TODO why tf is the server name on admin logs
|
||||
ServerName = value;
|
||||
}, true);
|
||||
_configurationManager.OnValueChanged(CCVars.DiscordRoundRestartWebhook, value =>
|
||||
_configurationManager.OnValueChanged(CCVars.DiscordRoundUpdateWebhook, value =>
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
@@ -76,7 +76,7 @@ namespace Content.Server.GameTicking
|
||||
{
|
||||
DiscordRoundEndRole = value;
|
||||
|
||||
if (value == 0)
|
||||
if (value == string.Empty)
|
||||
{
|
||||
DiscordRoundEndRole = null;
|
||||
}
|
||||
|
||||
@@ -252,6 +252,7 @@ namespace Content.Server.GameTicking
|
||||
UpdateLateJoinStatus();
|
||||
AnnounceRound();
|
||||
UpdateInfoText();
|
||||
SendRoundStartedDiscordMessage();
|
||||
|
||||
#if EXCEPTION_TOLERANCE
|
||||
}
|
||||
@@ -395,16 +396,21 @@ namespace Content.Server.GameTicking
|
||||
if (_webhookIdentifier == null)
|
||||
return;
|
||||
|
||||
var content = "The round has ended.";
|
||||
if (DiscordRoundEndRole != null)
|
||||
content += $"\n\n<@&{DiscordRoundEndRole}>, the server will reboot shortly!";
|
||||
var duration = RoundDuration();
|
||||
var content = Loc.GetString("discord-round-notifications-end",
|
||||
("id", RoundId),
|
||||
("hours", Math.Truncate(duration.TotalHours)),
|
||||
("minutes", duration.Minutes),
|
||||
("seconds", duration.Seconds));
|
||||
var payload = new WebhookPayload { Content = content };
|
||||
|
||||
var payload = new WebhookPayload
|
||||
{
|
||||
Content = content,
|
||||
Username = ServerName,
|
||||
};
|
||||
await _discord.CreateMessage(_webhookIdentifier.Value, payload);
|
||||
|
||||
if (DiscordRoundEndRole == null)
|
||||
return;
|
||||
|
||||
content = Loc.GetString("discord-round-notifications-end-ping", ("roleId", DiscordRoundEndRole));
|
||||
payload = new WebhookPayload { Content = content };
|
||||
payload.AllowedMentions.AllowRoleMentions();
|
||||
|
||||
await _discord.CreateMessage(_webhookIdentifier.Value, payload);
|
||||
@@ -439,6 +445,7 @@ namespace Content.Server.GameTicking
|
||||
RandomizeLobbyBackground();
|
||||
ResettingCleanup();
|
||||
IncrementRoundNumber();
|
||||
SendRoundStartingDiscordMessage();
|
||||
|
||||
if (!LobbyEnabled)
|
||||
{
|
||||
@@ -456,8 +463,6 @@ namespace Content.Server.GameTicking
|
||||
|
||||
ReqWindowAttentionAll();
|
||||
}
|
||||
|
||||
SendRoundStartingDiscordMessage();
|
||||
}
|
||||
|
||||
private async void SendRoundStartingDiscordMessage()
|
||||
@@ -467,13 +472,9 @@ namespace Content.Server.GameTicking
|
||||
if (_webhookIdentifier == null)
|
||||
return;
|
||||
|
||||
var content = "New round starting!";
|
||||
var content = Loc.GetString("discord-round-notifications-new");
|
||||
|
||||
var payload = new WebhookPayload
|
||||
{
|
||||
Content = content,
|
||||
Username = ServerName,
|
||||
};
|
||||
var payload = new WebhookPayload { Content = content };
|
||||
|
||||
await _discord.CreateMessage(_webhookIdentifier.Value, payload);
|
||||
}
|
||||
@@ -609,6 +610,26 @@ namespace Content.Server.GameTicking
|
||||
if (proto.Sound != null)
|
||||
SoundSystem.Play(proto.Sound.GetSound(), Filter.Broadcast());
|
||||
}
|
||||
|
||||
private async void SendRoundStartedDiscordMessage()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_webhookIdentifier == null)
|
||||
return;
|
||||
|
||||
var mapName = _gameMapManager.GetSelectedMap()?.MapName ?? Loc.GetString("discord-round-notifications-unknown-map");
|
||||
var content = Loc.GetString("discord-round-notifications-started", ("id", RoundId), ("map", mapName));
|
||||
|
||||
var payload = new WebhookPayload { Content = content };
|
||||
|
||||
await _discord.CreateMessage(_webhookIdentifier.Value, payload);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error($"Error while sending discord round start message:\n{e}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum GameRunLevel
|
||||
|
||||
@@ -344,14 +344,14 @@ namespace Content.Shared.CCVar
|
||||
/// <summary>
|
||||
/// URL of the Discord webhook which will relay round restart messages.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<string> DiscordRoundRestartWebhook =
|
||||
CVarDef.Create("discord.round_restart_webhook", string.Empty, CVar.SERVERONLY);
|
||||
public static readonly CVarDef<string> DiscordRoundUpdateWebhook =
|
||||
CVarDef.Create("discord.round_update_webhook", string.Empty, CVar.SERVERONLY);
|
||||
|
||||
/// <summary>
|
||||
/// Role id for the Discord webhook to ping when the round ends.
|
||||
/// </summary>
|
||||
public static readonly CVarDef<long> DiscordRoundEndRoleWebhook =
|
||||
CVarDef.Create("discord.round_end_role", 0L, CVar.SERVERONLY);
|
||||
public static readonly CVarDef<string> DiscordRoundEndRoleWebhook =
|
||||
CVarDef.Create("discord.round_end_role", string.Empty, CVar.SERVERONLY);
|
||||
|
||||
/*
|
||||
* Suspicion
|
||||
|
||||
5
Resources/Locale/en-US/discord/round-notifications.ftl
Normal file
5
Resources/Locale/en-US/discord/round-notifications.ftl
Normal file
@@ -0,0 +1,5 @@
|
||||
discord-round-notifications-new = A new round is starting!
|
||||
discord-round-notifications-started = Round #{$id} on map "{$map}" started.
|
||||
discord-round-notifications-end = Round #{$id} has ended. It lasted for {$hours} hours, {$minutes} minutes, and {$seconds} seconds.
|
||||
discord-round-notifications-end-ping = <@&{$roleId}>, the server will reboot shortly!
|
||||
discord-round-notifications-unknown-map = Unknown
|
||||
Reference in New Issue
Block a user