Skip to content

Commit a622cfa

Browse files
committed
Add chat command prefix helper
Implement chat command prefix in covalence command handler
1 parent b66459a commit a622cfa

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/Libraries/Covalence/CommandHandler.cs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,24 @@ public CommandHandler(CommandCallback callback, Func<string, bool> commandFilter
2626
this.commandFilter = commandFilter;
2727
}
2828

29+
/// <summary>
30+
/// Returns chat command prefix if the message is a chat command
31+
/// </summary>
32+
/// <param name="message"></param>
33+
/// <returns></returns>
34+
public static string GetChatCommandPrefix(string message)
35+
{
36+
foreach (string prefix in Interface.Oxide.Config.Commands.ChatPrefix)
37+
{
38+
if (message.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
39+
{
40+
return prefix;
41+
}
42+
}
43+
44+
return null;
45+
}
46+
2947
/// <summary>
3048
/// Handles a chat message from the specified player, returns true if handled
3149
/// </summary>
@@ -40,13 +58,14 @@ public bool HandleChatMessage(IPlayer player, string message)
4058
}
4159

4260
// Is it a chat command?
43-
if (message[0] != '/')
61+
string chatCommandPrefix = GetChatCommandPrefix(message);
62+
if ( chatCommandPrefix == null )
4463
{
4564
return false;
4665
}
4766

48-
// Get the message
49-
message = message.Substring(1);
67+
// Remove the prefix from the message
68+
message = message.Substring(chatCommandPrefix.Length);
5069

5170
// Parse the command
5271
ParseCommand(message, out string command, out string[] args);

0 commit comments

Comments
 (0)