summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-05-23 10:01:38 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-05-23 10:01:38 +0200
commit7bb9892e86c72282e5a428ed6898f0ee86a47edc (patch)
tree002f5cf889a30818a6e98725913138082bbba870 /src
parent3c17e9e27225f4471ed6dcc69ce03dccdf684207 (diff)
downloadweechat-7bb9892e86c72282e5a428ed6898f0ee86a47edc.zip
Add IRC command /wallchops, fix bug with display of notice for ops (task #10021, bug #29932)
Diffstat (limited to 'src')
-rw-r--r--src/plugins/irc/irc-command.c123
-rw-r--r--src/plugins/irc/irc-nick.c5
-rw-r--r--src/plugins/irc/irc-nick.h6
-rw-r--r--src/plugins/irc/irc-protocol.c14
4 files changed, 139 insertions, 9 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c
index 653740dbe..1fd77c938 100644
--- a/src/plugins/irc/irc-command.c
+++ b/src/plugins/irc/irc-command.c
@@ -1233,7 +1233,7 @@ irc_command_devoice (void *data, struct t_gui_buffer *buffer, int argc,
}
/*
- * irc_command_die: shotdown the server
+ * irc_command_die: shutdown the server
*/
int
@@ -3992,7 +3992,8 @@ irc_command_users (void *data, struct t_gui_buffer *buffer, int argc,
}
/*
- * irc_command_version: gives the version info of nick or server (current or specified)
+ * irc_command_version: gives the version info of nick or server (current or
+ * specified)
*/
int
@@ -4070,8 +4071,118 @@ irc_command_voice (void *data, struct t_gui_buffer *buffer, int argc,
}
/*
+ * irc_command_wallchops: send a notice to channel ops
+ */
+
+int
+irc_command_wallchops (void *data, struct t_gui_buffer *buffer, int argc,
+ char **argv, char **argv_eol)
+{
+ char *pos_channel;
+ int pos_args;
+ const char *support_wallchops, *support_statusmsg;
+ struct t_irc_nick *ptr_nick;
+
+ IRC_BUFFER_GET_SERVER_CHANNEL(buffer);
+ IRC_COMMAND_CHECK_SERVER("wallchops", 1);
+
+ /* make C compiler happy */
+ (void) data;
+
+ if (argc > 1)
+ {
+ if (irc_channel_is_channel (argv[1]))
+ {
+ pos_channel = argv[1];
+ pos_args = 2;
+ }
+ else
+ {
+ pos_channel = NULL;
+ pos_args = 1;
+ }
+
+ /* channel not given, use default buffer */
+ if (!pos_channel)
+ {
+ if (ptr_channel && (ptr_channel->type == IRC_CHANNEL_TYPE_CHANNEL))
+ pos_channel = ptr_channel->name;
+ else
+ {
+ weechat_printf (ptr_server->buffer,
+ _("%s%s: \"%s\" command can only be "
+ "executed in a channel buffer"),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME,
+ "wallchops");
+ return WEECHAT_RC_OK;
+ }
+ }
+
+ ptr_channel = irc_channel_search (ptr_server, pos_channel);
+ if (!ptr_channel)
+ {
+ weechat_printf (ptr_server->buffer,
+ _("%s%s: you are not on channel \"%s\""),
+ weechat_prefix ("error"), IRC_PLUGIN_NAME,
+ pos_channel);
+ return WEECHAT_RC_OK;
+ }
+
+ weechat_printf (ptr_channel->buffer,
+ "%s%sNoticeOp%s -> %s%s%s: %s",
+ weechat_prefix ("network"),
+ IRC_COLOR_NOTICE,
+ IRC_COLOR_CHAT,
+ IRC_COLOR_CHAT_CHANNEL,
+ ptr_channel->name,
+ IRC_COLOR_CHAT,
+ argv_eol[pos_args]);
+
+ support_wallchops = irc_server_get_isupport_value (ptr_server,
+ "WALLCHOPS");
+ support_statusmsg = irc_server_get_isupport_value (ptr_server,
+ "STATUSMSG");
+ if (support_wallchops
+ || (support_statusmsg && strchr (support_statusmsg, '@')))
+ {
+ /*
+ * if WALLCHOPS is supported, or if STATUSMSG includes '@',
+ * then send a notice to @#channel
+ */
+ irc_server_sendf (ptr_server, IRC_SERVER_OUTQUEUE_PRIO_HIGH,
+ "NOTICE @%s :%s",
+ ptr_channel->name, argv_eol[pos_args]);
+ }
+ else
+ {
+ /*
+ * if WALLCHOPS is not supported and '@' not in STATUSMSG,
+ * then send a notice to each op of channel
+ */
+ for (ptr_nick = ptr_channel->nicks; ptr_nick;
+ ptr_nick = ptr_nick->next_nick)
+ {
+ if (IRC_NICK_IS_OP(ptr_nick)
+ && (strcmp (ptr_nick->name, ptr_server->nick) != 0))
+ {
+ irc_server_sendf (ptr_server, IRC_SERVER_OUTQUEUE_PRIO_LOW,
+ "NOTICE %s :%s",
+ ptr_nick->name, argv_eol[pos_args]);
+ }
+ }
+ }
+ }
+ else
+ {
+ IRC_COMMAND_TOO_FEW_ARGUMENTS(ptr_server->buffer, "wallchops");
+ }
+
+ return WEECHAT_RC_OK;
+}
+
+/*
* irc_command_wallops: send a message to all currently connected users who
- * have set the 'w' user mode for themselves
+ * have set the 'w' user mode for themselves
*/
int
@@ -4771,6 +4882,12 @@ irc_command_init ()
N_("[nickname [nickname]]"),
"",
"%(nicks)|%*", &irc_command_voice, NULL);
+ weechat_hook_command ("wallchops",
+ N_("send a notice to channel ops"),
+ N_("[channel] text"),
+ N_("channel: channel name\n"
+ " test: text to send"),
+ NULL, &irc_command_wallchops, NULL);
weechat_hook_command ("wallops",
N_("send a message to all currently connected users "
"who have set the 'w' user mode for themselves"),
diff --git a/src/plugins/irc/irc-nick.c b/src/plugins/irc/irc-nick.c
index 6d0d3c47f..1e82a1d84 100644
--- a/src/plugins/irc/irc-nick.c
+++ b/src/plugins/irc/irc-nick.c
@@ -517,10 +517,7 @@ irc_nick_count (struct t_irc_channel *channel, int *total, int *count_op,
ptr_nick = ptr_nick->next_nick)
{
(*total)++;
- if ((ptr_nick->flags & IRC_NICK_CHANOWNER) ||
- (ptr_nick->flags & IRC_NICK_CHANADMIN) ||
- (ptr_nick->flags & IRC_NICK_CHANADMIN2) ||
- (ptr_nick->flags & IRC_NICK_OP))
+ if (IRC_NICK_IS_OP(ptr_nick))
(*count_op)++;
else
{
diff --git a/src/plugins/irc/irc-nick.h b/src/plugins/irc/irc-nick.h
index f27ab1973..38705203e 100644
--- a/src/plugins/irc/irc-nick.h
+++ b/src/plugins/irc/irc-nick.h
@@ -38,6 +38,12 @@
else \
nick->flags &= 0xFFFF - flag;
+#define IRC_NICK_IS_OP(__nick) \
+ ((__nick->flags & IRC_NICK_CHANOWNER) || \
+ (__nick->flags & IRC_NICK_CHANADMIN) || \
+ (__nick->flags & IRC_NICK_CHANADMIN2) || \
+ (__nick->flags & IRC_NICK_OP))
+
#define IRC_NICK_GROUP_CHANOWNER "01|chanowner"
#define IRC_NICK_GROUP_CHANADMIN "02|chanadmin"
#define IRC_NICK_GROUP_CHANADMIN2 "03|chanadmin2"
diff --git a/src/plugins/irc/irc-protocol.c b/src/plugins/irc/irc-protocol.c
index 2dc44bcfb..40de6c864 100644
--- a/src/plugins/irc/irc-protocol.c
+++ b/src/plugins/irc/irc-protocol.c
@@ -994,7 +994,7 @@ IRC_PROTOCOL_CALLBACK(notice)
char *pos_target, *pos_args;
struct t_irc_channel *ptr_channel;
struct t_irc_nick *ptr_nick;
- int notify_private;
+ int notify_private, notice_op;
struct t_gui_buffer *ptr_buffer;
/*
@@ -1009,10 +1009,19 @@ IRC_PROTOCOL_CALLBACK(notice)
if (ignored)
return WEECHAT_RC_OK;
+ notice_op = 0;
+
if (argv[0][0] == ':')
{
pos_target = argv[2];
+ if ((pos_target[0] == '@') && (irc_channel_is_channel (pos_target + 1)))
+ {
+ pos_target++;
+ notice_op = 1;
+ }
pos_args = (argv_eol[3][0] == ':') ? argv_eol[3] + 1 : argv_eol[3];
+ if (notice_op && (pos_args[0] == '@') && (pos_args[1] == ' '))
+ pos_args += 2;
}
else
{
@@ -1034,9 +1043,10 @@ IRC_PROTOCOL_CALLBACK(notice)
ptr_nick = irc_nick_search (ptr_channel, nick);
weechat_printf_tags ((ptr_channel) ? ptr_channel->buffer : server->buffer,
irc_protocol_tags (command, "notify_message"),
- "%s%sNotice%s(%s%s%s)%s: %s",
+ "%s%sNotice%s%s(%s%s%s)%s: %s",
weechat_prefix ("network"),
IRC_COLOR_NOTICE,
+ (notice_op) ? "Op" : "",
IRC_COLOR_CHAT_DELIMITERS,
IRC_COLOR_NICK_IN_SERVER_MESSAGE(ptr_nick),
(nick && nick[0]) ? nick : "?",