private string ProcessSlashCommand(ChatState userState, ISessionData session, ISocketClient client, ref byte[] bytes)
        {
            byte[]        tmpBytes;
            ISlashCommand command = null;

            foreach (var cmd in userState.Commands)
            {
                tmpBytes = cmd.Identifier;
                if (bytes.IndexOfSequence(ref tmpBytes) > -1)
                {
                    command = cmd;
                }
            }

            if (command != null)
            {
                var content = bytes.Skip(command.Identifier.Length)
                              .Take(bytes.Length - command.Identifier.Length)
                              .ToArray();

                command.Execute(ref content, _serverState, session, client);
                return(string.Empty);
            }

            return("Invalid slash command.");
        }
        public static void Parse(MainWindow window, string value)
        {
            value = value.Trim();
            string command = value.Substring(1);
            string args    = null;

            // Check if command contains arguments
            if (value.IndexOf(' ') > -1)
            {
                command = value.Substring(1, value.IndexOf(' ') - 1);
                args    = value.Substring(value.IndexOf(' ') + 1);
            }

            // Check if command exists
            ISlashCommand cmd = SlashCommandRegistry.GetHandler(command);

            if (cmd == null)
            {
                ClientMessage.Info($"Unknown command '{command}'");
                return;
            }

            cmd.Run(args);
        }
Beispiel #3
0
 public static void RegisterHandler(string command, ISlashCommand handler)
 {
     command = command.ToLower();
     Commands.Add(command, handler);
 }