Beispiel #1
0
        /// <summary>
        /// Responds to command call
        /// </summary>
        /// <param name="sender">User who sent the command</param>
        /// <param name="message">String command message send by user</param>
        private void RespondToCommand(User sender, string message)
        {
            // TODO: Fix this parsing and make it more efficient
            var command = _commandsHandler.CommandsList.FirstOrDefault(cmd =>
            {
                List <string> parsedMessageCommand = message.Split(' ').ToList();
                string messageCmdName = parsedMessageCommand.FirstOrDefault();
                int commandArgs       = cmd.CommandFormat.Split(' ').Count();

                return(cmd.CommandFormat.Contains(messageCmdName) && parsedMessageCommand.Count == commandArgs);
            });

            if (command != null)
            {
                if (!command.VerifyFormat(message))
                { // Check permission, if user doesn't have permission, don't send anything
                    // FIX: Inform user about wrong command structure?
                    //DeliverCommandResults(command, command.CheckCommandPermissions(sender) ? command.GetAboutInfoMessage() : "", sender);
                    return;
                }

                string commandResult = _commandsHandler.ExecuteCommand(command, sender, Parsing.ParseCommandValues(message));
                OnCommandReceived?.Invoke(this, new OnCommandReceivedArgs {
                    Command = command
                });
                DeliverCommandResults(command, commandResult, sender);
            }
        }