1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-30 06:46:38 +02:00

irc: add server option "autojoin_delay" (closes #862)

The server option "autojoin_delay" adds a delay before autojoin.

The server option "command_delay" is now used to add a delay before the
execution of the command.

On upgrade from an old version, the option "command_delay" is copied to
"autojoin_delay" (in old versions, "command_delay" was applied after the
execution of command and before the autojoin).
This commit is contained in:
Sébastien Helleu
2024-02-11 09:12:57 +01:00
parent f153b6e6c3
commit 0cfc61a17e
23 changed files with 409 additions and 179 deletions
+18 -8
View File
@@ -5421,6 +5421,16 @@ irc_command_display_server (struct t_irc_server *server, int with_detail)
weechat_printf (NULL, " usermode . . . . . . : %s'%s'",
IRC_COLOR_CHAT_VALUE,
weechat_config_string (server->options[IRC_SERVER_OPTION_USERMODE]));
/* command_delay */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_COMMAND_DELAY]))
weechat_printf (NULL, " command_delay. . . . : (%d %s)",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY),
NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY)));
else
weechat_printf (NULL, " command_delay. . . . : %s%d %s",
IRC_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[IRC_SERVER_OPTION_COMMAND_DELAY]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_COMMAND_DELAY])));
/* command */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_COMMAND]))
{
@@ -5443,16 +5453,16 @@ irc_command_display_server (struct t_irc_server *server, int with_detail)
if (cmd_pwd_hidden)
free (cmd_pwd_hidden);
}
/* command_delay */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_COMMAND_DELAY]))
weechat_printf (NULL, " command_delay. . . . : (%d %s)",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY),
NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY)));
/* autojoin_delay */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTOJOIN_DELAY]))
weechat_printf (NULL, " autojoin_delay . . . : (%d %s)",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOJOIN_DELAY),
NG_("second", "seconds", IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOJOIN_DELAY)));
else
weechat_printf (NULL, " command_delay. . . . : %s%d %s",
weechat_printf (NULL, " autojoin_delay . . . : %s%d %s",
IRC_COLOR_CHAT_VALUE,
weechat_config_integer (server->options[IRC_SERVER_OPTION_COMMAND_DELAY]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_COMMAND_DELAY])));
weechat_config_integer (server->options[IRC_SERVER_OPTION_AUTOJOIN_DELAY]),
NG_("second", "seconds", weechat_config_integer (server->options[IRC_SERVER_OPTION_AUTOJOIN_DELAY])));
/* autojoin */
if (weechat_config_option_is_null (server->options[IRC_SERVER_OPTION_AUTOJOIN]))
weechat_printf (NULL, " autojoin . . . . . . : ('%s')",
+73 -5
View File
@@ -2376,6 +2376,22 @@ irc_config_server_new_option (struct t_config_file *config_file,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_OPTION_COMMAND_DELAY:
new_option = weechat_config_new_option (
config_file, section,
option_name, "integer",
N_("delay (in seconds) before execution of command"),
NULL, 0, 3600,
default_value, value,
null_value_allowed,
callback_check_value,
callback_check_value_pointer,
callback_check_value_data,
callback_change,
callback_change_pointer,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_OPTION_COMMAND:
new_option = weechat_config_new_option (
config_file, section,
@@ -2398,13 +2414,13 @@ irc_config_server_new_option (struct t_config_file *config_file,
callback_change_data,
NULL, NULL, NULL);
break;
case IRC_SERVER_OPTION_COMMAND_DELAY:
case IRC_SERVER_OPTION_AUTOJOIN_DELAY:
new_option = weechat_config_new_option (
config_file, section,
option_name, "integer",
N_("delay (in seconds) after execution of command and before "
"auto-join of channels (example: give some time for "
"authentication before joining channels)"),
N_("delay (in seconds) before auto-join of channels "
"(example: give some time for authentication before joining "
"channels)"),
NULL, 0, 3600,
default_value, value,
null_value_allowed,
@@ -2880,8 +2896,9 @@ irc_config_update_cb (const void *pointer, void *data,
struct t_hashtable *data_read)
{
const char *ptr_section, *ptr_option, *ptr_value;
const char *option_autojoin_delay = "autojoin_delay";
char *new_option, *pos_option, *new_value;
int changes;
int changes, length;
/* make C compiler happy */
(void) pointer;
@@ -2987,6 +3004,57 @@ irc_config_update_cb (const void *pointer, void *data,
}
}
if (version_read < 4)
{
/*
* changes in v4 (WeeChat 4.3.0):
* - server option "command_delay" is renamed to "autojoin_delay"
* ("command_delay" is a new option that sets the delay before
* the command, while "autojoin_delay" sets the delay before the
* autojoin)
*/
ptr_section = weechat_hashtable_get (data_read, "section");
ptr_option = weechat_hashtable_get (data_read, "option");
if (ptr_section
&& ptr_option
&& (strcmp (ptr_section, "server_default") == 0)
&& (strcmp (ptr_option, "command_delay") == 0))
{
weechat_printf (
NULL,
_("IRC option renamed: \"irc.%s.%s\" => \"irc.%s.%s\""),
ptr_section, ptr_option,
ptr_section, option_autojoin_delay);
weechat_hashtable_set (data_read, "option", option_autojoin_delay);
changes++;
}
else if (ptr_section
&& ptr_option
&& (strcmp (ptr_section, "server") == 0))
{
pos_option = strrchr (ptr_option, '.');
if (pos_option && (strcmp (pos_option + 1, "command_delay") == 0))
{
length = (pos_option - ptr_option + 1) + strlen (option_autojoin_delay) + 1;
new_option = malloc (length);
if (new_option)
{
memcpy (new_option, ptr_option, pos_option - ptr_option + 1);
new_option[pos_option - ptr_option + 1] = '\0';
strcat (new_option, option_autojoin_delay);
weechat_printf (
NULL,
_("IRC option renamed: \"irc.%s.%s\" => \"irc.%s.%s\""),
ptr_section, ptr_option,
ptr_section, new_option);
weechat_hashtable_set (data_read, "option", new_option);
changes++;
free (new_option);
}
}
}
}
return (changes) ? data_read : NULL;
}
+1 -1
View File
@@ -23,7 +23,7 @@
#define IRC_CONFIG_NAME "irc"
#define IRC_CONFIG_PRIO_NAME (TO_STR(IRC_PLUGIN_PRIORITY) "|" IRC_CONFIG_NAME)
#define IRC_CONFIG_VERSION 3
#define IRC_CONFIG_VERSION 4
enum t_irc_config_look_server_buffer
{
+8 -52
View File
@@ -4004,10 +4004,7 @@ IRC_PROTOCOL_CALLBACK(warn)
IRC_PROTOCOL_CALLBACK(001)
{
char **commands, **ptr_command, *command2, *command3, *slash_command;
char *away_msg, *usermode;
const char *ptr_server_command;
int length;
IRC_PROTOCOL_MIN_PARAMS(1);
@@ -4061,57 +4058,16 @@ IRC_PROTOCOL_CALLBACK(001)
free (usermode);
/* execute command when connected */
ptr_server_command = IRC_SERVER_OPTION_STRING(ctxt->server,
IRC_SERVER_OPTION_COMMAND);
if (ptr_server_command && ptr_server_command[0])
{
/* split command on ';' which can be escaped with '\;' */
commands = weechat_string_split_command (ptr_server_command, ';');
if (commands)
{
for (ptr_command = commands; *ptr_command; ptr_command++)
{
command2 = irc_server_eval_expression (ctxt->server, *ptr_command);
if (command2)
{
command3 = irc_message_replace_vars (ctxt->server, NULL,
command2);
if (command3)
{
if (weechat_string_is_command_char (command3))
{
weechat_command (ctxt->server->buffer, command3);
}
else
{
length = 1 + strlen (command3) + 1;
slash_command = malloc (length);
if (slash_command)
{
snprintf (slash_command, length,
"/%s", command3);
weechat_command (ctxt->server->buffer,
slash_command);
free (slash_command);
}
}
free (command3);
}
free (command2);
}
}
weechat_string_free_split_command (commands);
}
if (IRC_SERVER_OPTION_INTEGER(ctxt->server, IRC_SERVER_OPTION_COMMAND_DELAY) > 0)
ctxt->server->command_time = time (NULL) + 1;
else
irc_server_autojoin_channels (ctxt->server);
}
if (IRC_SERVER_OPTION_INTEGER(ctxt->server, IRC_SERVER_OPTION_COMMAND_DELAY) > 0)
ctxt->server->command_time = time (NULL) + 1;
else
irc_server_execute_command (ctxt->server);
/* auto-join of channels */
if (IRC_SERVER_OPTION_INTEGER(ctxt->server, IRC_SERVER_OPTION_AUTOJOIN_DELAY) > 0)
ctxt->server->autojoin_time = time (NULL) + 1;
else
{
irc_server_autojoin_channels (ctxt->server);
}
return WEECHAT_RC_OK;
}
+87 -10
View File
@@ -109,8 +109,9 @@ char *irc_server_options[IRC_SERVER_NUM_OPTIONS][2] =
{ "realname", "" },
{ "local_hostname", "" },
{ "usermode", "" },
{ "command", "" },
{ "command_delay", "0" },
{ "command", "" },
{ "autojoin_delay", "0" },
{ "autojoin", "" },
{ "autojoin_dynamic", "off" },
{ "autorejoin", "off" },
@@ -1755,6 +1756,7 @@ irc_server_alloc (const char *name)
new_server->reconnect_delay = 0;
new_server->reconnect_start = 0;
new_server->command_time = 0;
new_server->autojoin_time = 0;
new_server->autojoin_done = 0;
new_server->disable_autojoin = 0;
new_server->is_away = 0;
@@ -4067,15 +4069,24 @@ irc_server_timer_cb (const void *pointer, void *data, int remaining_calls)
}
}
/* check if it's time to autojoin channels (after command delay) */
/* check if it's time to execute command (after command_delay) */
if ((ptr_server->command_time != 0)
&& (current_time >= ptr_server->command_time +
IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_COMMAND_DELAY)))
{
irc_server_autojoin_channels (ptr_server);
irc_server_execute_command (ptr_server);
ptr_server->command_time = 0;
}
/* check if it's time to auto-join channels (after autojoin_delay) */
if ((ptr_server->autojoin_time != 0)
&& (current_time >= ptr_server->autojoin_time +
IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTOJOIN_DELAY)))
{
irc_server_autojoin_channels (ptr_server);
ptr_server->autojoin_time = 0;
}
/* check if it's time to send MONITOR command */
if ((ptr_server->monitor_time != 0)
&& (current_time >= ptr_server->monitor_time))
@@ -5897,6 +5908,58 @@ irc_server_disconnect_all ()
}
}
/*
* Executes command on server (using server option ".command").
*/
void
irc_server_execute_command (struct t_irc_server *server)
{
char **commands, **ptr_command, *command2, *command3, *slash_command;
const char *ptr_server_command;
int length;
ptr_server_command = IRC_SERVER_OPTION_STRING(server,
IRC_SERVER_OPTION_COMMAND);
if (!ptr_server_command || !ptr_server_command[0])
return;
/* split command on ';' which can be escaped with '\;' */
commands = weechat_string_split_command (ptr_server_command, ';');
if (!commands)
return;
for (ptr_command = commands; *ptr_command; ptr_command++)
{
command2 = irc_server_eval_expression (server, *ptr_command);
if (command2)
{
command3 = irc_message_replace_vars (server, NULL, command2);
if (command3)
{
if (weechat_string_is_command_char (command3))
{
weechat_command (server->buffer, command3);
}
else
{
length = 1 + strlen (command3) + 1;
slash_command = malloc (length);
if (slash_command)
{
snprintf (slash_command, length, "/%s", command3);
weechat_command (server->buffer, slash_command);
free (slash_command);
}
}
free (command3);
}
free (command2);
}
}
weechat_string_free_split_command (commands);
}
/*
* Creates buffers for auto-joined channels on a server.
*/
@@ -6567,6 +6630,7 @@ irc_server_hdata_server_cb (const void *pointer, void *data,
WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_delay, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, reconnect_start, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, command_time, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, autojoin_time, TIME, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, autojoin_done, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, disable_autojoin, INTEGER, 0, NULL, NULL);
WEECHAT_HDATA_VAR(struct t_irc_server, is_away, INTEGER, 0, NULL, NULL);
@@ -6726,11 +6790,14 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
if (!weechat_infolist_new_var_string (ptr_item, "usermode",
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_USERMODE)))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "command_delay",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY)))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "command",
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_COMMAND)))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "command_delay",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_COMMAND_DELAY)))
if (!weechat_infolist_new_var_integer (ptr_item, "autojoin_delay",
IRC_SERVER_OPTION_INTEGER(server, IRC_SERVER_OPTION_AUTOJOIN_DELAY)))
return 0;
if (!weechat_infolist_new_var_string (ptr_item, "autojoin",
IRC_SERVER_OPTION_STRING(server, IRC_SERVER_OPTION_AUTOJOIN)))
@@ -6949,6 +7016,8 @@ irc_server_add_to_infolist (struct t_infolist *infolist,
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "command_time", server->command_time))
return 0;
if (!weechat_infolist_new_var_time (ptr_item, "autojoin_time", server->autojoin_time))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "autojoin_done", server->autojoin_done))
return 0;
if (!weechat_infolist_new_var_integer (ptr_item, "disable_autojoin", server->disable_autojoin))
@@ -7165,11 +7234,6 @@ irc_server_print_log ()
else
weechat_log_printf (" usermode. . . . . . . . . : '%s'",
weechat_config_string (ptr_server->options[IRC_SERVER_OPTION_USERMODE]));
/* command */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND]))
weechat_log_printf (" command . . . . . . . . . : null");
else
weechat_log_printf (" command . . . . . . . . . : (hidden)");
/* command_delay */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY]))
weechat_log_printf (" command_delay . . . . . . : null (%d)",
@@ -7177,6 +7241,18 @@ irc_server_print_log ()
else
weechat_log_printf (" command_delay . . . . . . : %d",
weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_COMMAND_DELAY]));
/* command */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_COMMAND]))
weechat_log_printf (" command . . . . . . . . . : null");
else
weechat_log_printf (" command . . . . . . . . . : (hidden)");
/* autojoin_delay */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN_DELAY]))
weechat_log_printf (" autojoin_delay. . . . . . : null (%d)",
IRC_SERVER_OPTION_INTEGER(ptr_server, IRC_SERVER_OPTION_AUTOJOIN_DELAY));
else
weechat_log_printf (" autojoin_delay. . . . . . : %d",
weechat_config_integer (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN_DELAY]));
/* autojoin */
if (weechat_config_option_is_null (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN]))
weechat_log_printf (" autojoin. . . . . . . . . : null ('%s')",
@@ -7336,6 +7412,7 @@ irc_server_print_log ()
weechat_log_printf (" reconnect_delay . . . . . : %d", ptr_server->reconnect_delay);
weechat_log_printf (" reconnect_start . . . . . : %lld", (long long)ptr_server->reconnect_start);
weechat_log_printf (" command_time. . . . . . . : %lld", (long long)ptr_server->command_time);
weechat_log_printf (" autojoin_time . . . . . . : %lld", (long long)ptr_server->autojoin_time);
weechat_log_printf (" autojoin_done . . . . . . : %d", ptr_server->autojoin_done);
weechat_log_printf (" disable_autojoin. . . . . : %d", ptr_server->disable_autojoin);
weechat_log_printf (" is_away . . . . . . . . . : %d", ptr_server->is_away);
+7 -3
View File
@@ -76,9 +76,10 @@ enum t_irc_server_option
IRC_SERVER_OPTION_REALNAME, /* real name */
IRC_SERVER_OPTION_LOCAL_HOSTNAME,/* custom local hostname */
IRC_SERVER_OPTION_USERMODE, /* usermode to set once connected */
IRC_SERVER_OPTION_COMMAND_DELAY, /* delay before execution of command */
IRC_SERVER_OPTION_COMMAND, /* command to run once connected */
IRC_SERVER_OPTION_COMMAND_DELAY, /* delay after execution of command */
IRC_SERVER_OPTION_AUTOJOIN, /* channels to automatically join */
IRC_SERVER_OPTION_AUTOJOIN_DELAY, /* delay before autojoin */
IRC_SERVER_OPTION_AUTOJOIN, /* channels to automatically join */
IRC_SERVER_OPTION_AUTOJOIN_DYNAMIC, /* auto set autojoin option */
IRC_SERVER_OPTION_AUTOREJOIN, /* auto rejoin channels when kicked */
IRC_SERVER_OPTION_AUTOREJOIN_DELAY, /* delay before auto rejoin */
@@ -269,7 +270,9 @@ struct t_irc_server
int reconnect_delay; /* current reconnect delay (growing) */
time_t reconnect_start; /* this time + delay = reconnect time */
time_t command_time; /* this time + command_delay = time to */
/* autojoin channels */
/* execute command */
time_t autojoin_time; /* this time + autojoin_delay = time to */
/* auto-join channels */
int autojoin_done; /* 1 if autojoin has been done */
int disable_autojoin; /* 1 if user asked to not autojoin chans */
int is_away; /* 1 is user is marked as away */
@@ -445,6 +448,7 @@ extern void irc_server_switch_address (struct t_irc_server *server,
extern void irc_server_disconnect (struct t_irc_server *server,
int switch_address, int reconnect);
extern void irc_server_disconnect_all ();
extern void irc_server_execute_command (struct t_irc_server *server);
extern void irc_server_free_sasl_data (struct t_irc_server *server);
extern void irc_server_free (struct t_irc_server *server);
extern int irc_server_xfer_send_ready_cb (const void *pointer, void *data,
+1
View File
@@ -649,6 +649,7 @@ irc_upgrade_read_cb (const void *pointer, void *data,
irc_upgrade_current_server->reconnect_delay = weechat_infolist_integer (infolist, "reconnect_delay");
irc_upgrade_current_server->reconnect_start = weechat_infolist_time (infolist, "reconnect_start");
irc_upgrade_current_server->command_time = weechat_infolist_time (infolist, "command_time");
irc_upgrade_current_server->autojoin_time = weechat_infolist_time (infolist, "autojoin_time");
irc_upgrade_current_server->autojoin_done = weechat_infolist_integer (infolist, "autojoin_done");
irc_upgrade_current_server->disable_autojoin = weechat_infolist_integer (infolist, "disable_autojoin");
irc_upgrade_current_server->is_away = weechat_infolist_integer (infolist, "is_away");