diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-info.c | 46 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.c | 52 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-protocol.c | 3 |
4 files changed, 102 insertions, 1 deletions
diff --git a/src/plugins/irc/irc-info.c b/src/plugins/irc/irc-info.c index b0315034e..96974fcbc 100644 --- a/src/plugins/irc/irc-info.c +++ b/src/plugins/irc/irc-info.c @@ -401,6 +401,47 @@ irc_info_info_irc_server_isupport_value_cb (const void *pointer, void *data, } /* + * Returns IRC info "irc_is_message_ignored". + */ + +char * +irc_info_info_irc_is_message_ignored_cb (const void *pointer, void *data, + const char *info_name, + const char *arguments) +{ + char *pos_comma, *server; + const char *pos_message; + struct t_irc_server *ptr_server; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) info_name; + + if (!arguments || !arguments[0]) + return NULL; + + ptr_server = NULL; + pos_message = arguments; + pos_comma = strchr (arguments, ','); + if (!pos_comma) + return NULL; + + pos_message = pos_comma + 1; + server = weechat_strndup (arguments, pos_comma - arguments); + if (server) + { + ptr_server = irc_server_search (server); + free (server); + } + if (!ptr_server) + return NULL; + + return (irc_message_ignored (ptr_server, pos_message)) ? + strdup ("1") : NULL; +} + +/* * Returns IRC info with hashtable "irc_message_parse". */ @@ -1129,6 +1170,11 @@ irc_info_init () N_("value of feature, if supported by server (from IRC message 005)"), N_("server,feature"), &irc_info_info_irc_server_isupport_value_cb, NULL, NULL); + weechat_hook_info ( + "irc_is_message_ignored", + N_("1 if the nick is ignored (message is not displayed)"), + N_("server,message (message is the raw IRC message)"), + &irc_info_info_irc_is_channel_cb, NULL, NULL); /* info_hashtable hooks */ weechat_hook_info_hashtable ( diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index 5c27b40dd..36341defd 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -27,7 +27,9 @@ #include "../weechat-plugin.h" #include "irc.h" #include "irc-channel.h" +#include "irc-color.h" #include "irc-config.h" +#include "irc-ignore.h" #include "irc-server.h" @@ -539,6 +541,56 @@ irc_message_get_address_from_host (const char *host) } /* + * Checks if a raw message is ignored (nick ignored on this server/channel). + * + * Returns: + * 0: message not ignored (displayed) + * 1: message ignored (not displayed) + */ + +int +irc_message_ignored (struct t_irc_server *server, const char *message) +{ + char *nick, *host, *host_no_color, *channel; + struct t_irc_channel *ptr_channel; + int ignored; + + if (!server || !message) + return 0; + + /* parse raw message */ + irc_message_parse (server, message, + NULL, NULL, &nick, NULL, &host, + NULL, &channel, NULL, + NULL, NULL, NULL, + NULL, NULL); + + /* remove colors from host */ + host_no_color = (host) ? irc_color_decode (host, 0) : NULL; + + /* search channel */ + ptr_channel = (channel) ? irc_channel_search (server, channel) : NULL; + + /* check if message is ignored or not */ + ignored = irc_ignore_check ( + server, + (ptr_channel) ? ptr_channel->name : channel, + nick, + host_no_color); + + if (nick) + free (nick); + if (host) + free (host); + if (host_no_color) + free (host_no_color); + if (channel) + free (channel); + + return ignored; +} + +/* * Replaces special IRC vars ($nick, $channel, $server) in a string. * * Note: result must be freed after use. diff --git a/src/plugins/irc/irc-message.h b/src/plugins/irc/irc-message.h index 69b75778d..5b118128b 100644 --- a/src/plugins/irc/irc-message.h +++ b/src/plugins/irc/irc-message.h @@ -38,6 +38,8 @@ extern char *irc_message_convert_charset (const char *message, const char *modifier_data); extern const char *irc_message_get_nick_from_host (const char *host); extern const char *irc_message_get_address_from_host (const char *host); +extern int irc_message_ignored (struct t_irc_server *server, + const char *message); extern char *irc_message_replace_vars (struct t_irc_server *server, const char *channel_name, const char *string); diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c index 9713a6a49..5be5796f4 100644 --- a/src/plugins/irc/irc-protocol.c +++ b/src/plugins/irc/irc-protocol.c @@ -6679,7 +6679,8 @@ irc_protocol_recv_command (struct t_irc_server *server, message_ignored = irc_ignore_check ( server, (ptr_channel) ? ptr_channel->name : msg_channel, - nick, host_no_color); + nick, + host_no_color); /* send signal with received command, even if command is ignored */ irc_server_send_signal (server, "irc_raw_in", msg_command, |