socketstats command

This commit is contained in:
Cynthia Foxwell 2025-03-16 12:23:19 -06:00
parent 28bdba1fd4
commit aca7f96c26
Signed by: Cynosphere
SSH key fingerprint: SHA256:H3SM8ufP/uxqLwKSH7xY89TDnbR9uOHzjLoBr0tlajk
2 changed files with 22 additions and 0 deletions

View file

@ -56,6 +56,7 @@ global.hf = {
events,
timer,
database,
event_stats: {},
};
const {formatUsername} = require("#util/misc.js");
@ -229,6 +230,13 @@ bot.on("unknown", (packet, id) => {
logger.verbose("hf:main", `Shard ${id} caught unknown packet:\n ${JSON.stringify(packet)}`);
});
bot.on("rawWS", (packet) => {
if (packet.op === 0 && packet.t != null) {
if (!hf.event_stats[packet.t]) hf.event_stats[packet.t] = 0;
hf.event_stats[packet.t]++;
}
});
instead("spawn", bot.shards, function (args, orig) {
const ret = orig.apply(this, args);
const shard = this.get(args[0]);

View file

@ -221,3 +221,17 @@ settings.callback = async function (msg, line, [cmd, key, value]) {
}
};
hf.registerCommand(settings);
const socketstats = new Command("socketstats");
socketstats.category = CATEGORY;
socketstats.helpText = "List the counts of socket events this session";
socketstats.callback = function () {
let out = "```c\n";
for (const [event, count] of Object.entries(hf.event_stats)) {
out += `"${event}": ${count}\n`;
}
out += "```";
return out;
};
hf.registerCommand(socketstats);