From d8e30e02e90f50f5460b2f57140ffc94015fd9c3 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sat, 30 Mar 2024 22:50:16 +0100 Subject: [PATCH] fix: remove repetitive webhook snippet and replace it with helper function --- Commands/basebans.cs | 24 ++--------- Commands/basechat.cs | 24 ++--------- Commands/basecommands.cs | 36 +++------------- Commands/basecomms.cs | 54 ++++-------------------- Commands/basevotes.cs | 6 +-- Commands/funcommands.cs | 18 ++------ Commands/playercommands.cs | 84 +++++++------------------------------- 7 files changed, 41 insertions(+), 205 deletions(-) diff --git a/Commands/basebans.cs b/Commands/basebans.cs index 20b411b..c8015a5 100644 --- a/Commands/basebans.cs +++ b/Commands/basebans.cs @@ -31,11 +31,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Database database = new Database(dbConnectionString); @@ -158,11 +154,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; @@ -273,11 +265,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; @@ -379,11 +367,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); diff --git a/Commands/basechat.cs b/Commands/basechat.cs index 6cee028..b4f8fd2 100644 --- a/Commands/basechat.cs +++ b/Commands/basechat.cs @@ -21,11 +21,7 @@ namespace CS2_SimpleAdmin if (caller == null || !caller.IsValid || command.GetCommandString[command.GetCommandString.IndexOf(' ')..].Length == 0) return; string callerName = caller == null ? "Console" : caller.PlayerName; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -54,11 +50,7 @@ namespace CS2_SimpleAdmin byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); string utf8String = Encoding.UTF8.GetString(utf8BytesString); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -109,11 +101,7 @@ namespace CS2_SimpleAdmin byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); string utf8String = Encoding.UTF8.GetString(utf8BytesString); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -129,11 +117,7 @@ namespace CS2_SimpleAdmin byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); string utf8String = Encoding.UTF8.GetString(utf8BytesString); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs index e9aa7a9..e6fc2db 100644 --- a/Commands/basecommands.cs +++ b/Commands/basecommands.cs @@ -122,11 +122,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); string steamid = command.GetArg(1); string name = command.GetArg(2); @@ -171,11 +167,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); string steamid = command.GetArg(1); bool globalDelete = command.GetArg(2).ToLower().Equals("-g"); @@ -285,11 +277,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -397,11 +385,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); if (command.ArgCount >= 2 && command.GetArg(2).Length > 0) reason = command.GetArg(2); @@ -614,11 +598,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -637,11 +617,7 @@ namespace CS2_SimpleAdmin { string callerName = caller == null ? "Console" : caller.PlayerName; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index 1a56e49..1bc65fb 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -32,11 +32,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); int.TryParse(command.GetArg(2), out time); @@ -157,11 +153,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); int time = 0; string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; @@ -269,11 +261,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -387,11 +375,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); int.TryParse(command.GetArg(2), out time); @@ -505,11 +489,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -612,11 +592,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -716,11 +692,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); int.TryParse(command.GetArg(2), out time); @@ -842,11 +814,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -951,11 +919,7 @@ namespace CS2_SimpleAdmin return; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); diff --git a/Commands/basevotes.cs b/Commands/basevotes.cs index 03965c1..2349e7b 100644 --- a/Commands/basevotes.cs +++ b/Commands/basevotes.cs @@ -20,11 +20,7 @@ namespace CS2_SimpleAdmin if (command.GetArg(1) == null || command.GetArg(1).Length < 0 || command.ArgCount < 2) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); diff --git a/Commands/funcommands.cs b/Commands/funcommands.cs index 9f82bf4..eb44aad 100644 --- a/Commands/funcommands.cs +++ b/Commands/funcommands.cs @@ -21,11 +21,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && player.PawnIsAlive && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { @@ -68,11 +64,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { @@ -121,11 +113,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { diff --git a/Commands/playercommands.cs b/Commands/playercommands.cs index a148d6f..d4d9c37 100644 --- a/Commands/playercommands.cs +++ b/Commands/playercommands.cs @@ -23,11 +23,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -98,11 +94,7 @@ namespace CS2_SimpleAdmin } } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { @@ -156,11 +148,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -210,11 +198,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -264,11 +248,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -318,11 +298,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -372,11 +348,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -423,11 +395,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -486,11 +454,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); @@ -545,11 +509,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); @@ -647,11 +607,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -691,11 +647,7 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { @@ -754,11 +706,7 @@ namespace CS2_SimpleAdmin List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command); @@ -810,11 +758,7 @@ namespace CS2_SimpleAdmin List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString])); - } + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, command);