Add round end Discord pings, discord webhook API (#19468)

This commit is contained in:
DrSmugleaf
2023-08-24 14:50:07 -07:00
committed by GitHub
parent 7ecdb937ac
commit 913c80db4a
13 changed files with 390 additions and 72 deletions

View File

@@ -3,10 +3,10 @@ using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Content.Server.Administration.Managers;
using Content.Server.Discord;
using Content.Server.GameTicking;
using Content.Server.Players;
using Content.Shared.Administration;
@@ -337,13 +337,13 @@ namespace Content.Server.Administration.Systems
{
Username = username,
AvatarUrl = string.IsNullOrWhiteSpace(_avatarUrl) ? null : _avatarUrl,
Embeds = new List<Embed>
Embeds = new List<WebhookEmbed>
{
new()
{
Description = messages,
Color = color,
Footer = new EmbedFooter
Footer = new WebhookEmbedFooter
{
Text = $"{serverName} ({round})",
IconUrl = string.IsNullOrWhiteSpace(_footerIconUrl) ? null : _footerIconUrl
@@ -469,75 +469,6 @@ namespace Content.Server.Administration.Systems
stringbuilder.Append(message);
return stringbuilder.ToString();
}
// https://discord.com/developers/docs/resources/channel#message-object-message-structure
private struct WebhookPayload
{
[JsonPropertyName("username")]
public string Username { get; set; } = "";
[JsonPropertyName("avatar_url")]
public string? AvatarUrl { get; set; } = "";
[JsonPropertyName("embeds")]
public List<Embed>? Embeds { get; set; } = null;
[JsonPropertyName("allowed_mentions")]
public Dictionary<string, string[]> AllowedMentions { get; set; } =
new()
{
{ "parse", Array.Empty<string>() },
};
public WebhookPayload()
{
}
}
// https://discord.com/developers/docs/resources/channel#embed-object-embed-structure
private struct Embed
{
[JsonPropertyName("description")]
public string Description { get; set; } = "";
[JsonPropertyName("color")]
public int Color { get; set; } = 0;
[JsonPropertyName("footer")]
public EmbedFooter? Footer { get; set; } = null;
public Embed()
{
}
}
// https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
private struct EmbedFooter
{
[JsonPropertyName("text")]
public string Text { get; set; } = "";
[JsonPropertyName("icon_url")]
public string? IconUrl { get; set; }
public EmbedFooter()
{
}
}
// https://discord.com/developers/docs/resources/webhook#webhook-object-webhook-structure
private struct WebhookData
{
[JsonPropertyName("guild_id")]
public string? GuildId { get; set; } = null;
[JsonPropertyName("channel_id")]
public string? ChannelId { get; set; } = null;
public WebhookData()
{
}
}
}
}