diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2014-05-06 21:25:31 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2014-05-06 21:25:31 +0200 |
commit | 37ad9e368490c4ef6f6d74dcc8911caad49f8e1a (patch) | |
tree | 6f313bbe3faf043301fcb56bfa6af7d998e93ee1 /src/plugins/irc | |
parent | ce189fdd2dfb52f733cfb641b16f39af813138b3 (diff) | |
download | weechat-37ad9e368490c4ef6f6d74dcc8911caad49f8e1a.zip |
irc: add option irc.look.join_auto_add_chantype (closes #65)
Diffstat (limited to 'src/plugins/irc')
-rw-r--r-- | src/plugins/irc/irc-channel.c | 33 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-command.c | 11 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 10 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.h | 1 |
5 files changed, 49 insertions, 8 deletions
diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index 9dbf3b794..739e7cc80 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -464,6 +464,39 @@ irc_channel_is_channel (struct t_irc_server *server, const char *string) } /* + * Returns a string with a channel type to add in front of a channel name, + * if it doesn't have a valid channel type for the given server. + * + * It returns an empty string if the channel already has a valid channel type, + * or if the option irc.look.join_auto_add_chantype is off. + */ + +const char * +irc_channel_get_auto_chantype (struct t_irc_server *server, + const char *channel_name) +{ + static char chantype[2]; + + chantype[0] = '\0'; + chantype[1] = '\0'; + + if (weechat_config_boolean (irc_config_look_join_auto_add_chantype) + && !irc_channel_is_channel (server, channel_name) + && server->chantypes + && server->chantypes[0]) + { + /* + * use '#' if it's in chantypes (anywhere in the string), because it is + * the most common channel type, and fallback on first channel type + */ + chantype[0] = (strchr (server->chantypes, '#')) ? + '#' : server->chantypes[0]; + } + + return chantype; +} + +/* * Removes away for all nicks on a channel. */ diff --git a/src/plugins/irc/irc-channel.h b/src/plugins/irc/irc-channel.h index f7b4314d9..65d319320 100644 --- a/src/plugins/irc/irc-channel.h +++ b/src/plugins/irc/irc-channel.h @@ -96,6 +96,8 @@ extern struct t_irc_channel *irc_channel_search (struct t_irc_server *server, const char *channel_name); extern int irc_channel_is_channel (struct t_irc_server *server, const char *string); +extern const char *irc_channel_get_auto_chantype (struct t_irc_server *server, + const char *channel_name); extern void irc_channel_remove_away (struct t_irc_server *server, struct t_irc_channel *channel); extern void irc_channel_check_away (struct t_irc_server *server, diff --git a/src/plugins/irc/irc-command.c b/src/plugins/irc/irc-command.c index b56371486..21870de3e 100644 --- a/src/plugins/irc/irc-command.c +++ b/src/plugins/irc/irc-command.c @@ -2224,9 +2224,6 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments, free (new_args); } - /* - * add "#" in front of each channel if no prefix is given - */ if (channels) { length = strlen (arguments) + num_channels + 1; @@ -2236,7 +2233,7 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments, if (manual_join) { snprintf (new_args, length, "%s%s", - (irc_channel_is_channel (server, channels[0])) ? "" : "#", + irc_channel_get_auto_chantype (server, channels[0]), channels[0]); ptr_channel = irc_channel_search (server, new_args); if (ptr_channel) @@ -2255,10 +2252,8 @@ irc_command_join_server (struct t_irc_server *server, const char *arguments, if (i > 0) strcat (new_args, ","); pos_channel = new_args + strlen (new_args); - if (!irc_channel_is_channel (server, channels[i])) - { - strcat (new_args, "#"); - } + strcat (new_args, + irc_channel_get_auto_chantype (server, channels[i])); strcat (new_args, channels[i]); if (manual_join || noswitch) { diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index b73f9981c..1d7ad9cfd 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -75,6 +75,7 @@ struct t_config_option *irc_config_look_item_channel_modes_hide_args; struct t_config_option *irc_config_look_item_display_server; struct t_config_option *irc_config_look_item_nick_modes; struct t_config_option *irc_config_look_item_nick_prefix; +struct t_config_option *irc_config_look_join_auto_add_chantype; struct t_config_option *irc_config_look_msgbuffer_fallback; struct t_config_option *irc_config_look_new_channel_position; struct t_config_option *irc_config_look_new_pv_position; @@ -2443,6 +2444,15 @@ irc_config_init () N_("display nick prefix in bar item \"input_prompt\""), NULL, 0, 0, "on", NULL, 0, NULL, NULL, &irc_config_change_bar_item_input_prompt, NULL, NULL, NULL); + irc_config_look_join_auto_add_chantype = weechat_config_new_option ( + irc_config_file, ptr_section, + "join_auto_add_chantype", "boolean", + N_("automatically add channel type in front of channel name on " + "command /join if the channel name does not start with a valid " + "channel type for the server; for example: \"/join weechat\" will " + "in fact send: \"/join #weechat\""), + NULL, 0, 0, "off", NULL, 0, NULL, NULL, + NULL, NULL, NULL, NULL); irc_config_look_msgbuffer_fallback = weechat_config_new_option ( irc_config_file, ptr_section, "msgbuffer_fallback", "integer", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 5e2bebfc0..7da924010 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -123,6 +123,7 @@ extern struct t_config_option *irc_config_look_item_channel_modes_hide_args; extern struct t_config_option *irc_config_look_item_display_server; extern struct t_config_option *irc_config_look_item_nick_modes; extern struct t_config_option *irc_config_look_item_nick_prefix; +extern struct t_config_option *irc_config_look_join_auto_add_chantype; extern struct t_config_option *irc_config_look_msgbuffer_fallback; extern struct t_config_option *irc_config_look_new_channel_position; extern struct t_config_option *irc_config_look_new_pv_position; |