Merge pull request #85 from Dliix66/main

Fixed Discord web hooks with the menu and several bug fixes/improvments on the menus
This commit is contained in:
Dawid Bepierszcz
2024-04-02 18:34:18 +02:00
committed by GitHub
15 changed files with 282 additions and 221 deletions

View File

@@ -122,12 +122,6 @@ namespace CS2_SimpleAdmin
return;
}
if (_discordWebhookClientLog != null && _localizer != null)
{
string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : "<https://steamcommunity.com/profiles/0>";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
string steamid = command.GetArg(1);
string name = command.GetArg(2);
string flags = command.GetArg(3);
@@ -146,7 +140,9 @@ namespace CS2_SimpleAdmin
AdminSQLManager _adminManager = new(_database);
_ = _adminManager.AddAdminBySteamId(steamid, name, flags, immunity, time, globalAdmin);
Helper.LogCommand(caller, $"css_addadmin {steamid} {name} {flags} {immunity} {time}");
string commandName = $"css_addadmin {steamid} {name} {flags} {immunity} {time}";
Helper.TryLogCommandOnDiscord(caller, commandName);
Helper.LogCommand(caller, commandName);
string msg = $"Added '{flags}' flags to '{name}' ({steamid})";
if (command != null)
@@ -171,12 +167,6 @@ namespace CS2_SimpleAdmin
return;
}
if (_discordWebhookClientLog != null && _localizer != null)
{
string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : "<https://steamcommunity.com/profiles/0>";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
string steamid = command.GetArg(1);
bool globalDelete = command.GetArg(2).ToLower().Equals("-g");
@@ -203,7 +193,9 @@ namespace CS2_SimpleAdmin
}
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
Helper.LogCommand(caller, $"css_deladmin {steamid}");
string commandName = $"css_deladmin {steamid}";
Helper.TryLogCommandOnDiscord(caller, commandName);
Helper.LogCommand(caller, commandName);
string msg = $"Removed flags from '{steamid}'";
if (command != null)
@@ -221,15 +213,18 @@ 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;
string commandName = "css_reladmin";
Helper.TryLogCommandOnDiscord(caller, commandName);
foreach (SteamID steamId in AdminSQLManager._adminCache.Keys.ToList())
{
if (AdminSQLManager._adminCache.TryRemove(steamId, out _))
@@ -397,12 +392,6 @@ namespace CS2_SimpleAdmin
return;
}
if (_discordWebhookClientLog != null && _localizer != null)
{
string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : "<https://steamcommunity.com/profiles/0>";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", command.GetCommandString]));
}
if (command.ArgCount >= 2 && command.GetArg(2).Length > 0)
reason = command.GetArg(2);
@@ -427,8 +416,10 @@ namespace CS2_SimpleAdmin
}
reason = reason ?? CS2_SimpleAdmin._localizer?["sa_unknown"] ?? "Unknown";
Helper.LogCommand(caller, $"css_kick {player.PlayerName} {reason}");
string commandName = $"css_kick {player.PlayerName} {reason}";
Helper.LogCommand(caller, commandName);
Helper.TryLogCommandOnDiscord(caller, commandName);
if (string.IsNullOrEmpty(reason) == false)
{
@@ -488,12 +479,8 @@ 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() + ">" : "<https://steamcommunity.com/profiles/0>";
string commandName = command?.GetCommandString ?? "css_changemap";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName]));
}
string commandName = command?.GetCommandString ?? $"css_changewsmap {map}";
Helper.TryLogCommandOnDiscord(caller, commandName);
if (command is not null)
Helper.LogCommand(caller, command);
@@ -532,6 +519,9 @@ namespace CS2_SimpleAdmin
if (!map.StartsWith("ws:"))
{
string commandName = command?.GetCommandString ?? $"css_changemap {map}";
Helper.TryLogCommandOnDiscord(caller, commandName);
AddTimer(2.0f, () =>
{
Server.ExecuteCommand($"changelevel {map}");
@@ -578,13 +568,9 @@ namespace CS2_SimpleAdmin
}
}
}
if (_discordWebhookClientLog != null && _localizer != null)
{
string communityUrl = caller != null ? "<" + new SteamID(caller.SteamID).ToCommunityUrl().ToString() + ">" : "<https://steamcommunity.com/profiles/0>";
string commandName = command?.GetCommandString ?? "css_changewsmap";
_discordWebhookClientLog.SendMessageAsync(Helper.GenerateMessageDiscord(_localizer["sa_discord_log_command", $"[{callerName}]({communityUrl})", commandName]));
}
string commandName = command?.GetCommandString ?? $"css_changewsmap {map}";
Helper.TryLogCommandOnDiscord(caller, commandName);
if (command is not null)
Helper.LogCommand(caller, command);
@@ -663,10 +649,13 @@ namespace CS2_SimpleAdmin
public static void RestartGame(CCSPlayerController? admin)
{
Helper.LogCommand(admin, "css_restartgame");
// TODO: Localize
var name = admin == null ? "Console" : admin.PlayerName;
string name = admin == null ? "Console" : admin.PlayerName;
string commandName = "css_restartgame";
Helper.TryLogCommandOnDiscord(admin, commandName);
Helper.LogCommand(admin, commandName);
Server.PrintToChatAll($"[SA] {name}: Restarting game...");
Server.ExecuteCommand("mp_restartgame 2");
}