From b2c56d3fa19dfa21e67bbe831d6a2fbbd2cb6892 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sat, 30 Mar 2024 22:41:27 +0100 Subject: [PATCH] feat: add helper function to send logs to discord webhook --- Helper.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Helper.cs b/Helper.cs index 7a38528..d2d9641 100644 --- a/Helper.cs +++ b/Helper.cs @@ -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.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() + ">" : ""; + 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";