Concord - C Discord API library
A Discord API wrapper library written in C

The Message Commands API for registering and parsing user commands. More...

Collaboration diagram for Message Commands API:

Data Structures

struct  discord_message_commands
 The handle for storing user's message commands. More...
 

Functions

void discord_message_commands_init (struct discord_message_commands *cmds, struct logconf *conf)
 Initialize a Message Commands handle. More...
 
void discord_message_commands_cleanup (struct discord_message_commands *cmds)
 Free a Message Commands handle. More...
 
discord_ev_message discord_message_commands_find (struct discord_message_commands *cmds, const char command[], size_t length)
 Search for a callback matching the command. More...
 
void discord_message_commands_append (struct discord_message_commands *cmds, const char command[], size_t length, discord_ev_message callback)
 Add a new command/callback pair, or update an existing command. More...
 
void discord_message_commands_set_prefix (struct discord_message_commands *cmds, const char prefix[], size_t length)
 Set a mandatory prefix before commands. More...
 
bool discord_message_commands_try_perform (struct discord_message_commands *cmds, struct discord_gateway_payload *payload)
 Read the current DISCORD_EV_MESSAGE_CREATE payload and attempt to perform its matching callback. More...
 

Detailed Description

The Message Commands API for registering and parsing user commands.

Function Documentation

◆ discord_message_commands_init()

void discord_message_commands_init ( struct discord_message_commands cmds,
struct logconf conf 
)

Initialize a Message Commands handle.

Parameters
cmdsthe message commands handle to be initialized
confpointer to discord logging module

◆ discord_message_commands_cleanup()

void discord_message_commands_cleanup ( struct discord_message_commands cmds)

Free a Message Commands handle.

Parameters
cmdsthe handle initialized with discord_message_commands_init()

◆ discord_message_commands_find()

discord_ev_message discord_message_commands_find ( struct discord_message_commands cmds,
const char  command[],
size_t  length 
)

Search for a callback matching the command.

Parameters
cmdsthe handle initialized with discord_message_commands_init()
commandthe command to be searched for
lengththe command length
Returns
the callback match, NULL in case there wasn't a match

◆ discord_message_commands_append()

void discord_message_commands_append ( struct discord_message_commands cmds,
const char  command[],
size_t  length,
discord_ev_message  callback 
)

Add a new command/callback pair, or update an existing command.

Parameters
cmdsthe handle initialized with discord_message_commands_init()
commandthe message command to be matched with callback
lengththe command length
callbackthe callback to be triggered when the command is sent

◆ discord_message_commands_set_prefix()

void discord_message_commands_set_prefix ( struct discord_message_commands cmds,
const char  prefix[],
size_t  length 
)

Set a mandatory prefix before commands.

See also
discord_set_on_command()

Example: If 'help' is a command and '!' prefix is set, the command will only be validated if '!help' is sent

Parameters
cmdsthe handle initialized with discord_message_commands_init()
prefixthe mandatory command prefix
lengththe prefix length

◆ discord_message_commands_try_perform()

bool discord_message_commands_try_perform ( struct discord_message_commands cmds,
struct discord_gateway_payload payload 
)

Read the current DISCORD_EV_MESSAGE_CREATE payload and attempt to perform its matching callback.

Parameters
cmdsthe handle initialized with discord_message_commands_init()
payloadthe event payload to read from (assumes its from MESSAGE_CREATE)
Returns
true if the callback has been performed