Added shard count to prometheus metrics, catch message deletes in soundplayer

This commit is contained in:
Essem 2021-09-20 18:32:59 -05:00
parent 264b59ba59
commit 3f28bf815c
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 10 additions and 3 deletions

View file

@ -17,6 +17,8 @@ class PrometheusWorker extends BaseServiceWorker {
# TYPE esmbot_command_count counter # TYPE esmbot_command_count counter
# HELP esmbot_server_count Number of servers/guilds the bot is in # HELP esmbot_server_count Number of servers/guilds the bot is in
# TYPE esmbot_server_count gauge # TYPE esmbot_server_count gauge
# HELP esmbot_shard_count Number of shards the bot has
# TYPE esmbot_shard_count gauge
`); `);
if (process.env.API === "true") { if (process.env.API === "true") {
const servers = await this.ipc.command("image", { type: "stats" }, true); const servers = await this.ipc.command("image", { type: "stats" }, true);
@ -43,6 +45,7 @@ esmbot_connected_workers ${servers.length}
const stats = await this.ipc.getStats(); const stats = await this.ipc.getStats();
res.write(`esmbot_server_count ${stats.guilds}\n`); res.write(`esmbot_server_count ${stats.guilds}\n`);
res.write(`esmbot_shard_count ${stats.shardCount}\n`);
res.end(); res.end();
}); });
this.httpServer.listen(process.env.METRICS, () => { this.httpServer.listen(process.env.METRICS, () => {

View file

@ -133,9 +133,13 @@ export async function nextSong(client, message, connection, track, info, music,
await connection.volume(75); await connection.volume(75);
players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, shuffle: shuffle, playMessage: playingMessage }); players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: message.author.id, voiceChannel: voiceChannel, originalChannel: message.channel, loop: loop, shuffle: shuffle, playMessage: playingMessage });
connection.once("error", (error) => { connection.once("error", (error) => {
try {
if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete(); if (playingMessage.channel.messages.get(playingMessage.id)) playingMessage.delete();
const playMessage = players.get(voiceChannel.guild.id).playMessage; const playMessage = players.get(voiceChannel.guild.id).playMessage;
if (playMessage.channel.messages.get(playMessage.id)) playMessage.delete(); if (playMessage.channel.messages.get(playMessage.id)) playMessage.delete();
} catch {
// no-op
}
manager.leave(voiceChannel.guild.id); manager.leave(voiceChannel.guild.id);
connection.removeAllListeners("end"); connection.removeAllListeners("end");
connection.destroy(); connection.destroy();