From b2c56d3fa19dfa21e67bbe831d6a2fbbd2cb6892 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sat, 30 Mar 2024 22:41:27 +0100 Subject: [PATCH 1/9] 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"; From d8e30e02e90f50f5460b2f57140ffc94015fd9c3 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sat, 30 Mar 2024 22:50:16 +0100 Subject: [PATCH 2/9] 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); From 8df1e70d5a1b6cc5e5f0e20e8de09af6e187cf41 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sun, 31 Mar 2024 01:06:42 +0100 Subject: [PATCH 3/9] feat: add penalty embed helper function --- Helper.cs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Helper.cs b/Helper.cs index d2d9641..fd67e3b 100644 --- a/Helper.cs +++ b/Helper.cs @@ -208,6 +208,68 @@ namespace CS2_SimpleAdmin } } + public enum PenaltyType + { + Ban, + Mute, + Gag, + Silence, + } + + + public static string ConvertMinutesToTime(int minutes) + { + TimeSpan time = TimeSpan.FromMinutes(minutes); + + return time.Days > 0 ? $"{time.Days}d {time.Hours}h {time.Minutes}m" : time.Hours > 0 ? $"{time.Hours}h {time.Minutes}m" : $"{time.Minutes}m"; + } + + public static void SendDiscordPenaltyMessage(CCSPlayerController? caller, CCSPlayerController? target, string reason, int duration, PenaltyType penalty, DiscordWebhookClient? discordWebhookClientPenalty, IStringLocalizer? localizer) + { + if (discordWebhookClientPenalty != null && localizer != null) + { + string callercommunityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + string targetcommunityUrl = target != null ? "<" + new SteamID(target.SteamID).ToCommunityUrl().ToString() + ">" : ""; + string callerName = caller != null ? caller.PlayerName : "Console"; + string targetName = target != null ? target.PlayerName : "Unknown"; + string targetSteamId = target != null ? new SteamID(target.SteamID).SteamId2.ToString() : "Unknown"; + + string[] fieldNames = ["Player:", "SteamID:", "Duration:", "Reason:", "Admin:"]; + string[] fieldValues = [$"[{targetName}]({targetcommunityUrl})", targetSteamId, ConvertMinutesToTime(duration), reason, $"[{callerName}]({callercommunityUrl})"]; + bool[] inlineFlags = [true, true, true, false, false]; + + var embed = new EmbedBuilder + { + Title = penalty switch + { + PenaltyType.Ban => "Ban registrered", + PenaltyType.Mute => "Mute registrered", + PenaltyType.Gag => "Gag registrered", + PenaltyType.Silence => "Silence registrered", + _ => "Unknown penalty registrered", + }, + + Color = penalty switch + { + PenaltyType.Ban => Color.Red, + PenaltyType.Mute => Color.Blue, + PenaltyType.Gag => Color.Gold, + PenaltyType.Silence => Color.Green, + _ => Color.Default, + }, + + Timestamp = DateTimeOffset.UtcNow + }; + + for (int i = 0; i < fieldNames.Length; i++) + { + embed.AddField(fieldNames[i], fieldValues[i], inlineFlags[i]); + } + + discordWebhookClientPenalty.SendMessageAsync(embeds: [embed.Build()]); + } + } + public static string GenerateMessageDiscord(string message) { string? hostname = ConVar.Find("hostname")!.StringValue ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; From a377871951605f6ee75b1cb83ee59a557a3eb1f0 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sun, 31 Mar 2024 01:23:15 +0100 Subject: [PATCH 4/9] fix: if punishment is 0 ie permanent show permanent --- Helper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Helper.cs b/Helper.cs index fd67e3b..1810194 100644 --- a/Helper.cs +++ b/Helper.cs @@ -234,8 +234,10 @@ namespace CS2_SimpleAdmin string targetName = target != null ? target.PlayerName : "Unknown"; string targetSteamId = target != null ? new SteamID(target.SteamID).SteamId2.ToString() : "Unknown"; + string time = duration != 0 ? ConvertMinutesToTime(duration) : "Permanent"; + string[] fieldNames = ["Player:", "SteamID:", "Duration:", "Reason:", "Admin:"]; - string[] fieldValues = [$"[{targetName}]({targetcommunityUrl})", targetSteamId, ConvertMinutesToTime(duration), reason, $"[{callerName}]({callercommunityUrl})"]; + string[] fieldValues = [$"[{targetName}]({targetcommunityUrl})", targetSteamId, time, reason, $"[{callerName}]({callercommunityUrl})"]; bool[] inlineFlags = [true, true, true, false, false]; var embed = new EmbedBuilder From 8f80e1310084ffe4600fce0bbfa628f6c6462443 Mon Sep 17 00:00:00 2001 From: Dollan Date: Sun, 31 Mar 2024 01:23:35 +0100 Subject: [PATCH 5/9] feat: implement penaltylog on gag --- Commands/basecomms.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index 1bc65fb..834e0be 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -34,6 +34,8 @@ namespace CS2_SimpleAdmin Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + + int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -47,6 +49,7 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { Gag(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager); + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _discordWebhookClientPenalty, _localizer); } }); } From ba2bf90340be041b3b2f797c171856d07f260ffe Mon Sep 17 00:00:00 2001 From: Dollan Date: Mon, 1 Apr 2024 18:30:03 +0200 Subject: [PATCH 6/9] fix: add hostname as embed description --- Helper.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Helper.cs b/Helper.cs index 1810194..efae9ed 100644 --- a/Helper.cs +++ b/Helper.cs @@ -240,6 +240,8 @@ namespace CS2_SimpleAdmin string[] fieldValues = [$"[{targetName}]({targetcommunityUrl})", targetSteamId, time, reason, $"[{callerName}]({callercommunityUrl})"]; bool[] inlineFlags = [true, true, true, false, false]; + string? hostname = ConVar.Find("hostname")!.StringValue ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + var embed = new EmbedBuilder { Title = penalty switch @@ -260,6 +262,8 @@ namespace CS2_SimpleAdmin _ => Color.Default, }, + Description = $"{hostname}", + Timestamp = DateTimeOffset.UtcNow }; From 052cea5ce325bd0fd00bbb85aec425a72b605557 Mon Sep 17 00:00:00 2001 From: Dollan Date: Mon, 1 Apr 2024 18:30:45 +0200 Subject: [PATCH 7/9] feat: embed is now integrated with all penalties --- Commands/basebans.cs | 11 ++++++++++- Commands/basecomms.cs | 3 ++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Commands/basebans.cs b/Commands/basebans.cs index c8015a5..cecb9eb 100644 --- a/Commands/basebans.cs +++ b/Commands/basebans.cs @@ -133,6 +133,7 @@ namespace CS2_SimpleAdmin } } } + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); } [ConsoleCommand("css_addban")] @@ -234,6 +235,7 @@ namespace CS2_SimpleAdmin } } } + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); } Task.Run(async () => @@ -340,8 +342,15 @@ namespace CS2_SimpleAdmin } if (player.UserId.HasValue) - AddTimer(Config.KickTime, () => Helper.KickPlayer(player.UserId.Value, "Banned"), CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + { + AddTimer(Config.KickTime, () => + { + Helper.KickPlayer(player.UserId.Value, "Banned"); + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + + } } + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); } Task.Run(async () => diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index 834e0be..d42355d 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -86,7 +86,6 @@ namespace CS2_SimpleAdmin Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time); - if (time == 0) { if (!player!.IsBot && !player.IsHLTV) @@ -393,6 +392,7 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { Mute(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager); + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _discordWebhookClientPenalty, _localizer); } }); } @@ -709,6 +709,7 @@ namespace CS2_SimpleAdmin { if (caller!.CanTarget(player)) { + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Silence, _discordWebhookClientPenalty, _localizer); Silence(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager); } }); From 89d27e1bd388e1702f06d26a5efd34ac40acf635 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:42:16 +0200 Subject: [PATCH 8/9] Added translation - Minor changes - Version bump - Added translation --- CS2-SimpleAdmin.cs | 2 +- Commands/basebans.cs | 61 +++++++++------- Commands/basechat.cs | 7 +- Commands/basecommands.cs | 82 +++++++++++---------- Commands/basecomms.cs | 105 ++++++++++++++------------ Commands/basevotes.cs | 2 - Commands/funcommands.cs | 13 ++-- Commands/playercommands.cs | 146 +++++++++++++++++++++---------------- Events.cs | 13 ++-- Helper.cs | 26 ++++--- lang/ar.json | 13 ++++ lang/en.json | 13 ++++ lang/es.json | 13 ++++ lang/fa.json | 13 ++++ lang/fr.json | 13 ++++ lang/lv.json | 13 ++++ lang/pl.json | 13 ++++ lang/pt-BR.json | 13 ++++ lang/ru.json | 13 ++++ lang/tr.json | 13 ++++ lang/zh-Hans.json | 13 ++++ 21 files changed, 392 insertions(+), 208 deletions(-) diff --git a/CS2-SimpleAdmin.cs b/CS2-SimpleAdmin.cs index 2875f68..402517d 100644 --- a/CS2-SimpleAdmin.cs +++ b/CS2-SimpleAdmin.cs @@ -38,7 +38,7 @@ public partial class CS2_SimpleAdmin : BasePlugin, IPluginConfig "CS2-SimpleAdmin"; public override string ModuleDescription => "Simple admin plugin for Counter-Strike 2 :)"; public override string ModuleAuthor => "daffyy & Dliix66"; - public override string ModuleVersion => "1.3.7a"; + public override string ModuleVersion => "1.3.8a"; public CS2_SimpleAdminConfig Config { get; set; } = new(); diff --git a/Commands/basebans.cs b/Commands/basebans.cs index cecb9eb..5b236fb 100644 --- a/Commands/basebans.cs +++ b/Commands/basebans.cs @@ -4,7 +4,6 @@ using CounterStrikeSharp.API.Core.Translations; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; -using CounterStrikeSharp.API.Modules.Entities; using System.Text; namespace CS2_SimpleAdmin @@ -20,7 +19,7 @@ namespace CS2_SimpleAdmin if (command.ArgCount < 2) return; - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; TargetResult? targets = GetTarget(command); if (targets == null) return; @@ -31,10 +30,7 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - Database database = new Database(dbConnectionString); - + Database database = new(dbConnectionString); BanManager _banManager = new(database, Config); int.TryParse(command.GetArg(2), out int time); @@ -46,12 +42,12 @@ namespace CS2_SimpleAdmin { if (caller!.CanTarget(player)) { - Ban(caller, player, time, reason, callerName, _banManager); + Ban(caller, player, time, reason, callerName, _banManager, command); } }); } - internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, BanManager? banManager = null) + internal void Ban(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, BanManager? banManager = null, CommandInfo? command = null) { if (_database == null) return; @@ -76,8 +72,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, $"css_ban {player.SteamID} {time} {reason}"); - Task.Run(async () => { banManager ??= new BanManager(_database, Config); @@ -133,6 +127,12 @@ namespace CS2_SimpleAdmin } } } + + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); } @@ -155,12 +155,9 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; - - Database database = new Database(dbConnectionString); + string reason = _localizer?["sa_unknown"] ?? "Unknown"; + Database database = new(dbConnectionString); BanManager _banManager = new(database, Config); int.TryParse(command.GetArg(2), out int time); @@ -175,8 +172,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, command); - List matches = Helper.GetPlayerFromSteamid64(steamid); if (matches.Count == 1) { @@ -235,6 +230,7 @@ namespace CS2_SimpleAdmin } } } + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); } @@ -244,7 +240,14 @@ namespace CS2_SimpleAdmin await _banManager.AddBanBySteamid(steamid, adminInfo, reason, time); }); - command.ReplyToCommand($"Banned player with steamid {steamid}."); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } + //Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); + + command?.ReplyToCommand($"Banned player with steamid {steamid}."); } [ConsoleCommand("css_banip")] @@ -269,7 +272,7 @@ namespace CS2_SimpleAdmin Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; PlayerInfo adminInfo = new PlayerInfo { @@ -278,8 +281,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, command); - int.TryParse(command.GetArg(2), out int time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -347,7 +348,6 @@ namespace CS2_SimpleAdmin { Helper.KickPlayer(player.UserId.Value, "Banned"); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); - } } Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Ban, _discordWebhookClientPenalty, _localizer); @@ -359,7 +359,13 @@ namespace CS2_SimpleAdmin await _banManager.AddBanByIp(ipAddress, adminInfo, reason, time); }); - command.ReplyToCommand($"Banned player with IP address {ipAddress}."); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } + + command?.ReplyToCommand($"Banned player with IP address {ipAddress}."); } [ConsoleCommand("css_unban")] @@ -376,15 +382,14 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - Helper.LogCommand(caller, command); - string pattern = command.GetArg(1); - BanManager _banManager = new BanManager(_database, Config); + BanManager _banManager = new(_database, Config); Task.Run(async () => await _banManager.UnbanPlayer(pattern)); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + command.ReplyToCommand($"Unbanned player with pattern {pattern}."); } } diff --git a/Commands/basechat.cs b/Commands/basechat.cs index b4f8fd2..b347df9 100644 --- a/Commands/basechat.cs +++ b/Commands/basechat.cs @@ -4,7 +4,6 @@ using CounterStrikeSharp.API.Core.Translations; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; -using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Utils; using System.Text; @@ -22,7 +21,6 @@ namespace CS2_SimpleAdmin string callerName = caller == null ? "Console" : caller.PlayerName; Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); byte[] utf8BytesString = Encoding.UTF8.GetBytes(command.GetCommandString[command.GetCommandString.IndexOf(' ')..]); @@ -51,7 +49,6 @@ namespace CS2_SimpleAdmin string utf8String = Encoding.UTF8.GetString(utf8BytesString); Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); foreach (CCSPlayerController _player in Helper.GetValidPlayers()) @@ -76,7 +73,7 @@ namespace CS2_SimpleAdmin if (targets == null) return; List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); - Helper.LogCommand(caller, command); + //Helper.LogCommand(caller, command); int range = command.GetArg(0).Length + command.GetArg(1).Length + 2; string message = command.GetCommandString[range..]; @@ -102,7 +99,6 @@ namespace CS2_SimpleAdmin string utf8String = Encoding.UTF8.GetString(utf8BytesString); Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); Helper.PrintToCenterAll(StringExtensions.ReplaceColorTags(utf8String)); @@ -118,7 +114,6 @@ namespace CS2_SimpleAdmin string utf8String = Encoding.UTF8.GetString(utf8BytesString); Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); VirtualFunctions.ClientPrintAll( diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs index e6fc2db..e8e6aa8 100644 --- a/Commands/basecommands.cs +++ b/Commands/basecommands.cs @@ -122,8 +122,6 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - string steamid = command.GetArg(1); string name = command.GetArg(2); string flags = command.GetArg(3); @@ -133,7 +131,7 @@ namespace CS2_SimpleAdmin int time = 0; int.TryParse(command.GetArg(5), out time); - AddAdmin(caller, steamid, name, flags, immunity, time, globalAdmin); + AddAdmin(caller, steamid, name, flags, immunity, time, globalAdmin, command); } public void AddAdmin(CCSPlayerController? caller, string steamid, string name, string flags, int immunity, int time = 0, bool globalAdmin = false, CommandInfo? command = null) @@ -142,6 +140,8 @@ namespace CS2_SimpleAdmin AdminSQLManager _adminManager = new(_database); _ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin); + if (command != null) + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, $"css_addadmin {steamid} {name} {flags} {immunity} {time}"); string msg = $"Added '{flags}' flags to '{name}' ({steamid})"; @@ -167,12 +167,10 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - string steamid = command.GetArg(1); bool globalDelete = command.GetArg(2).ToLower().Equals("-g"); - RemoveAdmin(caller, steamid, globalDelete); + RemoveAdmin(caller, steamid, globalDelete, command); } public void RemoveAdmin(CCSPlayerController? caller, string steamid, bool globalDelete = false, CommandInfo? command = null) @@ -195,6 +193,8 @@ namespace CS2_SimpleAdmin } }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + if (command != null) + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, $"css_deladmin {steamid}"); string msg = $"Removed flags from '{steamid}'"; @@ -277,7 +277,8 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + //Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.SteamID.ToString().Length == 17 && !player.IsHLTV).ToList(); @@ -371,7 +372,7 @@ namespace CS2_SimpleAdmin public void OnKickCommand(CCSPlayerController? caller, CommandInfo command) { string callerName = caller == null ? "Console" : caller.PlayerName; - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; TargetResult? targets = GetTarget(command); @@ -385,8 +386,6 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - if (command.ArgCount >= 2 && command.GetArg(2).Length > 0) reason = command.GetArg(2); @@ -397,12 +396,12 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - Kick(caller, player, reason, callerName); + Kick(caller, player, reason, callerName, command); } }); } - public void Kick(CCSPlayerController? caller, CCSPlayerController player, string reason = "Unknown", string? callerName = null) + public void Kick(CCSPlayerController? caller, CCSPlayerController player, string reason = "Unknown", string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; if (player.PawnIsAlive) @@ -410,8 +409,10 @@ namespace CS2_SimpleAdmin player.Pawn.Value!.Freeze(); } - reason = reason ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + reason = reason ?? _localizer?["sa_unknown"] ?? "Unknown"; + if (command != null) + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); Helper.LogCommand(caller, $"css_kick {player.PlayerName} {reason}"); if (string.IsNullOrEmpty(reason) == false) @@ -472,16 +473,14 @@ namespace CS2_SimpleAdmin _command = $"ds_workshop_changelevel {map.Replace("ws:", "")}"; } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - string commandName = command?.GetCommandString ?? "css_changemap"; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); - } - if (command is not null) - Helper.LogCommand(caller, command); + //if (_discordWebhookClientLog != null && _localizer != null) + //{ + // string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + // string commandName = command?.GetCommandString ?? "css_changemap"; + // _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); + //} - AddTimer(2.0f, () => + AddTimer(3.0f, () => { Server.ExecuteCommand(_command); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); @@ -499,6 +498,11 @@ namespace CS2_SimpleAdmin Server.PrintToConsole(msg); return; } + + AddTimer(3.0f, () => + { + Server.ExecuteCommand($"changelevel {map}"); + }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) @@ -514,12 +518,10 @@ namespace CS2_SimpleAdmin } } - if (!map.StartsWith("ws:")) + if (command != null) { - AddTimer(2.0f, () => - { - Server.ExecuteCommand($"changelevel {map}"); - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); } } @@ -563,19 +565,25 @@ namespace CS2_SimpleAdmin } } - if (_discordWebhookClientLog != null && _localizer != null) - { - string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - string commandName = command?.GetCommandString ?? "css_changewsmap"; - _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); - } - if (command is not null) - Helper.LogCommand(caller, command); + //if (_discordWebhookClientLog != null && _localizer != null) + //{ + // string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; + // string commandName = command?.GetCommandString ?? "css_changewsmap"; + // _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); + //} + //if (command is not null) + // Helper.LogCommand(caller, command); - AddTimer(2.0f, () => + AddTimer(3.0f, () => { Server.ExecuteCommand(_command); }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); + + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + } } [ConsoleCommand("css_cvar", "Change a cvar.")] @@ -599,7 +607,6 @@ namespace CS2_SimpleAdmin } Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); var value = command.GetArg(2); @@ -618,7 +625,6 @@ namespace CS2_SimpleAdmin string callerName = caller == null ? "Console" : caller.PlayerName; Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); Server.ExecuteCommand(command.ArgString); diff --git a/Commands/basecomms.cs b/Commands/basecomms.cs index d42355d..173b1db 100644 --- a/Commands/basecomms.cs +++ b/Commands/basecomms.cs @@ -5,7 +5,6 @@ using CounterStrikeSharp.API.Core.Translations; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; -using CounterStrikeSharp.API.Modules.Entities; using System.Text; namespace CS2_SimpleAdmin @@ -21,7 +20,7 @@ namespace CS2_SimpleAdmin string callerName = caller == null ? "Console" : caller.PlayerName; int time = 0; - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; TargetResult? targets = GetTarget(command); if (targets == null) return; @@ -32,10 +31,6 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -48,13 +43,12 @@ namespace CS2_SimpleAdmin { if (caller!.CanTarget(player)) { - Gag(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager); - Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _discordWebhookClientPenalty, _localizer); + Gag(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager, command); } }); } - internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, PlayerPenaltyManager? playerPenaltyManager = null) + internal void Gag(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, PlayerPenaltyManager? playerPenaltyManager = null, CommandInfo? command = null) { if (_database == null) return; callerName ??= caller == null ? "Console" : caller.PlayerName; @@ -75,8 +69,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, $"css_gag {player?.SteamID} {time} {reason}"); - Task.Run(async () => { await muteManager.MutePlayer(playerInfo, adminInfo, reason, time); @@ -132,6 +124,13 @@ namespace CS2_SimpleAdmin } } } + + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _discordWebhookClientPenalty, _localizer); + Helper.LogCommand(caller, command); + } } [ConsoleCommand("css_addgag")] @@ -155,10 +154,8 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - int time = 0; - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; MuteManager _muteManager = new(_database); PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); @@ -175,8 +172,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, command); - List matches = Helper.GetPlayerFromSteamid64(steamid); if (matches.Count == 1) { @@ -237,6 +232,8 @@ namespace CS2_SimpleAdmin playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Gag, DateTime.Now.AddMinutes(time), time); } + + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Gag, _discordWebhookClientPenalty, _localizer); } Task.Run(async () => @@ -244,7 +241,13 @@ namespace CS2_SimpleAdmin await _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 0); }); - command.ReplyToCommand($"Gagged player with steamid {steamid}."); + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + } + + command?.ReplyToCommand($"Gagged player with steamid {steamid}."); } [ConsoleCommand("css_ungag")] @@ -264,7 +267,6 @@ namespace CS2_SimpleAdmin } Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); bool found = false; @@ -366,7 +368,7 @@ namespace CS2_SimpleAdmin string callerName = caller == null ? "Console" : caller.PlayerName; int time = 0; - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; TargetResult? targets = GetTarget(command); if (targets == null) return; @@ -377,8 +379,6 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -391,13 +391,12 @@ namespace CS2_SimpleAdmin { if (caller!.CanTarget(player)) { - Mute(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager); - Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _discordWebhookClientPenalty, _localizer); + Mute(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager, command); } }); } - internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, PlayerPenaltyManager? playerPenaltyManager = null) + internal void Mute(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, PlayerPenaltyManager? playerPenaltyManager = null, CommandInfo? command = null) { if (_database == null) return; callerName ??= caller == null ? "Console" : caller.PlayerName; @@ -418,8 +417,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, $"css_mute {player?.SteamID} {time} {reason}"); - player!.VoiceFlags = VoiceFlags.Muted; Task.Run(async () => @@ -470,6 +467,13 @@ namespace CS2_SimpleAdmin } } } + + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _discordWebhookClientPenalty, _localizer); + Helper.LogCommand(caller, command); + } } [ConsoleCommand("css_addmute")] @@ -492,12 +496,8 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - Helper.LogCommand(caller, command); - int time = 0; - string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string reason = _localizer?["sa_unknown"] ?? "Unknown"; MuteManager _muteManager = new(_database); PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); @@ -569,6 +569,8 @@ namespace CS2_SimpleAdmin } } } + + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _discordWebhookClientPenalty, _localizer); } Task.Run(async () => @@ -576,7 +578,13 @@ namespace CS2_SimpleAdmin await _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 1); }); - command.ReplyToCommand($"Muted player with steamid {steamid}."); + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + } + + command?.ReplyToCommand($"Muted player with steamid {steamid}."); } [ConsoleCommand("css_unmute")] @@ -596,7 +604,6 @@ namespace CS2_SimpleAdmin } Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); string pattern = command.GetArg(1); @@ -695,8 +702,6 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - int.TryParse(command.GetArg(2), out time); if (command.ArgCount >= 3 && command.GetArg(3).Length > 0) @@ -709,13 +714,12 @@ namespace CS2_SimpleAdmin { if (caller!.CanTarget(player)) { - Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Silence, _discordWebhookClientPenalty, _localizer); - Silence(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager); + Silence(caller, player, time, reason, callerName, _muteManager, playerPenaltyManager, command); } }); } - internal void Silence(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, PlayerPenaltyManager? playerPenaltyManager = null) + internal void Silence(CCSPlayerController? caller, CCSPlayerController player, int time, string reason, string? callerName = null, MuteManager? muteManager = null, PlayerPenaltyManager? playerPenaltyManager = null, CommandInfo? command = null) { if (_database == null) return; callerName ??= caller == null ? "Console" : caller.PlayerName; @@ -736,8 +740,6 @@ namespace CS2_SimpleAdmin IpAddress = caller?.IpAddress?.Split(":")[0] }; - Helper.LogCommand(caller, $"css_silence {player?.SteamID} {time} {reason}"); - Task.Run(async () => { await muteManager.MutePlayer(playerInfo, adminInfo, reason, time, 2); @@ -747,7 +749,6 @@ namespace CS2_SimpleAdmin Server.ExecuteCommand($"css_tag_mute {player!.SteamID}"); player!.VoiceFlags = VoiceFlags.Muted; - playerPenaltyManager.AddPenalty(player!.Slot, PenaltyType.Silence, DateTime.Now.AddMinutes(time), time); if (time == 0) @@ -796,6 +797,13 @@ namespace CS2_SimpleAdmin } } } + + if (command != null) + { + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _discordWebhookClientPenalty, _localizer); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + } } [ConsoleCommand("css_addsilence")] @@ -818,10 +826,6 @@ namespace CS2_SimpleAdmin return; } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - Helper.LogCommand(caller, command); - int time = 0; string reason = CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; @@ -897,6 +901,8 @@ namespace CS2_SimpleAdmin } } } + + Helper.SendDiscordPenaltyMessage(caller, player, reason, time, Helper.PenaltyType.Mute, _discordWebhookClientPenalty, _localizer); } } Task.Run(async () => @@ -904,7 +910,13 @@ namespace CS2_SimpleAdmin await _muteManager.AddMuteBySteamid(steamid, adminInfo, reason, time, 2); }); - command.ReplyToCommand($"Silenced player with steamid {steamid}."); + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + } + + command?.ReplyToCommand($"Silenced player with steamid {steamid}."); } [ConsoleCommand("css_unsilence")] @@ -924,7 +936,6 @@ namespace CS2_SimpleAdmin } Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); string pattern = command.GetArg(1); diff --git a/Commands/basevotes.cs b/Commands/basevotes.cs index 2349e7b..088ada6 100644 --- a/Commands/basevotes.cs +++ b/Commands/basevotes.cs @@ -3,7 +3,6 @@ using CounterStrikeSharp.API.Core.Attributes.Registration; using CounterStrikeSharp.API.Core.Translations; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; -using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Menu; using System.Text; @@ -21,7 +20,6 @@ namespace CS2_SimpleAdmin return; Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); voteAnswers.Clear(); diff --git a/Commands/funcommands.cs b/Commands/funcommands.cs index eb44aad..26ec5e6 100644 --- a/Commands/funcommands.cs +++ b/Commands/funcommands.cs @@ -4,7 +4,6 @@ using CounterStrikeSharp.API.Core.Translations; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; -using CounterStrikeSharp.API.Modules.Entities; using System.Text; namespace CS2_SimpleAdmin @@ -113,24 +112,26 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) return; - Unfreeze(caller, player, callerName); + Unfreeze(caller, player, callerName, command); }); } - public void Unfreeze(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null) + public void Unfreeze(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; player!.Pawn.Value!.Unfreeze(); - Helper.LogCommand(caller, $"css_unfreeze {player.PlayerName}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { diff --git a/Commands/playercommands.cs b/Commands/playercommands.cs index d4d9c37..0a30fce 100644 --- a/Commands/playercommands.cs +++ b/Commands/playercommands.cs @@ -4,7 +4,6 @@ using CounterStrikeSharp.API.Core.Translations; using CounterStrikeSharp.API.Modules.Admin; using CounterStrikeSharp.API.Modules.Commands; using CounterStrikeSharp.API.Modules.Commands.Targeting; -using CounterStrikeSharp.API.Modules.Entities; using CounterStrikeSharp.API.Modules.Entities.Constants; using CounterStrikeSharp.API.Modules.Memory; using CounterStrikeSharp.API.Modules.Utils; @@ -23,17 +22,15 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => { - Slay(caller, player, callerName); + Slay(caller, player, callerName, command); }); } - public void Slay(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null) + public void Slay(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null) { if (!player.IsBot && player.SteamID.ToString().Length != 17) return; @@ -42,7 +39,11 @@ namespace CS2_SimpleAdmin player.CommitSuicide(false, true); - Helper.LogCommand(caller, $"css_slay {player.PlayerName}"); + if (command != null) + { + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + Helper.LogCommand(caller, command); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -94,14 +95,12 @@ namespace CS2_SimpleAdmin } } - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) return; - GiveWeapon(caller, player, weaponName, callerName); + GiveWeapon(caller, player, weaponName, callerName, command); }); } @@ -113,9 +112,13 @@ namespace CS2_SimpleAdmin SubGiveWeapon(caller, player!, weapon.ToString(), callerName); } - public void GiveWeapon(CCSPlayerController? caller, CCSPlayerController player, string weaponName, string? callerName = null) + public void GiveWeapon(CCSPlayerController? caller, CCSPlayerController player, string weaponName, string? callerName = null, CommandInfo? command = null) { - Helper.LogCommand(caller, $"css_give {player?.PlayerName} {weaponName}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } player?.GiveNamedItem(weaponName); SubGiveWeapon(caller, player!, weaponName, callerName); @@ -148,20 +151,18 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => { if (caller!.CanTarget(player)) { - StripWeapons(caller, player, callerName); + StripWeapons(caller, player, callerName, command); } }); } - public void StripWeapons(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null) + public void StripWeapons(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; @@ -170,7 +171,11 @@ namespace CS2_SimpleAdmin player.RemoveWeapons(); - Helper.LogCommand(caller, $"css_strip {player.PlayerName}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -198,20 +203,18 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => { if (caller!.CanTarget(player)) { - SetHp(caller, player, health, callerName); + SetHp(caller, player, health, callerName, command); } }); } - public void SetHp(CCSPlayerController? caller, CCSPlayerController player, int health, string? callerName = null) + public void SetHp(CCSPlayerController? caller, CCSPlayerController player, int health, string? callerName = null, CommandInfo? command = null) { if (!player.IsBot && player.SteamID.ToString().Length != 17) return; @@ -220,7 +223,11 @@ namespace CS2_SimpleAdmin player.SetHp(health); - Helper.LogCommand(caller, $"css_hp {player.PlayerName} {health}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -248,8 +255,6 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -259,18 +264,22 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - SetSpeed(caller, player, speed, callerName); + SetSpeed(caller, player, speed, callerName, command); } }); } - public void SetSpeed(CCSPlayerController? caller, CCSPlayerController player, double speed, string? callerName = null) + public void SetSpeed(CCSPlayerController? caller, CCSPlayerController player, double speed, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; player.SetSpeed((float)speed); - Helper.LogCommand(caller, $"css_speed {player?.PlayerName} {speed}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -309,18 +318,22 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - SetGravity(caller, player, gravity, callerName); + SetGravity(caller, player, gravity, callerName, command); } }); } - public void SetGravity(CCSPlayerController? caller, CCSPlayerController player, double gravity, string? callerName = null) + public void SetGravity(CCSPlayerController? caller, CCSPlayerController player, double gravity, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; player.SetGravity((float)gravity); - Helper.LogCommand(caller, $"css_gravity {player?.PlayerName} {gravity}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -348,8 +361,6 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -359,18 +370,22 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - SetMoney(caller, player, money, callerName); + SetMoney(caller, player, money, callerName, command); } }); } - public void SetMoney(CCSPlayerController? caller, CCSPlayerController player, int money, string? callerName = null) + public void SetMoney(CCSPlayerController? caller, CCSPlayerController player, int money, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; player.SetMoney(money); - Helper.LogCommand(caller, $"css_money {player?.PlayerName} {money}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -395,8 +410,6 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); playersToTarget.ForEach(player => @@ -406,18 +419,22 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - God(caller, player, callerName); + God(caller, player, callerName, command); } }); } - public void God(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null) + public void God(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; if (player != null) { - Helper.LogCommand(caller, $"css_god {player.PlayerName}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (!godPlayers.Contains(player.Slot)) { @@ -454,8 +471,6 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && player.PawnIsAlive && !player.IsHLTV).ToList(); if (command.ArgCount >= 2) @@ -470,17 +485,21 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - Slap(caller, player, damage); + Slap(caller, player, damage, command); } }); } - public void Slap(CCSPlayerController? caller, CCSPlayerController player, int damage, string? callerName = null) + public void Slap(CCSPlayerController? caller, CCSPlayerController player, int damage, CommandInfo? command = null) { - callerName ??= caller == null ? "Console" : caller.PlayerName; + string callerName = caller == null ? "Console" : caller.PlayerName; player!.Pawn.Value!.Slap(damage); - Helper.LogCommand(caller, $"css_slap {player.PlayerName} {damage}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -509,8 +528,6 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); if (targets == null) return; - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); switch (teamName) @@ -540,15 +557,13 @@ namespace CS2_SimpleAdmin bool kill = command.GetArg(3).ToLower().Equals("-k"); - Helper.LogCommand(caller, command); - playersToTarget.ForEach(player => { - ChangeTeam(caller, player, _teamName, teamNum, kill, callerName); + ChangeTeam(caller, player, _teamName, teamNum, kill, callerName, command); }); } - public void ChangeTeam(CCSPlayerController? caller, CCSPlayerController player, string teamName, CsTeam teamNum, bool kill, string? callerName = null) + public void ChangeTeam(CCSPlayerController? caller, CCSPlayerController player, string teamName, CsTeam teamNum, bool kill, string? callerName = null, CommandInfo? command = null) { if (!player.IsBot && player.SteamID.ToString().Length != 17) return; @@ -591,6 +606,12 @@ namespace CS2_SimpleAdmin } } } + + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } } [ConsoleCommand("css_rename", "Rename a player.")] @@ -607,9 +628,8 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { @@ -618,7 +638,6 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { foreach (CCSPlayerController _player in Helper.GetValidPlayers()) @@ -647,8 +666,6 @@ namespace CS2_SimpleAdmin TargetResult? targets = GetTarget(command); List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - playersToTarget.ForEach(player => { if (!player.IsBot && player.SteamID.ToString().Length != 17) @@ -656,12 +673,12 @@ namespace CS2_SimpleAdmin if (caller!.CanTarget(player)) { - Respawn(caller, player, callerName); + Respawn(caller, player, callerName, command); } }); } - public void Respawn(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null) + public void Respawn(CCSPlayerController? caller, CCSPlayerController player, string? callerName = null, CommandInfo? command = null) { callerName ??= caller == null ? "Console" : caller.PlayerName; @@ -672,7 +689,11 @@ namespace CS2_SimpleAdmin VirtualFunction.CreateVoid(player.Handle, GameData.GetOffset("CCSPlayerController_Respawn"))(player); - Helper.LogCommand(caller, $"css_respawn {player.PlayerName}"); + if (command != null) + { + Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); + } if (caller == null || caller != null && !silentPlayers.Contains(caller.Slot)) { @@ -706,9 +727,8 @@ namespace CS2_SimpleAdmin List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { @@ -758,10 +778,8 @@ namespace CS2_SimpleAdmin List playersToTarget = targets!.Players.Where(player => player != null && player.IsValid && !player.IsHLTV).ToList(); - Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); - - Helper.LogCommand(caller, command); + Helper.SendDiscordLogMessage(caller, command, _discordWebhookClientLog, _localizer); playersToTarget.ForEach(player => { diff --git a/Events.cs b/Events.cs index efcb0ab..7c5ea63 100644 --- a/Events.cs +++ b/Events.cs @@ -87,7 +87,6 @@ public partial class CS2_SimpleAdmin } } - [GameEventHandler] public HookResult OnPlayerFullConnect(EventPlayerConnectFull @event, GameEventInfo info) { @@ -226,10 +225,13 @@ public partial class CS2_SimpleAdmin public HookResult OnCommandSay(CCSPlayerController? player, CommandInfo info) { - if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).Length == 0 || info.GetArg(1).StartsWith("/") + if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).StartsWith("/") || info.GetArg(1).StartsWith("!") && info.GetArg(1).Length >= 12) return HookResult.Continue; + if (info.GetArg(1).Length == 0) + return HookResult.Handled; + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); if (playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence)) @@ -240,10 +242,13 @@ public partial class CS2_SimpleAdmin public HookResult OnCommandTeamSay(CCSPlayerController? player, CommandInfo info) { - if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).Length == 0 || info.GetArg(1).StartsWith("/") + if (player is null || !player.IsValid || player.IsBot || player.IsHLTV || info.GetArg(1).StartsWith("/") || info.GetArg(1).StartsWith("!") && info.GetArg(1).Length >= 12) return HookResult.Continue; + if (info.GetArg(1).Length == 0) + return HookResult.Handled; + PlayerPenaltyManager playerPenaltyManager = new PlayerPenaltyManager(); if (playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Gag) || playerPenaltyManager.IsPenalized(player.Slot, PenaltyType.Silence)) @@ -297,7 +302,6 @@ public partial class CS2_SimpleAdmin AddTimer(61.0f, () => { - #if DEBUG Logger.LogCritical("[OnMapStart] Expired check"); #endif @@ -407,7 +411,6 @@ public partial class CS2_SimpleAdmin await _adminManager.GiveAllFlags(); }); - }, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE); AddTimer(3.0f, () => diff --git a/Helper.cs b/Helper.cs index efae9ed..522ca5b 100644 --- a/Helper.cs +++ b/Helper.cs @@ -216,7 +216,6 @@ namespace CS2_SimpleAdmin Silence, } - public static string ConvertMinutesToTime(int minutes) { TimeSpan time = TimeSpan.FromMinutes(minutes); @@ -231,26 +230,31 @@ namespace CS2_SimpleAdmin string callercommunityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; string targetcommunityUrl = target != null ? "<" + new SteamID(target.SteamID).ToCommunityUrl().ToString() + ">" : ""; string callerName = caller != null ? caller.PlayerName : "Console"; - string targetName = target != null ? target.PlayerName : "Unknown"; - string targetSteamId = target != null ? new SteamID(target.SteamID).SteamId2.ToString() : "Unknown"; + string targetName = target != null ? target.PlayerName : localizer?["sa_unknown"] ?? "Unknown"; + string targetSteamId = target != null ? new SteamID(target.SteamID).SteamId2.ToString() : localizer?["sa_unknown"] ?? "Unknown"; - string time = duration != 0 ? ConvertMinutesToTime(duration) : "Permanent"; + string time = duration != 0 ? ConvertMinutesToTime(duration) : localizer?["sa_permanent"] ?? "Permanent"; - string[] fieldNames = ["Player:", "SteamID:", "Duration:", "Reason:", "Admin:"]; + string[] fieldNames = [ + localizer?["sa_player"] ?? "Player:", + localizer?["sa_steamid"] ?? "SteamID:", + localizer?["sa_duration"] ?? "Duration:", + localizer?["sa_reason"] ?? "Reason:", + localizer?["sa_admin"] ?? "Admin:"]; string[] fieldValues = [$"[{targetName}]({targetcommunityUrl})", targetSteamId, time, reason, $"[{callerName}]({callercommunityUrl})"]; bool[] inlineFlags = [true, true, true, false, false]; - string? hostname = ConVar.Find("hostname")!.StringValue ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown"; + string? hostname = ConVar.Find("hostname")!.StringValue ?? localizer?["sa_unknown"] ?? "Unknown"; var embed = new EmbedBuilder { Title = penalty switch { - PenaltyType.Ban => "Ban registrered", - PenaltyType.Mute => "Mute registrered", - PenaltyType.Gag => "Gag registrered", - PenaltyType.Silence => "Silence registrered", - _ => "Unknown penalty registrered", + PenaltyType.Ban => localizer?["sa_discord_penalty_ban"] ?? "Ban registrered", + PenaltyType.Mute => localizer?["sa_discord_penalty_mute"] ?? "Mute registrered", + PenaltyType.Gag => localizer?["sa_discord_penalty_gag"] ?? "Gag registrered", + PenaltyType.Silence => localizer?["sa_discord_penalty_silence"] ?? "Silence registrered", + _ => localizer?["sa_discord_penalty_unknown"] ?? "Unknown registrered", }, Color = penalty switch diff --git a/lang/ar.json b/lang/ar.json index 2564212..02e81ce 100644 --- a/lang/ar.json +++ b/lang/ar.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "مجهول", + "sa_player": "اللاعب", + "sa_steamid": "معرف البخار", + "sa_duration": "المدة", + "sa_reason": "السبب", + "sa_admin": "المشرف", + "sa_permanent": "دائم", + + "sa_discord_penalty_ban": "الحظر مسجل", + "sa_discord_penalty_mute": "الكتم مسجل", + "sa_discord_penalty_gag": "الصمت مسجل", + "sa_discord_penalty_silence": "الصمت مسجل", + "sa_discord_penalty_unknown": "غير معروف مسجل", + "sa_player_ban_message_time": "تم حظرك لمدة {lightred}{0}{default} لمدة {lightred}{1}{default} دقيقة من قبل {lightred}{2}{default}!", "sa_player_ban_message_perm": "تم حظرك بشكل دائم لمدة {lightred}{0}{default} من قبل {lightred}{1}{default}!", "sa_player_kick_message": "تم طردك لمدة {lightred}{0}{default} من قبل {lightred}{1}{default}!", diff --git a/lang/en.json b/lang/en.json index f4666b0..88cf250 100644 --- a/lang/en.json +++ b/lang/en.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Unknown", + "sa_player": "Player", + "sa_steamid": "SteamID", + "sa_duration": "Duration", + "sa_reason": "Reason", + "sa_admin": "Admin", + "sa_permanent": "Permanent", + + "sa_discord_penalty_ban": "Ban registrered", + "sa_discord_penalty_mute": "Mute registrered", + "sa_discord_penalty_gag": "Gag registrered", + "sa_discord_penalty_silence": "Silence registrered", + "sa_discord_penalty_unknown": "Unknown registrered", + "sa_player_ban_message_time": "You have been banned for {lightred}{0}{default} for {lightred}{1}{default} minutes by {lightred}{2}{default}!", "sa_player_ban_message_perm": "You have been banned permanently for {lightred}{0}{default} by {lightred}{1}{default}!", "sa_player_kick_message": "You have been kicked for {lightred}{0}{default} by {lightred}{1}{default}!", diff --git a/lang/es.json b/lang/es.json index 4c8cc39..cd1c49c 100644 --- a/lang/es.json +++ b/lang/es.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Desconocido", + "sa_player": "Jugador", + "sa_steamid": "ID de Steam", + "sa_duration": "Duración", + "sa_reason": "Motivo", + "sa_admin": "Admin", + "sa_permanent": "Permanente", + + "sa_discord_penalty_ban": "Ban registrado", + "sa_discord_penalty_mute": "Silencio registrado", + "sa_discord_penalty_gag": "Mordaza registrada", + "sa_discord_penalty_silence": "Silencio registrado", + "sa_discord_penalty_unknown": "Registro desconocido", + "sa_player_ban_message_time": "Has sido baneado por {lightred}{0}{default} durante {lightred}{1}{default} minutos por {lightred}{2}{default}!", "sa_player_ban_message_perm": "Has sido baneado permanentemente por {lightred}{0}{default} por {lightred}{1}{default}!", "sa_player_kick_message": "Has sido expulsado por {lightred}{0}{default} durante {lightred}{1}{default}!", diff --git a/lang/fa.json b/lang/fa.json index 5c200bc..1c057ba 100644 --- a/lang/fa.json +++ b/lang/fa.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "ناشناخته", + "sa_player": "بازیکن", + "sa_steamid": "شناسه استیم", + "sa_duration": "مدت زمان", + "sa_reason": "دلیل", + "sa_admin": "مدیر", + "sa_permanent": "دائمی", + + "sa_discord_penalty_ban": "بن انجام شده", + "sa_discord_penalty_mute": "سکوت انجام شده", + "sa_discord_penalty_gag": "بند زدن انجام شده", + "sa_discord_penalty_silence": "سکوت انجام شده", + "sa_discord_penalty_unknown": "ناشناخته انجام شده", + "sa_player_ban_message_time": "شما توسط {lightred}{2}{default} برای {lightred}{1}{default} دقیقه به دلیل {lightred}{0}{default} مسدود شده‌اید!", "sa_player_ban_message_perm": "شما توسط {lightred}{1}{default} به دلیل {lightred}{0}{default} برای همیشه مسدود شده‌اید!", "sa_player_kick_message": "شما توسط {lightred}{1}{default} به دلیل {lightred}{0}{default} اخراج شده‌اید!", diff --git a/lang/fr.json b/lang/fr.json index c4c0ff2..27797e7 100644 --- a/lang/fr.json +++ b/lang/fr.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Inconnu", + "sa_player": "Joueur", + "sa_steamid": "ID Steam", + "sa_duration": "Durée", + "sa_reason": "Raison", + "sa_admin": "Admin", + "sa_permanent": "Permanent", + + "sa_discord_penalty_ban": "Bannissement enregistré", + "sa_discord_penalty_mute": "Mute enregistré", + "sa_discord_penalty_gag": "Gag enregistré", + "sa_discord_penalty_silence": "Silence enregistré", + "sa_discord_penalty_unknown": "Inconnu enregistré", + "sa_player_ban_message_time": "Vous avez été banni pour {lightred}{0}{default} pendant {lightred}{1}{default} minutes par {lightred}{2}{default}!", "sa_player_ban_message_perm": "Vous avez été banni définitivement pour {lightred}{0}{default} par {lightred}{1}{default}!", "sa_player_kick_message": "Vous avez été expulsé pour {lightred}{0}{default} par {lightred}{1}{default}!", diff --git a/lang/lv.json b/lang/lv.json index fe09668..f8e2ea1 100644 --- a/lang/lv.json +++ b/lang/lv.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Nezināms", + "sa_player": "Spēlētājs", + "sa_steamid": "Steam ID", + "sa_duration": "Ilgums", + "sa_reason": "Iemesls", + "sa_admin": "Admins", + "sa_permanent": "Pastāvīgs", + + "sa_discord_penalty_ban": "Bans reģistrēts", + "sa_discord_penalty_mute": "Mute reģistrēts", + "sa_discord_penalty_gag": "Gag reģistrēts", + "sa_discord_penalty_silence": "Klusums reģistrēts", + "sa_discord_penalty_unknown": "Nezināms reģistrēts", + "sa_player_ban_message_time": "Tu esi nobanots uz {lightred}{0}{default} uz {lightred}{1}{default} minūtēm, iemesls: {lightred}{2}{default}!", "sa_player_ban_message_perm": "Tevis bans ir uz mūžu, iemesls: {lightred}{0}{default}, Admins: {lightred}{1}{default}!", "sa_player_kick_message": "Tu esi izmests, iemesls: {lightred}{0}{default}, Admins: {lightred}{1}{default}!", diff --git a/lang/pl.json b/lang/pl.json index 1746cb8..2ddddd7 100644 --- a/lang/pl.json +++ b/lang/pl.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Brak", + "sa_player": "Gracz", + "sa_steamid": "SteamID", + "sa_duration": "Czas trwania", + "sa_reason": "Powód", + "sa_admin": "Administrator", + "sa_permanent": "Na zawsze", + + "sa_discord_penalty_ban": "Nowy ban", + "sa_discord_penalty_mute": "Nowe wyciszenie", + "sa_discord_penalty_gag": "Nowe zakneblowanie", + "sa_discord_penalty_silence": "Nowe uciszenie", + "sa_discord_penalty_unknown": "Nowa nieznana blokada", + "sa_player_ban_message_time": "Zostałeś zbanowany za {lightred}{0}{default} na {lightred}{1}{default} minut przez {lightred}{2}{default}!", "sa_player_ban_message_perm": "Zostałeś zbanowany na zawsze za {lightred}{0}{default} przez {lightred}{1}{default}!", "sa_player_kick_message": "Zostałeś wyrzucony za {lightred}{0}{default} przez {lightred}{1}{default}!", diff --git a/lang/pt-BR.json b/lang/pt-BR.json index 36518a2..b8a987d 100644 --- a/lang/pt-BR.json +++ b/lang/pt-BR.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Desconhecido", + "sa_player": "Jogador", + "sa_steamid": "SteamID", + "sa_duration": "Duração", + "sa_reason": "Motivo", + "sa_admin": "Admin", + "sa_permanent": "Permanente", + + "sa_discord_penalty_ban": "Banimento registrado", + "sa_discord_penalty_mute": "Mute registrado", + "sa_discord_penalty_gag": "Gag registrado", + "sa_discord_penalty_silence": "Silêncio registrado", + "sa_discord_penalty_unknown": "Desconhecido registrado", + "sa_player_ban_message_time": "Você foi banido por {lightred}{0}{default} por {lightred}{1}{default} minutos por {lightred}{2}{default}!", "sa_player_ban_message_perm": "Você foi banido permanentemente por {lightred}{0}{default} por {lightred}{1}{default}!", "sa_player_kick_message": "Você foi expulso por {lightred}{0}{default} por {lightred}{1}{default}!", diff --git a/lang/ru.json b/lang/ru.json index 46a49ee..6b30dd0 100644 --- a/lang/ru.json +++ b/lang/ru.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Неизвестный", + "sa_player": "Игрок", + "sa_steamid": "SteamID", + "sa_duration": "Продолжительность", + "sa_reason": "Причина", + "sa_admin": "Администратор", + "sa_permanent": "Постоянный", + + "sa_discord_penalty_ban": "Бан зарегистрирован", + "sa_discord_penalty_mute": "Мут зарегистрирован", + "sa_discord_penalty_gag": "Запрет зарегистрирован", + "sa_discord_penalty_silence": "Молчание зарегистрировано", + "sa_discord_penalty_unknown": "Неизвестно зарегистрировано", + "sa_player_ban_message_time": "Вы были забанены по причине {lightred}{0}{default} на {lightred}{1}{default} минут(ы) администратором {lightred}{2}{default}!", "sa_player_ban_message_perm": "Вас забанили навсегда по причине {lightred}{0}{default} администратором {lightred}{1}{default}!", "sa_player_kick_message": "Вы были выгнаны {lightred}{0}{default} администратором {lightred}{1}{default}!", diff --git a/lang/tr.json b/lang/tr.json index a4df1ea..b337b6d 100644 --- a/lang/tr.json +++ b/lang/tr.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "Bilinmeyen", + "sa_player": "Oyuncu", + "sa_steamid": "SteamID", + "sa_duration": "Süre", + "sa_reason": "Neden", + "sa_admin": "Yönetici", + "sa_permanent": "Kalıcı", + + "sa_discord_penalty_ban": "Yasak kaydedildi", + "sa_discord_penalty_mute": "Susturma kaydedildi", + "sa_discord_penalty_gag": "Susturma kaydedildi", + "sa_discord_penalty_silence": "Sessizlik kaydedildi", + "sa_discord_penalty_unknown": "Bilinmeyen kaydedildi", + "sa_player_ban_message_time": "Senaryo nedeniyle {lightred}{0}{default} dakika boyunca {lightred}{1}{default} tarafından yasaklandınız!", "sa_player_ban_message_perm": "Senaryo nedeniyle kalıcı olarak {lightred}{0}{default} tarafından yasaklandınız!", "sa_player_kick_message": "Senaryo nedeniyle {lightred}{0}{default} tarafından atıldınız!", diff --git a/lang/zh-Hans.json b/lang/zh-Hans.json index a8dc380..895c242 100644 --- a/lang/zh-Hans.json +++ b/lang/zh-Hans.json @@ -2,6 +2,19 @@ "sa_prefix": "{lightred}[SA] {default}", "sa_unknown": "未知", + "sa_player": "玩家", + "sa_steamid": "SteamID", + "sa_duration": "持续时间", + "sa_reason": "原因", + "sa_admin": "管理员", + "sa_permanent": "永久", + + "sa_discord_penalty_ban": "封禁已记录", + "sa_discord_penalty_mute": "禁言已记录", + "sa_discord_penalty_gag": "禁言已记录", + "sa_discord_penalty_silence": "禁声已记录", + "sa_discord_penalty_unknown": "未知已记录", + "sa_player_ban_message_time": "你因为{lightred}{0}{default}的原因被{lightred}{1}{default}禁止{lightred}{2}{default}分钟!", "sa_player_ban_message_perm": "你因为{lightred}{0}{default}的原因被{lightred}{1}{default}永久禁止!", "sa_player_kick_message": "你因为{lightred}{0}{default}的原因被{lightred}{1}{default}踢出!", From 3abf246f9b9da5c0a790dc3de23dff3af7a8aee5 Mon Sep 17 00:00:00 2001 From: Dawid Bepierszcz <41084667+daffyyyy@users.noreply.github.com> Date: Tue, 2 Apr 2024 19:55:48 +0200 Subject: [PATCH 9/9] fixed reloadadmins --- Commands/basecommands.cs | 20 ++------------------ Menus/ManageAdminsMenu.cs | 4 ++-- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/Commands/basecommands.cs b/Commands/basecommands.cs index e8e6aa8..89adf98 100644 --- a/Commands/basecommands.cs +++ b/Commands/basecommands.cs @@ -213,12 +213,12 @@ namespace CS2_SimpleAdmin { if (_database == null) return; - ReloadAdmins(); + ReloadAdmins(caller); command.ReplyToCommand("Reloaded sql admins"); } - public void ReloadAdmins() + public void ReloadAdmins(CCSPlayerController? caller) { if (_database == null) return; @@ -473,13 +473,6 @@ namespace CS2_SimpleAdmin _command = $"ds_workshop_changelevel {map.Replace("ws:", "")}"; } - //if (_discordWebhookClientLog != null && _localizer != null) - //{ - // string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - // string commandName = command?.GetCommandString ?? "css_changemap"; - // _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); - //} - AddTimer(3.0f, () => { Server.ExecuteCommand(_command); @@ -565,15 +558,6 @@ namespace CS2_SimpleAdmin } } - //if (_discordWebhookClientLog != null && _localizer != null) - //{ - // string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : ""; - // string commandName = command?.GetCommandString ?? "css_changewsmap"; - // _discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName])); - //} - //if (command is not null) - // Helper.LogCommand(caller, command); - AddTimer(3.0f, () => { Server.ExecuteCommand(_command); diff --git a/Menus/ManageAdminsMenu.cs b/Menus/ManageAdminsMenu.cs index c7cfbff..7f7b6fa 100644 --- a/Menus/ManageAdminsMenu.cs +++ b/Menus/ManageAdminsMenu.cs @@ -77,9 +77,9 @@ namespace CS2_SimpleAdmin.Menus CS2_SimpleAdmin.Instance.RemoveAdmin(admin, player.SteamID.ToString()); } - private static void ReloadAdmins() + private static void ReloadAdmins(CCSPlayerController admin) { - CS2_SimpleAdmin.Instance.ReloadAdmins(); + CS2_SimpleAdmin.Instance.ReloadAdmins(admin); } } } \ No newline at end of file