-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for No Database, custom reason and more
- Loading branch information
Showing
13 changed files
with
257 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using CounterStrikeSharp.API; | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Admin; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
using CounterStrikeSharp.API.Modules.Cvars; | ||
using CounterStrikeSharp.API.Modules.Menu; | ||
|
||
namespace CallAdmin | ||
{ | ||
public partial class CallAdmin | ||
{ | ||
public void ReportCommand(CCSPlayerController? player, CommandInfo command) | ||
{ | ||
if (player == null || !player.IsValid || player.IsBot) return; | ||
|
||
if (!string.IsNullOrEmpty(Config.Commands.ReportPermission) && !AdminManager.PlayerHasPermissions(player, Config.Commands.ReportPermission.Split(";"))) | ||
{ | ||
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.MissingCommandPermission}"); | ||
return; | ||
} | ||
|
||
int playerIndex = (int)player.Index; | ||
|
||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CooldownRefreshCommandSeconds)) | ||
{ | ||
|
||
commandCooldown[playerIndex] = DateTime.UtcNow; | ||
|
||
ChatMenu reportMenu = new(Config.ChatMenuMessages.PlayersTitle); | ||
|
||
foreach (var playerOnServer in Utilities.GetPlayers()) | ||
{ | ||
if (playerOnServer.IsBot || playerOnServer.Index == player.Index) continue; | ||
|
||
reportMenu.AddMenuOption($"{playerOnServer.PlayerName} [{playerOnServer.Index}]", HandleMenu); | ||
} | ||
|
||
if (reportMenu.MenuOptions.Count == 0) | ||
{ | ||
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.NoPlayersAvailable}"); | ||
return; | ||
} | ||
ChatMenus.OpenMenu(player, reportMenu); | ||
return; | ||
} | ||
|
||
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.InCoolDown}"); | ||
|
||
} | ||
|
||
private void HandleMenu(CCSPlayerController player, ChatMenuOption option) | ||
{ | ||
var parts = option.Text.Split('[', ']'); | ||
var lastPart = parts[parts.Length - 2]; | ||
var numbersOnly = string.Join("", lastPart.Where(char.IsDigit)); | ||
|
||
var index = int.Parse(numbersOnly.Trim()); | ||
var reasons = Config.Reasons.Split(";"); | ||
var reasonMenu = new ChatMenu(Config.ChatMenuMessages.ReasonsTitle); | ||
reasonMenu.MenuOptions.Clear(); | ||
foreach (var reason in reasons) | ||
{ | ||
reasonMenu.AddMenuOption($"{reason.Replace("{CUSTOMREASON}", "")} [{index}{(reason.Contains("{CUSTOMREASON}") == true ? "-c" : "")}]", HandleMenu2Async); | ||
} | ||
|
||
ChatMenus.OpenMenu(player, reasonMenu); | ||
} | ||
|
||
private async void HandleMenu2Async(CCSPlayerController player, ChatMenuOption option) | ||
{ | ||
var parts = option.Text.Split('[', ']'); | ||
var lastPart = parts[^2]; | ||
|
||
if (lastPart.Contains("-c")) | ||
{ | ||
|
||
var findPlayer = CustomMessagePlayers.Find(obj => obj.Player == (int)player.Index); | ||
if (findPlayer == null) | ||
CustomMessagePlayers.Add(new CustomMessagePlayersClass | ||
{ | ||
HandleMessage = true, | ||
Player = (int)player.Index, | ||
Target = int.Parse(lastPart.Replace("-c", "").Trim()) | ||
|
||
}); | ||
else | ||
{ | ||
findPlayer.HandleMessage = true; | ||
findPlayer.Target = int.Parse(lastPart.Replace("-c", "").Trim()); | ||
} | ||
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.CustomReason}"); | ||
return; | ||
} | ||
else | ||
{ | ||
var target = Utilities.GetPlayerFromIndex(int.Parse(lastPart.Replace("-c", "").Trim())); | ||
|
||
await HandleSentToDiscordAsync(player, target, parts[0]); | ||
} | ||
|
||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
using CounterStrikeSharp.API.Core; | ||
using CounterStrikeSharp.API.Modules.Admin; | ||
using CounterStrikeSharp.API.Modules.Commands; | ||
|
||
namespace CallAdmin | ||
{ | ||
public partial class CallAdmin | ||
{ | ||
[CommandHelper(minArgs: 1, usage: "[identifier]", whoCanExecute: CommandUsage.CLIENT_ONLY)] | ||
public async void ReportHandledCommand(CCSPlayerController? player, CommandInfo command) | ||
{ | ||
if (player == null || !player.IsValid || player.IsBot || !Config.Commands.ReportHandledEnabled) return; | ||
|
||
|
||
|
||
if (!string.IsNullOrEmpty(Config.Commands.ReportHandledPermission) && !AdminManager.PlayerHasPermissions(player, Config.Commands.ReportHandledPermission.Split(";").Select(space => space.Trim()).ToArray())) | ||
{ | ||
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.MissingCommandPermission}"); | ||
return; | ||
} | ||
|
||
int playerIndex = (int)player.Index; | ||
|
||
if (commandCooldown != null && DateTime.UtcNow >= commandCooldown[playerIndex].AddSeconds(Config.CooldownRefreshCommandSeconds)) | ||
{ | ||
|
||
commandCooldown[playerIndex] = DateTime.UtcNow; | ||
|
||
string identifier = command.ArgString.Split(" ")[0].Trim(); | ||
|
||
var query = await GetReportDatabase(identifier); | ||
|
||
if (query == null) | ||
{ | ||
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.ReportNotFound}"); | ||
return; | ||
} | ||
|
||
string result = await SendMessageToDiscord(Payload(query.victim_name, query.victim_steamid, query.suspect_name, | ||
query.suspect_steamid, query.host_name, query.host_ip, query.reason, identifier, Config.EmbedMessages.Content, player.PlayerName, player.SteamID.ToString()), query.message_id); | ||
|
||
if (!result.All(char.IsDigit)) | ||
{ | ||
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.WebhookError}"); | ||
Console.WriteLine(result); | ||
return; | ||
} | ||
|
||
bool executeResult = await UpdateReportDatabase(identifier, player.PlayerName, player.SteamID.ToString()); | ||
|
||
if (!executeResult) | ||
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.MarkedAsHandledButNotInDatabase}"); | ||
|
||
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.ReportMarkedAsHandled}"); | ||
|
||
return; | ||
} | ||
|
||
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.InCoolDown}"); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.