Skip to content

Implement a command handler #2

@DrFrankenstein

Description

@DrFrankenstein

Who: Bot users.
When: A command is posted in chat.
What: Parses the command and finds a suitable handler for it.
Why: So that the bot can accept commands from users.
Points: 5

Acceptance Criteria

  • Detects all messages starting with the trigger.
    • That trigger is configured under the "trigger" key of the config file.
  • Allows modules to register commands with names and hanglers.
  • Looks for and calls that handler when the command is posted in chat.

Example

  • Config file contains: trigger: "!".
  • A user posts !roll d6.
    The bot should find a command handler for roll and call it with argument d6.

Technical discussion

A command record should contain:

  • The command name
  • The number of arguments
  • A pointer to the handler to call.

When parsing the command, arguments would be split on whitespace until the argument count is reached. If more whitespace is found, it becomes part of the last argument. For example, if command addquote takes 2 arguments, then !addquote somedude My password is hunter2 would be parsed as

command: "addquote"
arguments: ["somedude", "My password is hunter2"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    botIssues targeting the bot moduleenhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions