socketstats command
This commit is contained in:
parent
28bdba1fd4
commit
aca7f96c26
2 changed files with 22 additions and 0 deletions
|
@ -56,6 +56,7 @@ global.hf = {
|
||||||
events,
|
events,
|
||||||
timer,
|
timer,
|
||||||
database,
|
database,
|
||||||
|
event_stats: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const {formatUsername} = require("#util/misc.js");
|
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)}`);
|
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) {
|
instead("spawn", bot.shards, function (args, orig) {
|
||||||
const ret = orig.apply(this, args);
|
const ret = orig.apply(this, args);
|
||||||
const shard = this.get(args[0]);
|
const shard = this.get(args[0]);
|
||||||
|
|
|
@ -221,3 +221,17 @@ settings.callback = async function (msg, line, [cmd, key, value]) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
hf.registerCommand(settings);
|
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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue