Syntax
Since the list of supported commands and the exact syntax for each command is application specific, IrcCommandParser does not provide any built-in command syntaxes. It is left up to the applications to introduce the supported commands and syntaxes. IrcCommandParser supports the following command syntax markup:
Syntax | Example | Description |
<param> | <target> | A required parameter. |
(<param>) | (<key>) | An optional parameter. |
<param...> | <message...> | A required parameter, multiple words accepted. (1) |
(<param...>) | (<message...>) | An optional parameter, multiple words accepted. (1) |
(<#param>) | (<#channel>) | An optional channel parameter. (2) |
[param] | [target] | Inject the current target. |
- Multi-word parameters are only supported in the last parameter position.
- An optional channel parameter is filled up with the current channel when absent.
The following example presents introducing some typical commands.
- Note
- The parameter names are insignificant, but descriptive parameter names are recommended for the sake of readability.
Context
Notice that commands are often context sensitive. While some command may accept an optional parameter that is filled up with the current target (channel/query) name when absent, another command may always inject the current target name as a certain parameter. Therefore IrcCommandParser must be kept up-to-date with the current target and the list of channels.
parser->setTarget("jpnurmi");
parser->setChannels(
QStringList() <<
"#communi" <<
"#freenode");
Command triggers
IrcCommandParser serves as a generic parser for typical IRC commands. It can be utilized for parsing commands from user input in GUI clients, and from messages from other clients when implementing IRC bots.
The command parsing behavior is controlled by setting up command triggers. Whilst a typical GUI client might use "/"
as a command trigger, an IRC bot might use "!"
and the nick name of the bot. The following snippet illustrates a typical GUI client usage.
parser->setTarget("#communi");
Input | Result | Description |
"hello" | IrcCommand::Message | No matching command trigger => a message "hello" to #communi |
"/join #channel" | IrcCommand::Join | Matching command trigger => a command to join "#channel" |
See the bot example to see how the parser can be effectively utilized for IRC bots.
Custom commands
The parser also supports such custom client specific commands that are not sent to the server. Since IrcCommand does not know how to handle custom commands, the parser treats them as a special case injecting the command as a first parameter.
IrcParser parser;
IrcCommand* command = parser.parse(
"/query jpnurmi");