ZyklonB: factor out make_status_report()
This commit is contained in:
parent
3582789cf5
commit
e8aefd9f96
60
zyklonb.c
60
zyklonb.c
|
@ -1279,6 +1279,36 @@ process_plugin_reload (struct bot_context *ctx,
|
||||||
process_plugin_load (ctx, msg, name);
|
process_plugin_load (ctx, msg, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static char *
|
||||||
|
make_status_report (struct bot_context *ctx)
|
||||||
|
{
|
||||||
|
struct str report;
|
||||||
|
str_init (&report);
|
||||||
|
|
||||||
|
const char *reason = getenv (g_startup_reason_str);
|
||||||
|
if (!reason)
|
||||||
|
reason = "launched normally";
|
||||||
|
str_append_printf (&report, "\x02startup reason:\x0f %s", reason);
|
||||||
|
|
||||||
|
size_t zombies = 0;
|
||||||
|
const char *prepend = "; \x02plugins:\x0f ";
|
||||||
|
for (struct plugin *plugin = ctx->plugins; plugin; plugin = plugin->next)
|
||||||
|
{
|
||||||
|
if (plugin->is_zombie)
|
||||||
|
zombies++;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str_append_printf (&report, "%s%s", prepend, plugin->name);
|
||||||
|
prepend = ", ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!ctx->plugins)
|
||||||
|
str_append_printf (&report, "%s\x02none\x0f", prepend);
|
||||||
|
|
||||||
|
str_append_printf (&report, "; \x02zombies:\x0f %zu", zombies);
|
||||||
|
return str_steal (&report);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
|
process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
|
||||||
{
|
{
|
||||||
|
@ -1317,33 +1347,9 @@ process_privmsg (struct bot_context *ctx, const struct irc_message *msg)
|
||||||
}
|
}
|
||||||
else if (parse_bot_command (text, "status", &following))
|
else if (parse_bot_command (text, "status", &following))
|
||||||
{
|
{
|
||||||
struct str report;
|
char *report = make_status_report (ctx);
|
||||||
str_init (&report);
|
respond_to_user (ctx, msg, "%s", report);
|
||||||
|
free (report);
|
||||||
const char *reason = getenv (g_startup_reason_str);
|
|
||||||
if (!reason)
|
|
||||||
reason = "launched normally";
|
|
||||||
str_append_printf (&report,
|
|
||||||
"\x02startup reason:\x0f %s; \x02plugins:\x0f ", reason);
|
|
||||||
size_t zombies = 0;
|
|
||||||
const char *prepend = "";
|
|
||||||
for (struct plugin *plugin = ctx->plugins;
|
|
||||||
plugin; plugin = plugin->next)
|
|
||||||
{
|
|
||||||
if (plugin->is_zombie)
|
|
||||||
zombies++;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
str_append_printf (&report, "%s%s", prepend, plugin->name);
|
|
||||||
prepend = ", ";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!ctx->plugins)
|
|
||||||
str_append (&report, "\x02none\x0f");
|
|
||||||
str_append_printf (&report, "; \x02zombies:\x0f %zu", zombies);
|
|
||||||
|
|
||||||
respond_to_user (ctx, msg, "%s", report.str);
|
|
||||||
str_free (&report);
|
|
||||||
}
|
}
|
||||||
else if (parse_bot_command (text, "load", &following))
|
else if (parse_bot_command (text, "load", &following))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue