Skip to content

Commit

Permalink
Отправка в дис конца раунда
Browse files Browse the repository at this point in the history
  • Loading branch information
Schrodinger71 committed Jan 20, 2025
1 parent 0ba549f commit ba53607
Showing 1 changed file with 81 additions and 14 deletions.
95 changes: 81 additions & 14 deletions Content.Server/GameTicking/GameTicker.RoundFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Robust.Shared.Player;
using Robust.Shared.Random;
using Robust.Shared.Utility;
using System.Text.RegularExpressions;

namespace Content.Server.GameTicking
{
Expand Down Expand Up @@ -344,14 +345,14 @@ public void EndRound(string text = "")
Log.Error($"Error while showing round end scoreboard: {e}");
}

try
{
SendRoundEndDiscordMessage();
}
catch (Exception e)
{
Log.Error($"Error while sending round end Discord message: {e}");
}
// try
// {
// SendRoundEndDiscordMessage();
// }
// catch (Exception e)
// {
// Log.Error($"Error while sending round end Discord message: {e}");
// }
}

public void ShowRoundEndScoreboard(string text = "")
Expand Down Expand Up @@ -453,21 +454,87 @@ public void ShowRoundEndScoreboard(string text = "")

_replayRoundPlayerInfo = listOfPlayerInfoFinal;
_replayRoundText = roundEndText;
var roundEndSummary = GenerateRoundEndSummary(gamemodeTitle, roundEndText, listOfPlayerInfoFinal); // ADT-Tweak
SendRoundEndDiscordMessage(roundEndSummary); // ADT-Tweak
}
// ADT-Start: Отправка в дис UPDATE
private string ConvertBBCodeToMarkdown(string text)
{
text = Regex.Replace(text, @"\[.*?\]", "**");

return text;
}
// Метод для разбивки сообщения на части
private List<string> SplitMessage(string message, int maxLength)
{
var parts = new List<string>();
for (int i = 0; i < message.Length; i += maxLength)
{
// Берем подстроку длиной maxLength или оставшуюся часть сообщения
var part = message.Substring(i, Math.Min(maxLength, message.Length - i));
parts.Add(part);
}
return parts;
}
private string GenerateRoundEndSummary(string gamemodeTitle, string roundEndText, RoundEndMessageEvent.RoundEndPlayerInfo[] playerInfoArray)
{
var roundEndTextMarkdown = ConvertBBCodeToMarkdown(roundEndText);

private async void SendRoundEndDiscordMessage()

var contentt = $"**Режим**: {gamemodeTitle}\n";
var payload = new WebhookPayload { Content = contentt };
payload.AllowedMentions.AllowRoleMentions();
SendWebHOOkDiscrodInfoENDRound(payload);

if (!string.IsNullOrWhiteSpace(roundEndTextMarkdown))
{
var content = $"**Информация**: {roundEndTextMarkdown}\n";
var payloadd = new WebhookPayload { Content = content };
payloadd.AllowedMentions.AllowRoleMentions();
SendWebHOOkDiscrodInfoENDRound(payloadd);
}

var groupedPlayers = playerInfoArray
.GroupBy(p => new { p.PlayerOOCName, p.PlayerICName })
.Select(g => new
{
PlayerOOCName = g.Key.PlayerOOCName,
PlayerICName = g.Key.PlayerICName,
Roles = string.Join(", ", g.Select(p => p.Role).Distinct())
})
.ToList();

int totalPlayers = groupedPlayers.Count;
var stringBuilder = new System.Text.StringBuilder();
stringBuilder.AppendLine($"**Всего было игроков**: {totalPlayers}\n");
stringBuilder.AppendLine($"**Игроки**:\n");

foreach (var playerInfo in groupedPlayers)
{
stringBuilder.AppendLine($"*{playerInfo.PlayerOOCName}* '**{playerInfo.PlayerICName}**' в роли: {Loc.GetString(playerInfo.Roles)}");
}

return stringBuilder.ToString();
}
private async void SendWebHOOkDiscrodInfoENDRound(WebhookPayload payload)
{
if (_webhookIdentifier == null)
return;
payload.AllowedMentions.AllowRoleMentions();
await _discord.CreateMessage(_webhookIdentifier.Value, payload);
}
// ADT-End
private async void SendRoundEndDiscordMessage(string roundEndSummary) // ADT-Tweak
{
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 content = $"**Раунд {RoundId} завершен!**\n" +
$"**Продолжительность**: {Math.Truncate(duration.TotalHours)} часов {duration.Minutes} минут {duration.Seconds} секунд\n" +
$"{roundEndSummary}"; // ADT-Tweak
var payload = new WebhookPayload { Content = content };

await _discord.CreateMessage(_webhookIdentifier.Value, payload);
Expand Down

0 comments on commit ba53607

Please sign in to comment.