feat: add helper function to send logs to discord webhook

This commit is contained in:
Dollan
2024-03-30 22:41:27 +01:00
parent 5609748d19
commit b2c56d3fa1

View File

@@ -7,6 +7,8 @@ using CounterStrikeSharp.API.Modules.Entities;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Menu;
using Discord;
using Discord.Webhook;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using System.Reflection;
using System.Runtime.CompilerServices;
@@ -196,6 +198,16 @@ namespace CS2_SimpleAdmin
return new List<Embed> { embed.Build() };
}
public static void SendDiscordLogMessage(CCSPlayerController? caller, CommandInfo command, DiscordWebhookClient? discordWebhookClientLog, IStringLocalizer? localizer)
{
if (discordWebhookClientLog != null && localizer != null)
{
string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : "<https://steamcommunity.com/profiles/0>";
string callerName = caller != null ? caller.PlayerName : "Console";
discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
}
public static string GenerateMessageDiscord(string message)
{
string? hostname = ConVar.Find("hostname")!.StringValue ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";