diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-10-08 19:57:04 +0200 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-10-08 19:57:04 +0200 |
commit | d82f8c81658a6a3294668136a0df0cd0e15641b9 (patch) | |
tree | 0faee3083577dd3729556e12424ad1701ba8e644 /src/plugins | |
parent | 4adbb8da1e036a769a60606ea6f4b0ec19ecffaf (diff) | |
download | weechat-d82f8c81658a6a3294668136a0df0cd0e15641b9.zip |
irc: add server option "default_msg_kick" to customize default kick/kickban message (task #12777) (patch from Nils Görs)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/irc/irc-command.c | 81 | ||||
-rw-r--r-- | src/plugins/irc/irc-completion.c | 34 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 14 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.c | 6 | ||||
-rw-r--r-- | src/plugins/irc/irc-message.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 14 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.h | 1 |
7 files changed, 122 insertions, 30 deletions
diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index 3aa946dfb..03138dede 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -334,7 +334,7 @@ irc_command_exec_all_channels (struct t_irc_server *server, if (!excluded) { cmd_vars_replaced = irc_message_replace_vars (ptr_server, - ptr_channel, + ptr_channel->name, str_command); weechat_command (ptr_channel->buffer, (cmd_vars_replaced) ? cmd_vars_replaced : str_command); @@ -2328,6 +2328,41 @@ irc_command_join (void *data, struct t_gui_buffer *buffer, int argc, } /* + * Sends a kick message to a channel. + */ + +void +irc_command_kick_channel (struct t_irc_server *server, + const char *channel_name, const char *nick_name, + const char *message) +{ + const char *msg_kick; + char *msg_vars_replaced; + + msg_kick = (message && message[0]) ? + message : IRC_SERVER_OPTION_STRING(server, + IRC_SERVER_OPTION_DEFAULT_MSG_KICK); + if (msg_kick && msg_kick[0]) + { + msg_vars_replaced = irc_message_replace_vars (server, + channel_name, + msg_kick); + irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "KICK %s %s :%s", + channel_name, nick_name, + (msg_vars_replaced) ? msg_vars_replaced : msg_kick); + if (msg_vars_replaced) + free (msg_vars_replaced); + } + else + { + irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, + "KICK %s %s", + channel_name, nick_name); + } +} + +/* * Callback for command "/kick": forcibly removes a user from a channel. */ @@ -2378,19 +2413,8 @@ irc_command_kick (void *data, struct t_gui_buffer *buffer, int argc, return WEECHAT_RC_OK; } } - - if (pos_comment) - { - irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "KICK %s %s :%s", - pos_channel, pos_nick, pos_comment); - } - else - { - irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "KICK %s %s", - pos_channel, pos_nick); - } + irc_command_kick_channel (ptr_server, pos_channel, pos_nick, + pos_comment); } else { @@ -2499,12 +2523,8 @@ irc_command_kickban (void *data, struct t_gui_buffer *buffer, int argc, } /* kick nick */ - irc_server_sendf (ptr_server, IRC_SERVER_SEND_OUTQ_PRIO_HIGH, NULL, - "KICK %s %s%s%s", - pos_channel, - nick_only, - (pos_comment) ? " :" : "", - (pos_comment) ? pos_comment : ""); + irc_command_kick_channel (ptr_server, pos_channel, nick_only, + pos_comment); free (nick_only); } } @@ -4519,6 +4539,14 @@ irc_command_display_server (struct t_irc_server *server, int with_detail) weechat_printf (NULL, " away_check_max_nicks : %s%d", IRC_COLOR_CHAT_VALUE, weechat_config_integer (server->options[IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS])); + /* default_msg_kick */ + if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_DEFAULT_MSG_KICK])) + weechat_printf (NULL, " default_msg_kick . . : ('%s')", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_KICK)); + else + weechat_printf (NULL, " default_msg_kick . . : %s'%s'", + IRC_COLOR_CHAT_VALUE, + weechat_config_string (server->options[IRC_SERVER_OPTION_DEFAULT_MSG_KICK])); /* default_msg_part */ if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_DEFAULT_MSG_PART])) weechat_printf (NULL, " default_msg_part . . : ('%s')", @@ -5958,21 +5986,26 @@ irc_command_init () N_("[<channel>] <nick> [<reason>]"), N_("channel: channel where user is\n" " nick: nick to kick\n" - " reason: reason for kick"), - "%(nicks) %-", &irc_command_kick, NULL); + " reason: reason for kick (special variables " + "$nick, $channel and $server are replaced by their " + "value)"), + "%(nicks) %(irc_msg_kick) %-", &irc_command_kick, NULL); weechat_hook_command ("kickban", N_("kicks and bans a nick from a channel"), N_("[<channel>] <nick> [<reason>]"), N_("channel: channel where user is\n" " nick: nick to kick and ban\n" - " reason: reason for kick\n\n" + " reason: reason for kick (special variables " + "$nick, $channel and $channel are replaced by their " + "value)\n\n" "It is possible to kick/ban with a mask, nick " "will be extracted from mask and replaced by " "\"*\".\n\n" "Example:\n" " ban \"*!*@host.com\" and then kick \"toto\":\n" " /kickban toto!*@host.com"), - "%(irc_channel_nicks_hosts) %-", &irc_command_kickban, NULL); + "%(irc_channel_nicks_hosts) %(irc_msg_kick) %-", + &irc_command_kickban, NULL); weechat_hook_command ("kill", N_("close client-server connection"), N_("<nick> <reason>"), diff --git a/src/plugins/irc/irc-completion.c b/src/plugins/irc/irc-completion.c index bdfd06231..ced451c60 100644 --- a/src/plugins/irc/irc-completion.c +++ b/src/plugins/irc/irc-completion.c @@ -524,6 +524,37 @@ irc_completion_privates_cb (void *data, const char *completion_item, } /* + * Adds default kick message to completion list. + */ + +int +irc_completion_msg_kick_cb (void *data, const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + const char *msg_kick; + + IRC_BUFFER_GET_SERVER(buffer); + + /* make C compiler happy */ + (void) data; + (void) completion_item; + + if (ptr_server) + { + msg_kick = IRC_SERVER_OPTION_STRING(ptr_server, + IRC_SERVER_OPTION_DEFAULT_MSG_KICK); + if (msg_kick && msg_kick[0]) + { + weechat_hook_completion_list_add (completion, msg_kick, + 0, WEECHAT_LIST_POS_SORT); + } + } + + return WEECHAT_RC_OK; +} + +/* * Adds default part message to completion list. */ @@ -668,6 +699,9 @@ irc_completion_init () weechat_hook_completion ("irc_privates", N_("privates on all IRC servers"), &irc_completion_privates_cb, NULL); + weechat_hook_completion ("irc_msg_kick", + N_("default kick message"), + &irc_completion_msg_kick_cb, NULL); weechat_hook_completion ("irc_msg_part", N_("default part message for IRC channel"), &irc_completion_msg_part_cb, NULL); diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 7177d838e..66a877e76 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -1885,6 +1885,20 @@ irc_config_server_new_option (struct t_config_file *config_file, callback_change, callback_change_data, NULL, NULL); break; + case IRC_SERVER_OPTION_DEFAULT_MSG_KICK: + new_option = weechat_config_new_option ( + config_file, section, + option_name, "string", + N_("default kick message used by commands \"/kick\" and " + "\"/kickban\" (special variables $nick, $channel and $server " + "are replaced by their value)"), + NULL, 0, 0, + default_value, value, + null_value_allowed, + callback_check_value, callback_check_value_data, + callback_change, callback_change_data, + NULL, NULL); + break; case IRC_SERVER_OPTION_DEFAULT_MSG_PART: new_option = weechat_config_new_option ( config_file, section, diff --git a/src/plugins/irc/irc-message.c b/src/plugins/irc/irc-message.c index 7123bf5f6..b6fa0d39d 100644 --- a/src/plugins/irc/irc-message.c +++ b/src/plugins/irc/irc-message.c @@ -355,14 +355,14 @@ irc_message_get_address_from_host (const char *host) char * irc_message_replace_vars (struct t_irc_server *server, - struct t_irc_channel *channel, const char *string) + const char *channel_name, const char *string) { - char *var_nick, *var_channel, *var_server; + const char *var_nick, *var_channel, *var_server; char empty_string[1] = { '\0' }; char *res, *temp; var_nick = (server && server->nick) ? server->nick : empty_string; - var_channel = (channel) ? channel->name : empty_string; + var_channel = (channel_name) ? channel_name : empty_string; var_server = (server) ? server->name : empty_string; /* replace nick */ diff --git a/src/plugins/irc/irc-message.h b/src/plugins/irc/irc-message.h index 1e1f96629..20234c49b 100644 --- a/src/plugins/irc/irc-message.h +++ b/src/plugins/irc/irc-message.h @@ -32,7 +32,7 @@ extern struct t_hashtable *irc_message_parse_to_hashtable (struct t_irc_server * 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 char *irc_message_replace_vars (struct t_irc_server *server, - struct t_irc_channel *channel, + const char *channel_name, const char *string); extern struct t_hashtable *irc_message_split (struct t_irc_server *server, const char *message); diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 9d6881a7e..5f0c3adb1 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -77,7 +77,7 @@ char *irc_server_option_string[IRC_SERVER_NUM_OPTIONS] = "connection_timeout", "anti_flood_prio_high", "anti_flood_prio_low", "away_check", "away_check_max_nicks", - "default_msg_part", "default_msg_quit", + "default_msg_kick", "default_msg_part", "default_msg_quit", "notify", }; @@ -92,7 +92,7 @@ char *irc_server_option_default[IRC_SERVER_NUM_OPTIONS] = "60", "2", "2", "0", "25", - "WeeChat %v", "WeeChat %v", + "","WeeChat %v", "WeeChat %v", "", }; @@ -4725,6 +4725,9 @@ irc_server_add_to_infolist (struct t_infolist *infolist, if (!weechat_infolist_new_var_integer (ptr_item, "away_check_max_nicks", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS))) return 0; + if (!weechat_infolist_new_var_string (ptr_item, "default_msg_kick", + IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_KICK))) + return 0; if (!weechat_infolist_new_var_string (ptr_item, "default_msg_part", IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_DEFAULT_MSG_PART))) return 0; @@ -5039,6 +5042,13 @@ irc_server_print_log () else weechat_log_printf (" away_check_max_nicks : %d", weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS])); + /* default_msg_kick */ + if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_KICK])) + weechat_log_printf (" default_msg_kick . . : null ('%s')", + IRC_SERVER_OPTION_STRING(ptr_server, IRC_SERVER_OPTION_DEFAULT_MSG_KICK)); + else + weechat_log_printf (" default_msg_kick . . : '%s'", + weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_KICK])); /* default_msg_part */ if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_DEFAULT_MSG_PART])) weechat_log_printf (" default_msg_part . . : null ('%s')", diff --git a/src/plugins/irc/irc-server.h b/src/plugins/irc/irc-server.h index 0f746dd8a..27fd22211 100644 --- a/src/plugins/irc/irc-server.h +++ b/src/plugins/irc/irc-server.h @@ -65,6 +65,7 @@ enum t_irc_server_option IRC_SERVER_OPTION_ANTI_FLOOD_PRIO_LOW, /* anti-flood (low priority) */ IRC_SERVER_OPTION_AWAY_CHECK, /* delay between away checks */ IRC_SERVER_OPTION_AWAY_CHECK_MAX_NICKS, /* max nicks for away check */ + IRC_SERVER_OPTION_DEFAULT_MSG_KICK, /* default kick message */ IRC_SERVER_OPTION_DEFAULT_MSG_PART, /* default part message */ IRC_SERVER_OPTION_DEFAULT_MSG_QUIT, /* default quit message */ IRC_SERVER_OPTION_NOTIFY, /* notify list */ |