diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-31 18:37:27 +0100 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-01-31 18:37:27 +0100 |
commit | 9f5ca3b1a9fbf891d7450d6191c6f16818ea9ebe (patch) | |
tree | c2475f87357351e1856ec78d8cd20a59cdbb11b4 /src/plugins | |
parent | 4c0d2ab3b16c3ffa99b063671fa3fb0f4ef78d68 (diff) | |
download | weechat-9f5ca3b1a9fbf891d7450d6191c6f16818ea9ebe.zip |
irc: add command `/knock` (closes #7)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-command.c | 38 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 87 |
2 files changed, 124 insertions, 1 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 1620953ac..c48a2fbc5 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -3258,6 +3258,36 @@ IRC_COMMAND_CALLBACK(kill) } /* + * Callback for command "/knock": sends a notice to an invitation-only channel, + * requesting an invite. + */ + +IRC_COMMAND_CALLBACK(knock) +{ + IRC_BUFFER_GET_SERVER(buffer); + IRC_COMMAND_CHECK_SERVER("knock", 1, 1); + + /* make C compiler happy */ + (void) pointer; + (void) data; + + WEECHAT_COMMAND_MIN_ARGS(2, ""); + + if (argc < 3) + { + irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "KNOCK %s", argv[1]); + } + else + { + irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "KNOCK %s :%s", argv[1], argv_eol[2]); + } + + return WEECHAT_RC_OK; +} + +/* * Callback for command "/links": lists all server names which are known by the * server answering the query. */ @@ -7148,6 +7178,14 @@ irc_command_init () "reason: reason"), "%(nicks) %-", &irc_command_kill, NULL, NULL); weechat_hook_command ( + "knock", + N_("send a notice to an invitation-only channel, requesting an invite"), + N_("<channel> [<message>]"), + N_("channel: channel name\n" + "message: message to send"), + "%(irc_channels)", + &irc_command_knock, NULL, NULL); + weechat_hook_command ( "links", N_("list all server names which are known by the server answering the " "query"), diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index a4eba464d..e9e430cf4 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -348,7 +348,7 @@ irc_protocol_string_params (const char **params, int arg_start, int arg_end) * * Called by callbacks for commands: FAIL, WARN, NOTE. * - * Commands looks like: + * Commands look like: * FAIL * NEED_REGISTRATION :You need to be registered to continue * FAIL ACC REG_INVALID_CALLBACK REGISTER :Email address is not valid * FAIL BOX BOXES_INVALID STACK CLOCKWISE :Given boxes are not supported @@ -1921,6 +1921,41 @@ IRC_PROTOCOL_CALLBACK(kill) } /* + * Callback for an IRC KNOCK reply. + * + * Commands look like: + * 711 nick #channel :Your KNOCK has been delivered. + * 712 nick #channel :Too many KNOCKs (channel). + * 713 nick #channel :Channel is open. + * 714 nick #channel :You are already on that channel. + */ + +IRC_PROTOCOL_CALLBACK(knock_reply) +{ + char *str_message; + + IRC_PROTOCOL_MIN_PARAMS(3); + + str_message = irc_protocol_string_params (params, 2, num_params - 1); + + weechat_printf_date_tags ( + irc_msgbuffer_get_target_buffer (server, params[0], command, NULL, NULL), + date, + irc_protocol_tags (command, tags, NULL, NULL, NULL), + "%s%s%s%s: %s", + weechat_prefix ("network"), + IRC_COLOR_CHAT_CHANNEL, + params[1], + IRC_COLOR_RESET, + str_message); + + if (str_message) + free (str_message); + + return WEECHAT_RC_OK; +} + +/* * Callback for the IRC command "MODE". * * Command looks like: @@ -6825,6 +6860,51 @@ IRC_PROTOCOL_CALLBACK(help) } /* + * Callback for the IRC command "710": has asked for an invite (knock). + * + * Command looks like: + * 710 #channel #channel nick!user@host :has asked for an invite. + */ + +IRC_PROTOCOL_CALLBACK(710) +{ + struct t_irc_channel *ptr_channel; + const char *nick_address; + char *str_message; + + IRC_PROTOCOL_MIN_PARAMS(3); + + if (ignored) + return WEECHAT_RC_OK; + + ptr_channel = irc_channel_search (server, params[1]); + if (!ptr_channel) + return WEECHAT_RC_ERROR; + + nick_address = irc_protocol_nick_address ( + server, 1, NULL, irc_message_get_nick_from_host (params[2]), + irc_message_get_address_from_host (params[2])); + + str_message = irc_protocol_string_params (params, 3, num_params - 1); + + weechat_printf_date_tags ( + irc_msgbuffer_get_target_buffer ( + server, NULL, command, NULL, ptr_channel->buffer), + date, + irc_protocol_tags (command, tags, "notify_message", NULL, NULL), + "%s%s %s", + weechat_prefix ("network"), + (nick_address[0]) ? nick_address : "?", + (str_message && str_message[0]) ? + str_message : _("has asked for an invite")); + + if (str_message) + free (str_message); + + return WEECHAT_RC_OK; +} + +/* * Callback for the IRC command "728": quietlist. * * Command looks like: @@ -7500,6 +7580,11 @@ irc_protocol_recv_command (struct t_irc_server *server, IRCB(704, 1, 0, help), /* start of HELP/HELPOP */ IRCB(705, 1, 0, help), /* body of HELP/HELPOP */ IRCB(706, 1, 0, help), /* end of HELP/HELPOP */ + IRCB(710, 1, 0, 710), /* knock: has asked for an invite */ + IRCB(711, 1, 0, knock_reply), /* knock: has been delivered */ + IRCB(712, 1, 0, knock_reply), /* knock: too many knocks */ + IRCB(713, 1, 0, knock_reply), /* knock: channel is open */ + IRCB(714, 1, 0, knock_reply), /* knock: already on that channel */ IRCB(728, 1, 0, 728), /* quietlist */ IRCB(729, 1, 0, 729), /* end of quietlist */ IRCB(730, 1, 0, 730), /* monitored nicks online */ |