summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-config.c10
-rw-r--r--src/plugins/irc/irc-config.h1
-rw-r--r--src/plugins/irc/irc-mode.c69
-rw-r--r--src/plugins/irc/irc-mode.h6
-rw-r--r--src/plugins/irc/irc-protocol.c17
5 files changed, 92 insertions, 11 deletions
diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c
index 6b3b1f818..50e20d2da 100644
--- a/src/plugins/irc/irc-config.c
+++ b/src/plugins/irc/irc-config.c
@@ -99,6 +99,7 @@ struct t_config_option *irc_config_look_smart_filter;
struct t_config_option *irc_config_look_smart_filter_delay;
struct t_config_option *irc_config_look_smart_filter_join;
struct t_config_option *irc_config_look_smart_filter_join_unmask;
+struct t_config_option *irc_config_look_smart_filter_mode;
struct t_config_option *irc_config_look_smart_filter_nick;
struct t_config_option *irc_config_look_smart_filter_quit;
struct t_config_option *irc_config_look_topic_strip_colors;
@@ -2569,6 +2570,15 @@ irc_config_init ()
"update on topic), the join is unmasked, as well as nick changes "
"after this join (0 = disable: never unmask a join)"),
NULL, 0, 60*24*7, "30", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
+ irc_config_look_smart_filter_mode = weechat_config_new_option (
+ irc_config_file, ptr_section,
+ "smart_filter_mode", "string",
+ /* TRANSLATORS: please do not translate "mode" */
+ N_("enable smart filter for \"mode\" messages: \"*\" to filter all "
+ "modes, \"xyz\" to filter only modes x/y/z, \"-xyz\" to filter all "
+ "modes but not x/y/z; examples: \"ovh\": filter modes o/v/h, "
+ "\"-bkl\": filter all modes but not b/k/l"),
+ NULL, 0, 0, "ovh", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
irc_config_look_smart_filter_nick = weechat_config_new_option (
irc_config_file, ptr_section,
"smart_filter_nick", "boolean",
diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h
index 0a5e13e0d..47a4ba22e 100644
--- a/src/plugins/irc/irc-config.h
+++ b/src/plugins/irc/irc-config.h
@@ -147,6 +147,7 @@ extern struct t_config_option *irc_config_look_smart_filter;
extern struct t_config_option *irc_config_look_smart_filter_delay;
extern struct t_config_option *irc_config_look_smart_filter_join;
extern struct t_config_option *irc_config_look_smart_filter_join_unmask;
+extern struct t_config_option *irc_config_look_smart_filter_mode;
extern struct t_config_option *irc_config_look_smart_filter_nick;
extern struct t_config_option *irc_config_look_smart_filter_quit;
extern struct t_config_option *irc_config_look_topic_strip_colors;
diff --git a/src/plugins/irc/irc-mode.c b/src/plugins/irc/irc-mode.c
index a3179de91..b16d9bc9a 100644
--- a/src/plugins/irc/irc-mode.c
+++ b/src/plugins/irc/irc-mode.c
@@ -26,6 +26,7 @@
#include "../weechat-plugin.h"
#include "irc.h"
#include "irc-mode.h"
+#include "irc-config.h"
#include "irc-server.h"
#include "irc-channel.h"
#include "irc-nick.h"
@@ -263,21 +264,64 @@ irc_mode_channel_update (struct t_irc_server *server,
}
/*
+ * Checks if a mode is smart filtered (according to option
+ * irc.look.smart_filter_mode).
+ *
+ * Returns:
+ * 1: the mode is smart filtered
+ * 0: the mode is NOT smart filtered
+ */
+
+int
+irc_mode_smart_filtered (char mode)
+{
+ const char *ptr_modes;
+
+ ptr_modes = weechat_config_string (irc_config_look_smart_filter_mode);
+
+ /* if empty value, there's no smart filtering on mode messages */
+ if (!ptr_modes || !ptr_modes[0])
+ return 0;
+
+ /* if var is "*", ALL modes are smart filtered */
+ if (strcmp (ptr_modes, "*") == 0)
+ return 1;
+
+ /*
+ * if var starts with "-", smart filter all modes except following modes
+ * example: "-kl": smart filter all modes but not k/l
+ */
+ if (ptr_modes[0] == '-')
+ return (strchr (ptr_modes + 1, mode)) ? 0 : 1;
+
+ /*
+ * explicit list of modes to smart filter
+ * example: "ovh": smart filter modes o/v/h
+ */
+ return (strchr (ptr_modes, mode)) ? 1 : 0;
+}
+
+/*
* Sets channel modes using CHANMODES (from message 005) and update channel
* modes if needed.
+ *
+ * Returns:
+ * 1: the mode message can be "smart filtered"
+ * 0: the mode message must NOT be "smart filtered"
*/
-void
+int
irc_mode_channel_set (struct t_irc_server *server,
struct t_irc_channel *channel,
const char *modes)
{
char *pos_args, *str_modes, set_flag, **argv, *pos, *ptr_arg, chanmode_type;
int argc, current_arg, update_channel_modes, channel_modes_updated;
+ int smart_filter;
struct t_irc_nick *ptr_nick;
if (!server || !channel || !modes)
- return;
+ return 0;
channel_modes_updated = 0;
argc = 0;
@@ -287,7 +331,7 @@ irc_mode_channel_set (struct t_irc_server *server,
{
str_modes = weechat_strndup (modes, pos_args - modes);
if (!str_modes)
- return;
+ return 0;
pos_args++;
while (pos_args[0] == ' ')
pos_args++;
@@ -297,11 +341,15 @@ irc_mode_channel_set (struct t_irc_server *server,
{
str_modes = strdup (modes);
if (!str_modes)
- return;
+ return 0;
}
current_arg = 0;
+ smart_filter = (weechat_config_boolean (irc_config_look_smart_filter)
+ && weechat_config_string (irc_config_look_smart_filter_mode)
+ && weechat_config_string (irc_config_look_smart_filter_mode)[0]) ? 1 : 0;
+
if (str_modes && str_modes[0])
{
set_flag = '+';
@@ -344,6 +392,9 @@ irc_mode_channel_set (struct t_irc_server *server,
if (ptr_arg)
current_arg++;
+ if (smart_filter && !irc_mode_smart_filtered (pos[0]))
+ smart_filter = 0;
+
if (pos[0] == 'k')
{
/* channel key */
@@ -388,6 +439,14 @@ irc_mode_channel_set (struct t_irc_server *server,
{
irc_nick_set_mode (server, channel, ptr_nick,
(set_flag == '+'), pos[0]);
+ if (smart_filter
+ && irc_channel_nick_speaking_time_search (server,
+ channel,
+ ptr_nick->name,
+ 1))
+ {
+ smart_filter = 0;
+ }
}
}
}
@@ -410,6 +469,8 @@ irc_mode_channel_set (struct t_irc_server *server,
if (channel_modes_updated)
weechat_bar_item_update ("buffer_modes");
+
+ return smart_filter;
}
/*
diff --git a/src/plugins/irc/irc-mode.h b/src/plugins/irc/irc-mode.h
index 28c570bed..140a98b04 100644
--- a/src/plugins/irc/irc-mode.h
+++ b/src/plugins/irc/irc-mode.h
@@ -23,9 +23,9 @@
struct t_irc_server;
struct t_irc_channel;
-extern void irc_mode_channel_set (struct t_irc_server *server,
- struct t_irc_channel *channel,
- const char *modes);
+extern int irc_mode_channel_set (struct t_irc_server *server,
+ struct t_irc_channel *channel,
+ const char *modes);
extern void irc_mode_user_set (struct t_irc_server *server, const char *modes,
int reset_modes);
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 3aa8844ad..cf0735b24 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -848,6 +848,7 @@ IRC_PROTOCOL_CALLBACK(kill)
IRC_PROTOCOL_CALLBACK(mode)
{
char *pos_modes;
+ int smart_filter, local_mode;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
struct t_gui_buffer *ptr_buffer;
@@ -859,16 +860,24 @@ IRC_PROTOCOL_CALLBACK(mode)
if (irc_channel_is_channel (server, argv[2]))
{
+ smart_filter = 0;
ptr_channel = irc_channel_search (server, argv[2]);
if (ptr_channel)
- irc_mode_channel_set (server, ptr_channel, pos_modes);
+ {
+ smart_filter = irc_mode_channel_set (server, ptr_channel,
+ pos_modes);
+ }
+ local_mode = (irc_server_strcasecmp (server, nick, server->nick) == 0);
ptr_nick = irc_nick_search (server, ptr_channel, nick);
ptr_buffer = (ptr_channel) ? ptr_channel->buffer : server->buffer;
weechat_printf_date_tags (irc_msgbuffer_get_target_buffer (server, NULL,
command, NULL,
ptr_buffer),
date,
- irc_protocol_tags (command, NULL, NULL),
+ irc_protocol_tags (command,
+ (smart_filter && !local_mode) ?
+ "irc_smart_filter" : NULL,
+ NULL),
_("%sMode %s%s %s[%s%s%s]%s by %s%s"),
weechat_prefix ("network"),
IRC_COLOR_CHAT_CHANNEL,
@@ -2923,8 +2932,8 @@ IRC_PROTOCOL_CALLBACK(324)
irc_channel_set_modes (ptr_channel, ((argc > 4) ? argv_eol[4] : NULL));
if (argc > 4)
{
- irc_mode_channel_set (server, ptr_channel,
- ptr_channel->modes);
+ (void) irc_mode_channel_set (server, ptr_channel,
+ ptr_channel->modes);
}
}
weechat_printf_date_tags (irc_msgbuffer_get_target_buffer (server, NULL,