From 83a3e44d6bc162a6c054951bf9071b98fd2687f3 Mon Sep 17 00:00:00 2001 From: Huntifer Date: Fri, 23 Feb 2024 08:00:53 -0600 Subject: [PATCH 1/3] Add afkcheck and afkmodule logging to influxDB --- commands/afkCheck.js | 18 ++++++++++++++++++ index.js | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/commands/afkCheck.js b/commands/afkCheck.js index 24217dc5..0e635fe1 100644 --- a/commands/afkCheck.js +++ b/commands/afkCheck.js @@ -7,6 +7,8 @@ const extensions = require(`../lib/extensions`) const consumablePopTemplates = require(`../data/keypop.json`); const popCommand = require('./pop.js'); const AfkButton = require('../lib/afk/AfkButton'); +const { writePoint } = require('../metrics.js'); +const { Point } = require('@influxdata/influxdb-client'); module.exports = { name: 'afk', @@ -80,6 +82,9 @@ module.exports = { console.log(afkTemplate.message()) continue } + writePoint(new Point('afkchecksmodules') + .tag('raidID', currentStoredAfkCheck.raidID) + .stringField('module', 'insert')) bot.afkModules[currentStoredAfkCheck.raidID] = new afkCheck(afkTemplate, bot, db, message, currentStoredAfkCheck.location) await bot.afkModules[currentStoredAfkCheck.raidID].loadBotAfkCheck(currentStoredAfkCheck) } @@ -182,6 +187,9 @@ class afkCheck { async start() { if (this.phase === 0) this.phase = 1 this.timer = new Date(Date.now() + (this.#body[this.phase].timeLimit * 1000)) + writePoint(new Point('afkchecksmodules') + .tag('raidID', this.#raidID) + .stringField('module', 'insert')) this.#bot.afkModules[this.#raidID] = this await Promise.all([this.sendStatusMessage(), this.sendCommandsMessage(), this.sendChannelsMessage()]) this.startTimers() @@ -194,10 +202,17 @@ class afkCheck { saveBotAfkCheck(deleteCheck = false) { if (deleteCheck) { + writePoint(new Point('afkchecksmodules') + .tag('raidID', this.#raidID) + .stringField('check', 'delete') + .stringField('module', 'delete')) delete this.#bot.afkChecks[this.#raidID] delete this.#bot.afkModules[this.#raidID] } else { + writePoint(new Point('afkchecksmodules') + .tag('raidID', this.#raidID) + .stringField('check', 'create')) this.#bot.afkChecks[this.#raidID] = { afkTemplateName: this.afkTemplateName, message: this.#message, @@ -229,6 +244,9 @@ class afkCheck { raidChannelsMessage: this.raidChannelsMessage, } } + writePoint(new Point('afkchecksmodules') + .tag('raidID', this.#raidID) + .booleanField('fileWrite', true)) fs.writeFileSync('./data/afkChecks.json', JSON.stringify(this.#bot.afkChecks, null, 4), err => { if (err) ErrorLogger.log(err, this.#bot, this.#guild) }) } diff --git a/index.js b/index.js index 449ea197..52a28151 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,8 @@ const ErrorLogger = require('./lib/logError'); const botSetup = require('./botSetup.js'); const dbSetup = require('./dbSetup.js'); const memberHandler = require('./memberHandler.js'); -const { logWrapper } = require('./metrics.js'); +const { logWrapper, writePoint } = require('./metrics.js'); +const { Point } = require('@influxdata/influxdb-client'); const { handleReactionRow } = require('./redis.js'); const Modmail = require('./lib/modmail.js'); // Specific Commands @@ -168,6 +169,18 @@ Promise.all(botSettings.config?.guildIds.map(guildId => { bot.login(botSettings.key); }); +setInterval(() => { + for (const afkCheckId of Object.keys(bot.afkChecks)) { + writePoint(new Point('afkchecksmodulesinterval') + .stringField('afkCheck', afkCheckId)) + } + for (const afkModuleId of Object.keys(bot.afkModules)) { + writePoint(new Point('afkchecksmodulesinterval') + .stringField('afkModule', afkModuleId)) + } +}, 60000) + + // =========================================================================================================== // Process Event Listening // =========================================================================================================== From 32796f3071746181f49d223df5e92852febabdab Mon Sep 17 00:00:00 2001 From: Huntifer Date: Fri, 23 Feb 2024 08:05:06 -0600 Subject: [PATCH 2/3] eslint --- index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 52a28151..62bbc883 100644 --- a/index.js +++ b/index.js @@ -172,14 +172,13 @@ Promise.all(botSettings.config?.guildIds.map(guildId => { setInterval(() => { for (const afkCheckId of Object.keys(bot.afkChecks)) { writePoint(new Point('afkchecksmodulesinterval') - .stringField('afkCheck', afkCheckId)) + .stringField('afkCheck', afkCheckId)); } for (const afkModuleId of Object.keys(bot.afkModules)) { writePoint(new Point('afkchecksmodulesinterval') - .stringField('afkModule', afkModuleId)) + .stringField('afkModule', afkModuleId)); } -}, 60000) - +}, 60000); // =========================================================================================================== // Process Event Listening From 6dcaf47855a4ffa64d256075900af89734fa0e97 Mon Sep 17 00:00:00 2001 From: Raghav Viswakumar Date: Fri, 23 Feb 2024 17:40:14 +0000 Subject: [PATCH 3/3] Updated package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d71f0596..9a25595f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vibot", - "version": "8.16.5", + "version": "8.16.6", "description": "ViBot", "main": "index.js", "dependencies": {