mirror of
https://github.com/weechat/weechat.git
synced 2026-07-10 11:43:13 +02:00
irc: add info "irc_is_message_ignored"
This commit is contained in:
@@ -400,6 +400,47 @@ irc_info_info_irc_server_isupport_value_cb (const void *pointer, void *data,
|
||||
return (isupport_value) ? strdup (isupport_value) : NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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 (
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
@@ -538,6 +540,56 @@ irc_message_get_address_from_host (const char *host)
|
||||
return address;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user