mirror of
https://github.com/JogmansonReal/Radicade.git
synced 2026-10-25 23:18:56 -07:00
Radicade Public Code
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace RadicadeServer.Discord.Webhooks;
|
||||
|
||||
public static class WebhookImages
|
||||
{
|
||||
public const string BanAppeal = "https://cdn.radicade.app/BanAppeal.png";
|
||||
public const string AdminActivity = "https://cdn.radicade.app/AuditLogs.png";
|
||||
public const string InGameBan = "https://cdn.radicade.app/BanRecords.png";
|
||||
public const string BugReport = "https://cdn.radicade.app/BugReport.png";
|
||||
public const string ClubReport = "https://cdn.radicade.app/ClubReport.png";
|
||||
public const string PlayerReport = "https://cdn.radicade.app/PlayerReport.png";
|
||||
public const string RoomReport = "https://cdn.radicade.app/RoomReport.png";
|
||||
public const string EventReport = "https://cdn.radicade.app/EventReport.png";
|
||||
public const string InventionReport = "https://cdn.radicade.app/InventionReport.png";
|
||||
|
||||
public static string? ForReport(string? reportType) => reportType?.Trim().ToLowerInvariant() switch
|
||||
{
|
||||
"club" => ClubReport,
|
||||
"player" => PlayerReport,
|
||||
"room" => RoomReport,
|
||||
"event" => EventReport,
|
||||
"invention" => InventionReport,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public static class WebhookConfig
|
||||
{
|
||||
private const string ConfigurationPrefix = "Radicade:Discord:Webhooks:";
|
||||
|
||||
public static string BanAppealsUrl { get; private set; } = "";
|
||||
public static string AdminActivityUrl { get; private set; } = "";
|
||||
public static string InGameBansUrl { get; private set; } = "";
|
||||
public static string ReportsUrl { get; private set; } = "";
|
||||
public static string GeneralActivityUrl { get; private set; } = "";
|
||||
|
||||
public static void Load(IConfiguration configuration, string contentRootPath)
|
||||
{
|
||||
var fileValues = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
|
||||
var filePath = Path.Combine(contentRootPath, "Discord", "Webhooks", "webhooks.json");
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
fileValues = JsonSerializer.Deserialize<Dictionary<string, string?>>(File.ReadAllText(filePath))
|
||||
?? fileValues;
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
BanAppealsUrl = ReadUrl("BanAppeals");
|
||||
AdminActivityUrl = ReadUrl("AdminActivity");
|
||||
InGameBansUrl = ReadUrl("InGameBans");
|
||||
ReportsUrl = ReadUrl("Reports");
|
||||
GeneralActivityUrl = ReadUrl("GeneralActivity");
|
||||
|
||||
string ReadUrl(string name)
|
||||
{
|
||||
var configuredValue = configuration[ConfigurationPrefix + name];
|
||||
var value = configuredValue ?? (fileValues.TryGetValue(name, out var fileValue) ? fileValue : "");
|
||||
if (string.IsNullOrWhiteSpace(value)) return "";
|
||||
|
||||
value = value.Trim();
|
||||
if (Uri.TryCreate(value, UriKind.Absolute, out var uri)
|
||||
&& uri.Scheme == Uri.UriSchemeHttps
|
||||
&& string.Equals(uri.Host, "discord.com", StringComparison.OrdinalIgnoreCase)
|
||||
&& uri.AbsolutePath.StartsWith("/api/webhooks/", StringComparison.Ordinal))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user