public static bool Is(this ServerCommand serverCommand, CommandInfo commandInfo) { if (serverCommand == null || commandInfo == null) return false; // remove last expression to allow commands requiring a prefix to work withput prefix return commandInfo.ContaisCommandName(serverCommand.MainCommand) && commandInfo.Options.RequiresPrefix == serverCommand.HasCommandPrefix; }
public static bool IsAny(this ServerCommand serverCommand, params CommandInfo[] commandInfoList) { if (commandInfoList == null || commandInfoList.Length == 0) return false; foreach (CommandInfo commandInfo in commandInfoList) { if (serverCommand.Is(commandInfo)) return true; } return false; }
public static bool IsAny(this ServerCommand serverCommand, params Command[] commands) { if (commands == null || commands.Length == 0) return false; foreach (Command command in commands) { if (serverCommand.Is(command)) return true; } return false; }
public static ServerCommand Parse(string chatMessage) { if (chatMessage == null) return null; if (!chatMessage.StartsWith("/")) return null; string originalMessage = chatMessage; bool hasCommandPrefix = TrimmCommandPrefix(chatMessage, out chatMessage); string[] commandParts = chatMessage.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (commandParts.Length == 0) return null; ServerCommand result = new ServerCommand { OriginalText = originalMessage, CommandText = chatMessage, MainCommand = commandParts[0], HasCommandPrefix = hasCommandPrefix }; List<string> parts = new List<string>(); List<string> partsWithoutMainCommand = new List<string>(); for (int i = 0; i < commandParts.Length; i++ ) { parts.Add(commandParts[i]); if (i > 0) partsWithoutMainCommand.Add(commandParts[i]); } result.Parts = parts.AsReadOnly(); result.PartsWithoutMainCommand = partsWithoutMainCommand.AsReadOnly(); return result; }
public static bool Is(this ServerCommand serverCommand, Command command) { return Is(serverCommand, CommandInfo.Parse(command)); }