-
Notifications
You must be signed in to change notification settings - Fork 3
Tags
Tags are an optional part of an IRC message. If present, they are the first part of a message and prefixed with an @
. They come as a string of key-value pairs and contain meta data for the message. Depending on the type of message, different kind of tags can be present. Here is an example for a message with tags:
@badges=;color=#DAA520;display-name=domsson;emotes=;message-id=2;thread-id=1234_5678;turbo=0;user-id=123456;user-type= :[email protected] WHISPER kaulmate :hey kaul!
If a message contains tags, these will be handed to your callback function as the char **tags
member within the twirc_event_t *evt
struct, where twirc_event_t
has two members, key
and value
. The value
will point to an empty string if the tag did not have a value, as for example the badges
tag in the example message above.
In your event handler, you can use the twirc_get_tag()
function to extract a specified tag if that tag was present. If there was no tag with the specified key, it will return NULL
. Example:
void handle_whisper(twirc_state_t *s, twirc_event_t *evt)
{
twirc_tag_t *display_name = twirc_get_tag(evt->tags, "display-name");
twirc_tag_t *message_id = twirc_get_tag(evt->tags, "message-id");
fprintf(stdout, "*** Whisper from %s (message id %s): %s\n",
display_name == NULL ? evt->origin : display_name->value,
message_id == NULL ? "n/a" : message_id->value,
evt->message);
}
The signature of the method is as follows:
twirc_tag_t *twirc_get_tag(twirc_tag_t **tags, const char *key);
Alternatively, as a short-cut, you can use twirc_get_tag_value()
, which will give you the pointer to the requested tag's value directly, saving you a line of code. Again, if the specified tag does not exist, NULL
will be returned. The signature is as follows:
char const *twirg_get_tag_value(twirc_tag_t **tags, const char *key);