diff --git a/src/index.js b/src/index.js index e09a91b..41f46d1 100644 --- a/src/index.js +++ b/src/index.js @@ -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]); diff --git a/src/modules/bot.js b/src/modules/bot.js index 7352bc5..765a16c 100644 --- a/src/modules/bot.js +++ b/src/modules/bot.js @@ -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);