[feat] Discord hooks

# Conflicts:
#	Content.Server/GameTicking/GameTicker.RoundFlow.cs
This commit is contained in:
rhailrake
2023-04-25 20:11:23 +06:00
committed by Remuchi
parent 37a34cbf2a
commit e52d533b2c
5 changed files with 179 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
using System.Collections.ObjectModel;
using System.Linq;
using Content.Server.Announcements;
using Content.Server.Discord;
@@ -158,7 +159,10 @@ namespace Content.Server.GameTicking
var ev = new PreGameMapLoad(targetMapId, map, loadOpts);
RaiseLocalEvent(ev);
var gridIds = _map.LoadMap(targetMapId, ev.GameMap.MapPath.ToString(), ev.Options);
if (!_map.TryLoad(targetMapId, ev.GameMap.MapPath.ToString(), out var gridIds, ev.Options))
{
return new Collection<EntityUid>();
}
_metaData.SetEntityName(_mapManager.GetMapEntityId(targetMapId), "Station map");
@@ -250,7 +254,7 @@ namespace Content.Server.GameTicking
UpdateLateJoinStatus();
AnnounceRound();
UpdateInfoText();
SendRoundStartedDiscordMessage();
RaiseLocalEvent(new RoundStartedEvent(RoundId)); // WD-EDIT
#if EXCEPTION_TOLERANCE
}
@@ -304,7 +308,6 @@ namespace Content.Server.GameTicking
LobbySong = _robustRandom.Pick(_lobbyMusicCollection.PickFiles).ToString();
ShowRoundEndScoreboard(text);
SendRoundEndDiscordMessage();
}
public void ShowRoundEndScoreboard(string text = "")
@@ -360,7 +363,7 @@ namespace Content.Server.GameTicking
if (TryGetEntity(mind.OriginalOwnedEntity, out var entity))
{
_pvsOverride.AddGlobalOverride(GetNetEntity(entity.Value), recursive: true);
_pvsOverride.AddGlobalOverride(entity.Value);
}
var roles = _roles.MindGetAllRoles(mindId);
@@ -388,38 +391,7 @@ namespace Content.Server.GameTicking
RaiseNetworkEvent(new RoundEndMessageEvent(gamemodeTitle, roundEndText, roundDuration, RoundId,
listOfPlayerInfoFinal.Length, listOfPlayerInfoFinal, LobbySong));
}
private async void SendRoundEndDiscordMessage()
{
try
{
if (_webhookIdentifier == null)
return;
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 };
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);
}
catch (Exception e)
{
Log.Error($"Error while sending discord round end message:\n{e}");
}
RaiseLocalEvent(new RoundEndedEvent(RoundId, roundDuration)); // WD-EDIT
}
public void RestartRound()