Skip to content
Permalink
Browse files

Update tagmsg to accept dicts

  • Loading branch information
vanosg committed Jan 21, 2020
1 parent b504c15 commit 91e70543abfa728f63cd6a4883f401ea078d93ca
Showing with 27 additions and 11 deletions.
  1. +10 −4 doc/sphinx_source/mainDocs/tcl-commands.rst
  2. +0 −2 src/mod/server.mod/servmsg.c
  3. +17 −5 src/mod/server.mod/tclserv.c
@@ -165,10 +165,14 @@ cap <active/available/raw> [arg]
Module: server

^^^^^^^^^^^^^^^^^^^^^^^^^^^^
tagmsg <tag string> <target>
tagmsg <tags> <target>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Description: sends an IRCv3 TAGMSG command to the target. Only works if message-tags as been negotiated with the server via the cap command. tag string is a single string containing the tags you wish to send separated by commas (do not include the @prefix), and target is the nickname or channel you wish to send the tags to.
Description: sends an IRCv3 TAGMSG command to the target. Only works if message-tags has been negotiated with the server via the cap command. tags is a Tcl dict (or space-separated string) of the tags you wish to send separated by commas (do not include the @prefix), and target is the nickname or channel you wish to send the tags to. To send a tag only (not a key/value pair), use a "" as the value for a key in a dict, or a "{}" if you are sending as a space-separated string.

Examples:
set mytags [dict create +foo bar moo baa +last ""]; tagmsg $mytags #channel
tagmsg "+foo bar moo baa +last {}" #channel

Returns: nothing

@@ -2945,7 +2949,9 @@ The following is a list of bind types and how they work. Below each bind type is

procname <from> <keyword> <text>

Description: previous versions of Eggdrop required a special compile option to enable this binding, but it's now standard. The keyword is either a numeric, like "368", or a keyword, such as "PRIVMSG". "from" will be the server name or the source user (depending on the keyword); flags are ignored. The order of the arguments is identical to the order that the IRC server sends to the bot. The pre-processing only splits it apart enough to determine the keyword. If the proc returns 1, Eggdrop will not process the line any further (this could cause unexpected behavior in some cases). RAW and RAWT binds are exclusive; RAW binds will only trigger if the IRCv3 message-tags capability is not negotiated with the server.
IMPORTANT: While not necessarily deprecated, this bind has been supplanted by the RAWT bind as of 1.9.0. You probably want to be using RAWT, not RAW.

Description: previous versions of Eggdrop required a special compile option to enable this binding, but it's now standard. The keyword is either a numeric, like "368", or a keyword, such as "PRIVMSG". "from" will be the server name or the source user (depending on the keyword); flags are ignored. The order of the arguments is identical to the order that the IRC server sends to the bot. The pre-processing only splits it apart enough to determine the keyword. If the proc returns 1, Eggdrop will not process the line any further (this could cause unexpected behavior in some cases). The RAW bind does not support the IRCv3 message-tags capability, please see RAWT for more information.

Module: server

@@ -3304,7 +3310,7 @@ The following is a list of bind types and how they work. Below each bind type is

procname <from> <keyword> <text> <tag>

Description: triggered when a raw message of type keyword that includes an IRCv3 message-tag is processed by Eggdrop. RAW and RAWT binds are exclusive; RAWT binds will only trigger if the IRCv3 message-tags capability is not negotiated with the server. The keyword is either a numeric, like "368", or a keyword, such as "PRIVMSG". "from" will be the server name or the source user (depending on the keyword); flags are ignored. "tag" will be the contents of the entire tag message prefixed to the server message, such as "msgid=890~1572172797~68;aaa=bbb". The order of the arguments is identical to the order that the IRC server sends to the bot. If the proc returns 1, Eggdrop will not process the line any further (this could cause unexpected behavior in some cases).
Description: similar to the RAW bind, but allows an extra field for the IRCv3 message-tags capability. The keyword is either a numeric, like "368", or a keyword, such as "PRIVMSG" or "TAGMSG". "from" will be the server name or the source user (depending on the keyword); flags are ignored. "tag" will be the contents, if any, of the entire tag message prefixed to the server message in a dict format, such as "msgid 890157217279768 aaa bbb". The order of the arguments is identical to the order that the IRC server sends to the bot. If the proc returns 1, Eggdrop will not process the line any further (this could cause unexpected behavior in some cases). As of 1.9.0, it is recommended to use the RAWT bind instead of the RAW bind.

^^^^^^^^^^^^^
Return Values
@@ -1114,8 +1114,6 @@ static void server_activity(int idx, char *tagmsg, int len)
strncpy(tagstr, tagmsg, TOTALTAGMAX);
tagstrptr = strtok_r(tagmsg, " ", &msgptr);
tagstrptr++; /* Remove @ */
putlog(LOG_DEBUG, "*", "Found message-tag %s on msg %s",
tagstrptr, msgptr);
/* Split each key/value pair apart, then split the key from the value */
for (i = 0, s1 = tagstrptr; ; i++, s1 = NULL){
token = strtok_r(s1, ";", &saveptr1);
@@ -164,20 +164,32 @@ static int tcl_puthelp STDVAR

/* Send a msg to the server prefixed with an IRCv3 message-tag */
static int tcl_tagmsg STDVAR {
char tag[CLITAGMAX];
char tag[CLITAGMAX-9]; /* minus @, TAGMSG and two spaces */
char tagdict[CLITAGMAX-9];
char target[MSGMAX];
char *p;
int taglen = 0, i = 1;
BADARGS(3, 3, " tag target");

if (!msgtag) {
Tcl_AppendResult(irp, "message-tags not enabled, cannot send tag", NULL);
return TCL_ERROR;
}
strlcpy(tag, argv[1], sizeof tag);
strlcpy(tagdict, argv[1], sizeof tag);
strlcpy(target, argv[2], sizeof target);
if (*tag == '@') {
Tcl_AppendResult(irp, "tag cannot be prefixed with @", NULL);
return TCL_ERROR;
p = strtok(tagdict, " ");
while (p != NULL) {
if ((i % 2) != 0) {
taglen += egg_snprintf(tag + taglen, CLITAGMAX - 9 - taglen, "%s", p);
} else {
if (strcmp(p, "{}") != 0) {
taglen += egg_snprintf(tag + taglen, CLITAGMAX - 9 - taglen, "=%s;", p);
} else {
taglen += egg_snprintf(tag + taglen, CLITAGMAX - 9 - taglen, ";");
}
}
i++;
p = strtok(NULL, " ");
}
p = strchr(target, '\n');
if (p != NULL)

0 comments on commit 91e7054

Please sign in to comment.
You can’t perform that action at this time.