diff --git a/Content.Server/GameTicking/GameTicker.CVars.cs b/Content.Server/GameTicking/GameTicker.CVars.cs
index 8bb7f83856..beae71c50b 100644
--- a/Content.Server/GameTicking/GameTicker.CVars.cs
+++ b/Content.Server/GameTicking/GameTicker.CVars.cs
@@ -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;
}
diff --git a/Content.Server/GameTicking/GameTicker.RoundFlow.cs b/Content.Server/GameTicking/GameTicker.RoundFlow.cs
index a20cefb233..aa66ee9372 100644
--- a/Content.Server/GameTicking/GameTicker.RoundFlow.cs
+++ b/Content.Server/GameTicking/GameTicker.RoundFlow.cs
@@ -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
diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs
index 14357e7f26..8cad414a56 100644
--- a/Content.Shared/CCVar/CCVars.cs
+++ b/Content.Shared/CCVar/CCVars.cs
@@ -344,14 +344,14 @@ namespace Content.Shared.CCVar
///
/// URL of the Discord webhook which will relay round restart messages.
///
- public static readonly CVarDef DiscordRoundRestartWebhook =
- CVarDef.Create("discord.round_restart_webhook", string.Empty, CVar.SERVERONLY);
+ public static readonly CVarDef DiscordRoundUpdateWebhook =
+ CVarDef.Create("discord.round_update_webhook", string.Empty, CVar.SERVERONLY);
///
/// Role id for the Discord webhook to ping when the round ends.
///
- public static readonly CVarDef DiscordRoundEndRoleWebhook =
- CVarDef.Create("discord.round_end_role", 0L, CVar.SERVERONLY);
+ public static readonly CVarDef DiscordRoundEndRoleWebhook =
+ CVarDef.Create("discord.round_end_role", string.Empty, CVar.SERVERONLY);
/*
* Suspicion
diff --git a/Resources/Locale/en-US/discord/round-notifications.ftl b/Resources/Locale/en-US/discord/round-notifications.ftl
new file mode 100644
index 0000000000..a9a3d5fb50
--- /dev/null
+++ b/Resources/Locale/en-US/discord/round-notifications.ftl
@@ -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