Skip to content

Commit

Permalink
Add translation
Browse files Browse the repository at this point in the history
  • Loading branch information
1Mack committed Dec 13, 2023
1 parent acf4c0a commit 7c5b52b
Show file tree
Hide file tree
Showing 29 changed files with 303 additions and 228 deletions.
4 changes: 2 additions & 2 deletions CallAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public class CustomMessagePlayersClass
public int? Target { get; set; }
public required bool HandleMessage { get; set; }
}
[MinimumApiVersion(77)]
[MinimumApiVersion(124)]
public partial class CallAdmin : BasePlugin, IPluginConfig<CallAdminConfig>
{

public override string ModuleName => "CallAdmin";
public override string ModuleDescription => "Report System with database support";
public override string ModuleAuthor => "1MaaaaaacK";
public override string ModuleVersion => "1.6";
public static int ConfigVersion => 5;
public static int ConfigVersion => 6;

private string DatabaseConnectionString = string.Empty;

Expand Down
10 changes: 7 additions & 3 deletions CallAdmin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.90" />
<PackageReference Include="Dapper" Version="2.1.24" />
<PackageReference Include="MySqlConnector" Version="2.3.1" />
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.124" />
<PackageReference Include="Dapper" Version="*" />
<PackageReference Include="MySqlConnector" Version="*" />

<None Update="lang\**\*.*" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

</Project>
14 changes: 7 additions & 7 deletions Commands/Report.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Modules.Admin;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Core.Translations;
using CounterStrikeSharp.API.Modules.Menu;

namespace CallAdmin
Expand All @@ -15,7 +15,7 @@ public void ReportCommand(CCSPlayerController? player, CommandInfo command)

if (!string.IsNullOrEmpty(Config.Commands.ReportPermission) && !AdminManager.PlayerHasPermissions(player, Config.Commands.ReportPermission.Split(";")))
{
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.MissingCommandPermission}");
command.ReplyToCommand($"{Localizer["Prefix"]} {Localizer["MissingCommandPermission"]}");
return;
}

Expand All @@ -26,7 +26,7 @@ public void ReportCommand(CCSPlayerController? player, CommandInfo command)

commandCooldown[playerIndex] = DateTime.UtcNow;

ChatMenu reportMenu = new(Config.ChatMenuMessages.PlayersTitle);
ChatMenu reportMenu = new(Localizer["ChatMenu.PlayersTitle"]);

foreach (var playerOnServer in Utilities.GetPlayers())
{
Expand All @@ -37,14 +37,14 @@ public void ReportCommand(CCSPlayerController? player, CommandInfo command)

if (reportMenu.MenuOptions.Count == 0)
{
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.NoPlayersAvailable}");
command.ReplyToCommand($"{Localizer["Prefix"]} {Localizer["NoPlayersAvailable"]}");
return;
}
ChatMenus.OpenMenu(player, reportMenu);
return;
}

command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.InCoolDown}");
command.ReplyToCommand($"{Localizer["Prefix"]} {Localizer["InCoolDown", Config.CooldownRefreshCommandSeconds]}");

}

Expand All @@ -56,7 +56,7 @@ private void HandleMenu(CCSPlayerController player, ChatMenuOption option)

var index = int.Parse(numbersOnly.Trim());
var reasons = Config.Reasons.Split(";");
var reasonMenu = new ChatMenu(Config.ChatMenuMessages.ReasonsTitle);
var reasonMenu = new ChatMenu(Localizer["ChatMenu.ReasonsTitle"]);
reasonMenu.MenuOptions.Clear();
foreach (var reason in reasons)
{
Expand Down Expand Up @@ -89,7 +89,7 @@ private async void HandleMenu2Async(CCSPlayerController player, ChatMenuOption o
findPlayer.HandleMessage = true;
findPlayer.Target = int.Parse(lastPart.Replace("-c", "").Trim());
}
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.CustomReason}");
player.PrintToChat($"{Localizer["Prefix"]} {Localizer["CustomReason"]}");
return;
}
else
Expand Down
14 changes: 7 additions & 7 deletions Commands/ReportHandled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void ReportHandledCommand(CCSPlayerController? player, CommandInfo comman

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}");
command.ReplyToCommand($"{Localizer["Prefix"]} {Localizer["MissingCommandPermission"]}");
return;
}

Expand All @@ -39,33 +39,33 @@ public void ReportHandledCommand(CCSPlayerController? player, CommandInfo comman
{
if (query == null)
{
command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.ReportNotFound}");
command.ReplyToCommand($"{Localizer["Prefix"]} {Localizer["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, playerName, playerSteamid), query.message_id);
query.suspect_steamid, query.host_name, query.host_ip, query.reason, identifier, playerName, playerSteamid), query.message_id);
if (!result.All(char.IsDigit))
{
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.WebhookError}");
player.PrintToChat($"{Localizer["Prefix"]} {Localizer["WebhookError"]}");
Console.WriteLine(result);
return;
}
bool executeResult = await UpdateReportDatabase(identifier, playerName, playerSteamid);
if (!executeResult)
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.MarkedAsHandledButNotInDatabase}");
player.PrintToChat($"{Localizer["Prefix"]} {Localizer["MarkedAsHandledButNotInDatabase"]}");
player.PrintToChat($"{Config.Prefix} {Config.ChatMessages.ReportMarkedAsHandled}");
player.PrintToChat($"{Localizer["Prefix"]} {Localizer["ReportMarkedAsHandled"]}");
});
});

}
else

command.ReplyToCommand($"{Config.Prefix} {Config.ChatMessages.InCoolDown}");
command.ReplyToCommand($"{Localizer["Prefix"]} {Localizer["InCoolDown", Config.CooldownRefreshCommandSeconds]}");

}
}
Expand Down
140 changes: 4 additions & 136 deletions Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,86 +25,27 @@ public void OnConfigParsed(CallAdminConfig config)
{
throw new Exception($"You need to setup WebHookUrl and Reasons in config!");
}

config.Prefix = ChatTags(config, config.Prefix);

var messageProperties = config.ChatMessages.GetType().GetProperties();

foreach (var message in messageProperties)
{
var value = message.GetValue(config.ChatMessages)?.ToString();


if (string.IsNullOrEmpty(value)) throw new Exception($"You need to setup the message `{message.Name}` in config!");

message.SetValue(config.ChatMessages, ChatTags(config, value));
}

Config = config;

}
private static string ChatTags(CallAdminConfig config, string input)
{
Dictionary<string, dynamic> tags = new()
{
{ "{DEFAULT}", ChatColors.Default },
{ "{WHITE}", ChatColors.White },
{ "{DARKRED}", ChatColors.Darkred },
{ "{GREEN}", ChatColors.Green },
{ "{LIGHTYELLOW}", ChatColors.LightYellow },
{ "{LIGHTBLUE}", ChatColors.LightBlue },
{ "{OLIVE}", ChatColors.Olive },
{ "{LIME}", ChatColors.Lime },
{ "{RED}", ChatColors.Red },
{ "{LIGHTPURPLE}", ChatColors.LightPurple },
{ "{PURPLE}", ChatColors.Purple },
{ "{GREY}", ChatColors.Grey },
{ "{YELLOW}", ChatColors.Yellow },
{ "{GOLD}", ChatColors.Gold },
{ "{SILVER}", ChatColors.Silver },
{ "{BLUE}", ChatColors.Blue },
{ "{DARKBLUE}", ChatColors.DarkBlue },
{ "{BLUEGREY}", ChatColors.BlueGrey },
{ "{MAGENTA}", ChatColors.Magenta },
{ "{LIGHTRED}", ChatColors.LightRed },
{ "{COOLDOWNSECONDS}", config.CooldownRefreshCommandSeconds }
};

foreach (var color in tags)
{
input = input.Replace(color.Key, color.Value.ToString());

}

return input;
}
}
public class CallAdminConfig : BasePluginConfig
{
public override int Version { get; set; } = 5;

[JsonPropertyName("Prefix")]
public string Prefix { get; set; } = "{DEFAULT}[{GREEN}CallAdmin{DEFAULT}]";
public override int Version { get; set; } = 6;
[JsonPropertyName("ServerIpWithPort")]
public string ServerIpWithPort { get; set; } = "";
[JsonPropertyName("CooldownRefreshCommandSeconds")]
public int CooldownRefreshCommandSeconds { get; set; } = 60;
public int CooldownRefreshCommandSeconds { get; set; } = 30;
[JsonPropertyName("Reasons")]
public string Reasons { get; set; } = "Hack;Toxic;Camping;Your Custom Reason{CUSTOMREASON}";
[JsonPropertyName("WebHookUrl")]
public bool Debug { get; set; } = false;
[JsonPropertyName("Debug")]
public string WebHookUrl { get; set; } = "";
[JsonPropertyName("Debug")]
public bool Debug { get; set; } = false;
[JsonPropertyName("Database")]
public Database Database { get; set; } = new();
[JsonPropertyName("Commands")]
public Commands Commands { get; set; } = new();
[JsonPropertyName("ChatMessages")]
public ChatMessages ChatMessages { get; set; } = new();
[JsonPropertyName("EmbedMessages")]
public EmbedMessages EmbedMessages { get; set; } = new();
[JsonPropertyName("ChatMenuMessages")]
public ChatMenuMessages ChatMenuMessages { get; set; } = new();
}
public class Database
{
Expand Down Expand Up @@ -136,78 +77,5 @@ public class Commands

[JsonPropertyName("ReportHandledPermission")]
public string ReportHandledPermission { get; set; } = "@css/generic;@css/ban";

}
public class ChatMessages
{
[JsonPropertyName("MissingCommandPermission")]
public string MissingCommandPermission { get; set; } = "{DEFAULT}You don't have permission to use this command!";

[JsonPropertyName("NoPlayersAvailable")]
public string NoPlayersAvailable { get; set; } = "{DEFAULT}There are no players available";

[JsonPropertyName("InCoolDown")]
public string InCoolDown { get; set; } = "You are on a cooldown...wait {COOLDOWNSECONDS} seconds and try again";

[JsonPropertyName("ReportSent")]
public string ReportSent { get; set; } = "{DEFAULT}Your report has been sent to the admins!";

[JsonPropertyName("WebhookError")]
public string WebhookError { get; set; } = "{DEFAULT}There was an error sending the webhook";

[JsonPropertyName("InsertIntoDatabaseError")]
public string InsertIntoDatabaseError { get; set; } = "{DEFAULT}There was an error while inserting into database!";

[JsonPropertyName("ReportNotFound")]
public string ReportNotFound { get; set; } = "{DEFAULT}I couldn't find this report";

[JsonPropertyName("MarkedAsHandledButNotInDatabase")]
public string MarkedAsHandledButNotInDatabase { get; set; } = "{DEFAULT}This report has been marked as handled on Discord but not in database!";

[JsonPropertyName("ReportMarkedAsHandled")]
public string ReportMarkedAsHandled { get; set; } = "{DEFAULT}This report has been marked as handled!";
[JsonPropertyName("CustomReason")]
public string CustomReason { get; set; } = "{DEFAULT}Type the reason for the report";
}
public class EmbedMessages
{
[JsonPropertyName("Title")]
public string Title { get; set; } = "Report";
[JsonPropertyName("ColorReport")]
public int ColorReport { get; set; } = 16711680;
[JsonPropertyName("ColorReportHandled")]
public int ColorReportHandled { get; set; } = 65280;
[JsonPropertyName("Player")]
public string Player { get; set; } = "Player";
[JsonPropertyName("PlayerName")]
public string PlayerName { get; set; } = "Name";
[JsonPropertyName("PlayerSteamid")]
public string PlayerSteamid { get; set; } = "SteamID";
public string Suspect { get; set; } = "Suspect";
[JsonPropertyName("SuspectName")]
public string SuspectName { get; set; } = "Name";
[JsonPropertyName("SuspectSteamid")]
public string SuspectSteamid { get; set; } = "SteamID";
[JsonPropertyName("Admin")]
public string Admin { get; set; } = "Admin";
[JsonPropertyName("AdminName")]
public string AdminName { get; set; } = "Name";
[JsonPropertyName("AdminSteamid")]
public string AdminSteamid { get; set; } = "SteamID";
[JsonPropertyName("Reason")]
public string Reason { get; set; } = "Reason";
[JsonPropertyName("Ip")]
public string Ip { get; set; } = "Ip";
[JsonPropertyName("Map")]
public string Map { get; set; } = "Map";
[JsonPropertyName("Content")]
public string Content { get; set; } = "You can write anything here or leave it blank. Ping a member like this: <@MemberId> or a role: <@&RoleID>";
}
public class ChatMenuMessages
{
[JsonPropertyName("ReasonsTitle")]
public string ReasonsTitle { get; set; } = "[REPORT] Choose a Reason";
[JsonPropertyName("PlayersTitle")]
public string PlayersTitle { get; set; } = "[REPORT] Choose a Player";
}
}
8 changes: 4 additions & 4 deletions Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ private void TestDatabaseConnection()

if (connection.State != System.Data.ConnectionState.Open)
{
throw new Exception($"{Config.Prefix} Unable connect to database!");
throw new Exception($"{Localizer["Prefix"]} Unable connect to database!");
}
}
catch (Exception ex)
{
throw new Exception($"{Config.Prefix} Unknown mysql exception! " + ex.Message);
throw new Exception($"{Localizer["Prefix"]} Unknown mysql exception! " + ex.Message);
}
CheckDatabaseTables();
}
Expand All @@ -60,12 +60,12 @@ async private void CheckDatabaseTables()
{
await transaction.RollbackAsync();
await connection.CloseAsync();
throw new Exception($"{Config.Prefix} Unable to create tables!");
throw new Exception($"{Localizer["Prefix"]} Unable to create tables!");
}
}
catch (Exception ex)
{
throw new Exception($"{Config.Prefix} Unknown mysql exception! " + ex.Message);
throw new Exception($"{Localizer["Prefix"]} Unknown mysql exception! " + ex.Message);
}
}

Expand Down

0 comments on commit 7c5b52b

Please sign in to comment.