Skip to content

Commit

Permalink
Merge pull request #757 from ViBotTeam/huntifer/add-afkcheckmodules-l…
Browse files Browse the repository at this point in the history
…ogging

Add afkcheck and afkmodule logging to influxDB
  • Loading branch information
Ragviswa authored Feb 23, 2024
2 parents f84eacf + 6dcaf47 commit 0f78f32
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions commands/afkCheck.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand Down Expand Up @@ -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) })
}

Expand Down
14 changes: 13 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -168,6 +169,17 @@ 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
// ===========================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vibot",
"version": "8.16.5",
"version": "8.16.6",
"description": "ViBot",
"main": "index.js",
"dependencies": {
Expand Down

0 comments on commit 0f78f32

Please sign in to comment.