1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-06 17:53:13 +02:00

irc: fix duplicated CTCP messages displayed when capability "echo-message" is enabled (issue #139)

This commit is contained in:
Sébastien Helleu
2023-05-25 21:51:00 +02:00
parent 809f59dfd1
commit d9789e522f
19 changed files with 211 additions and 108 deletions
+4 -26
View File
@@ -35,6 +35,7 @@
#include "../weechat-plugin.h"
#include "irc.h"
#include "irc-command.h"
#include "irc-ctcp.h"
#include "irc-buffer.h"
#include "irc-channel.h"
#include "irc-color.h"
@@ -1909,36 +1910,13 @@ IRC_COMMAND_CALLBACK(ctcp)
if (ctcp_target)
{
irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"PRIVMSG %s :\01%s%s%s\01",
ctcp_target,
ctcp_type,
(ctcp_args) ? " " : "",
(ctcp_args) ? ctcp_args : "");
/* display message only if capability "echo-message" is NOT enabled */
if (!weechat_hashtable_has_key (ptr_server->cap_list, "echo-message"))
{
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (
ptr_server, ctcp_target, NULL, "ctcp", NULL),
0,
irc_protocol_tags (
ptr_server,
"privmsg",
NULL,
"irc_ctcp,self_msg,notify_none,no_highlight",
NULL, NULL),
_("%sCTCP query to %s%s%s: %s%s%s%s%s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (ptr_server, 0, NULL, ctcp_target),
ctcp_target,
IRC_COLOR_RESET,
IRC_COLOR_CHAT_CHANNEL,
ctcp_type,
IRC_COLOR_RESET,
(ctcp_args) ? " " : "",
(ctcp_args) ? ctcp_args : "");
irc_ctcp_display_send (ptr_server, ctcp_target, ctcp_type,
ctcp_args);
}
irc_ctcp_send (ptr_server, ctcp_target, ctcp_type, ctcp_args);
}
}
+47
View File
@@ -1255,3 +1255,50 @@ irc_ctcp_recv (struct t_irc_server *server, time_t date,
free (dup_arguments);
}
/*
* Displays an outgoing CTCP.
*/
void
irc_ctcp_display_send (struct t_irc_server *server,
const char *target, const char *type, const char *args)
{
weechat_printf_date_tags (
irc_msgbuffer_get_target_buffer (
server, target, NULL, "ctcp", NULL),
0,
irc_protocol_tags (
server,
"privmsg",
NULL,
"irc_ctcp,self_msg,notify_none,no_highlight",
NULL, NULL),
_("%sCTCP query to %s%s%s: %s%s%s%s%s"),
weechat_prefix ("network"),
irc_nick_color_for_msg (server, 0, NULL, target),
target,
IRC_COLOR_RESET,
IRC_COLOR_CHAT_CHANNEL,
type,
IRC_COLOR_RESET,
(args && args[0]) ? " " : "",
(args && args[0]) ? args : "");
}
/*
* Sends a CTCP to a target.
*/
void
irc_ctcp_send (struct t_irc_server *server,
const char *target, const char *type, const char *args)
{
irc_server_sendf (server,
IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL,
"PRIVMSG %s :\01%s%s%s\01",
target,
type,
(args) ? " " : "",
(args) ? args : "");
}
+6
View File
@@ -49,5 +49,11 @@ extern void irc_ctcp_recv (struct t_irc_server *server, time_t date,
const char *address, const char *nick,
const char *remote_nick, const char *arguments,
const char *message);
extern void irc_ctcp_display_send (struct t_irc_server *server,
const char *target, const char *type,
const char *args);
extern void irc_ctcp_send (struct t_irc_server *server,
const char *target, const char *type,
const char *args);
#endif /* WEECHAT_PLUGIN_IRC_CTCP_H */
+68 -12
View File
@@ -2947,6 +2947,48 @@ IRC_PROTOCOL_CALLBACK(pong)
return WEECHAT_RC_OK;
}
/*
* Displays a CTCP sent, that was received by PRIVMSG if the origin nick
* is self.
*
* Parameter "arguments" is the message arguments, for example:
*
* \01VERSION\01
* \01TEST some arguments\01
*/
void
irc_protocol_privmsg_display_ctcp_send (struct t_irc_server *server,
const char *target,
const char *arguments)
{
const char *pos_space, *pos_end;
char *ctcp_type, *ctcp_args;
if (!arguments || !arguments[0])
return;
pos_end = strchr (arguments + 1, '\01');
if (!pos_end)
return;
pos_space = strchr (arguments + 1, ' ');
ctcp_type = weechat_strndup (
arguments + 1,
(pos_space) ?
pos_space - arguments - 1 : pos_end - arguments - 1);
ctcp_args = (pos_space) ?
weechat_strndup (pos_space + 1, pos_end - pos_space - 1) : NULL;
irc_ctcp_display_send (server, target, ctcp_type, ctcp_args);
if (ctcp_type)
free (ctcp_type);
if (ctcp_args)
free (ctcp_args);
}
/*
* Callback for the IRC command "PRIVMSG".
*
@@ -2984,15 +3026,13 @@ IRC_PROTOCOL_CALLBACK(privmsg)
pos_target = params[0];
status_msg = 0;
is_channel = irc_channel_is_channel (server, pos_target);
if (!is_channel)
if (!is_channel
&& irc_channel_is_channel (server, pos_target + 1)
&& irc_server_prefix_char_statusmsg (server, pos_target[0]))
{
if (irc_channel_is_channel (server, pos_target + 1)
&& irc_server_prefix_char_statusmsg (server, pos_target[0]))
{
is_channel = 1;
status_msg = 1;
pos_target++;
}
is_channel = 1;
status_msg = 1;
pos_target++;
}
/* receiver is a channel ? */
@@ -3010,8 +3050,16 @@ IRC_PROTOCOL_CALLBACK(privmsg)
/* CTCP to channel */
if (msg_args[0] == '\01')
{
irc_ctcp_recv (server, date, tags, command, ptr_channel,
address, nick, NULL, msg_args, irc_message);
if (nick_is_me)
{
irc_protocol_privmsg_display_ctcp_send (server, pos_target,
msg_args);
}
else
{
irc_ctcp_recv (server, date, tags, command, ptr_channel,
address, nick, NULL, msg_args, irc_message);
}
goto end;
}
@@ -3106,8 +3154,16 @@ IRC_PROTOCOL_CALLBACK(privmsg)
/* CTCP to user */
if (msg_args[0] == '\01')
{
irc_ctcp_recv (server, date, tags, command, NULL,
address, nick, remote_nick, msg_args, irc_message);
if (nick_is_me)
{
irc_protocol_privmsg_display_ctcp_send (server, remote_nick,
msg_args);
}
else
{
irc_ctcp_recv (server, date, tags, command, NULL,
address, nick, remote_nick, msg_args, irc_message);
}
goto end;
}