summaryrefslogtreecommitdiff
path: root/src/plugins/plugin-api.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2016-12-31 18:28:55 +0100
committerSébastien Helleu <flashcode@flashtux.org>2016-12-31 18:28:55 +0100
commit668bb3a4add26ae0193ec97097210441e8217b75 (patch)
tree68357b353c9f564187fd5bc4565e66da18ac6720 /src/plugins/plugin-api.c
parentc6baabff27206ff581502106312237c4ecb24e6b (diff)
downloadweechat-668bb3a4add26ae0193ec97097210441e8217b75.zip
api: add info "uptime" (WeeChat uptime)
Diffstat (limited to 'src/plugins/plugin-api.c')
-rw-r--r--src/plugins/plugin-api.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/plugins/plugin-api.c b/src/plugins/plugin-api.c
index 280d830af..db0612de1 100644
--- a/src/plugins/plugin-api.c
+++ b/src/plugins/plugin-api.c
@@ -842,6 +842,52 @@ plugin_api_info_nick_color_name_cb (const void *pointer, void *data,
}
/*
+ * Returns WeeChat info "uptime".
+ */
+
+const char *
+plugin_api_info_uptime_cb (const void *pointer, void *data,
+ const char *info_name,
+ const char *arguments)
+{
+ static char value[32];
+ time_t total_seconds;
+ int days, hours, minutes, seconds;
+
+ /* make C compiler happy */
+ (void) pointer;
+ (void) data;
+ (void) info_name;
+
+ if (!arguments || !arguments[0])
+ {
+ /* return uptime with format: "days:hh:mm:ss" */
+ util_get_uptime (NULL, &days, &hours, &minutes, &seconds);
+ snprintf (value, sizeof (value), "%d:%02d:%02d:%02d",
+ days, hours, minutes, seconds);
+ return value;
+ }
+
+ if (strcmp (arguments, "days") == 0)
+ {
+ /* return the number of days */
+ util_get_uptime (NULL, &days, NULL, NULL, NULL);
+ snprintf (value, sizeof (value), "%d", days);
+ return value;
+ }
+
+ if (strcmp (arguments, "seconds") == 0)
+ {
+ /* return the number of seconds */
+ util_get_uptime (&total_seconds, NULL, NULL, NULL, NULL);
+ snprintf (value, sizeof (value), "%ld", total_seconds);
+ return value;
+ }
+
+ return NULL;
+}
+
+/*
* Returns WeeChat infolist "bar".
*
* Note: result must be freed after use with function weechat_infolist_free().
@@ -1922,6 +1968,11 @@ plugin_api_init ()
N_("get nick color name"),
N_("nickname"),
&plugin_api_info_nick_color_name_cb, NULL, NULL);
+ hook_info (NULL, "uptime",
+ N_("WeeChat uptime (format: \"days:hh:mm:ss\")"),
+ N_("\"days\" (number of days) or \"seconds\" (number of "
+ "seconds) (optional)"),
+ &plugin_api_info_uptime_cb, NULL, NULL);
/* WeeChat core infolist hooks */
hook_infolist (NULL, "bar",