Skip to content

Commit bbd552f

Browse files
committed
Change type of CommandPrefix to be pseudo-char (string ensured to be length 1)
1 parent 68850c6 commit bbd552f

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

Nuclei/Features/ChatService.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ private static bool CanSend(string message, bool ignoreEmpty = false, bool ignor
4242
/// <returns> The sanitized message. </returns>
4343
private static string SanitizeMessage(this string message)
4444
{
45-
var prefix = NucleiConfig.CommandPrefix!.Value;
46-
while(message.StartsWith(prefix))
47-
message = message.Substring(prefix.Length - 1);
48-
return message;
45+
return message.TrimStart(NucleiConfig.CommandPrefixChar);
4946
}
5047

5148
/// <summary>

Nuclei/Features/NucleiConfig.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public static class NucleiConfig
8989
internal static List<string> BannedPlayersList => BannedPlayers!.Value.Split(';').Where(b => !string.IsNullOrWhiteSpace(b)).ToList();
9090

9191
internal static List<string> MissionsList => Missions!.Value.Split(';').Where(m => !string.IsNullOrWhiteSpace(m)).ToList();
92+
93+
internal static char CommandPrefixChar => CommandPrefix!.Value[0];
9294

9395
internal static void InitSettings(ConfigFile config)
9496
{
@@ -157,7 +159,7 @@ internal static void InitSettings(ConfigFile config)
157159
UseAllMissions = config.Bind(GeneralSection, "UseAllMissions", DefaultUseAllMissions, "Whether to use all missions available to the client (including tutorials, workshop items, custom missions, etc...) for mission selection. If false, only the missions in the config will be used.");
158160
Nuclei.Logger?.LogDebug($"UseAllMissions: {UseAllMissions.Value}");
159161

160-
CommandPrefix = config.Bind(GeneralSection, "CommandPrefix", DefaultCommandPrefix, "What to use as the command prefix (the string that needs to be at the start of a command to be seen as one).");
162+
CommandPrefix = config.Bind(GeneralSection, "CommandPrefix", DefaultCommandPrefix, "What to use as the command prefix (the character at the start of a command).");
161163
Nuclei.Logger?.LogDebug($"CommandPrefix: {CommandPrefix.Value}");
162164

163165
Nuclei.Logger?.LogDebug("Loaded settings!");
@@ -203,9 +205,9 @@ internal static void ValidateSettings()
203205
TargetFrameRate.Value = -1;
204206
}
205207

206-
if (CommandPrefix!.Value.Length == 0)
208+
if (CommandPrefix!.Value.Length != 1)
207209
{
208-
Nuclei.Logger?.LogWarning("CommandPrefix must not be empty! Resetting to default value.");
210+
Nuclei.Logger?.LogWarning("CommandPrefix must be a single character! Resetting to default value.");
209211
CommandPrefix.Value = DefaultCommandPrefix;
210212
}
211213

Nuclei/Patches/ChatManagerPatches.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private static bool UserCode_CmdSendChatMessage_1323305531Prefix(string message,
1818
if (!sender.TryGetPlayer(out var player))
1919
Nuclei.Logger?.LogWarning("Player component is null");
2020

21-
if (message.StartsWith(NucleiConfig.CommandPrefix!.Value) && message.Length > NucleiConfig.CommandPrefix!.Value.Length)
21+
if (message.StartsWith(NucleiConfig.CommandPrefix!.Value) && message.Length > 1)
2222
if (CommandService.TryExecuteCommand(player!, message.Remove(0, 1)))
2323
return false;
2424

0 commit comments

Comments
 (0)