From ad1f6c3139d839e2fb9b8ccf92bb678dc30d549b Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Sat, 19 Mar 2022 22:42:31 -0500 Subject: [PATCH] Use new logger for commands --- commands/rounds.js | 3 ++- commands/top.js | 5 ++--- commands/train.js | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/commands/rounds.js b/commands/rounds.js index a9167c0..be18c2a 100644 --- a/commands/rounds.js +++ b/commands/rounds.js @@ -3,6 +3,7 @@ const { MessageEmbed } = require('discord.js'); const axios = require('axios'); +const { log } = require('../helpers/log'); const generatedRound = require('../models/generateRound'); module.exports = { @@ -66,7 +67,7 @@ module.exports = { newGeneratedRound.save((err, round) => { if (err) { - console.log(err); + log({ logger: 'rounds', content: `Saving round to DB failed: ${err}`, level: 'error' }); return; } interaction.reply(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true }); diff --git a/commands/top.js b/commands/top.js index bb5abb9..f08413e 100644 --- a/commands/top.js +++ b/commands/top.js @@ -1,6 +1,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders'); const { MessageEmbed } = require('discord.js'); +const { log } = require('../helpers/log'); const userScore = require('../models/userScore'); module.exports = { @@ -14,10 +15,8 @@ module.exports = { .sort({ score: -1 }) // Sort by descending order .exec((err, obj) => { if (err) { + log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' }); console.log(err); - return interaction.reply( - 'Uh oh! :( There was an internal error. Please try again.', - ); } if (obj.length < 10) { // Need at least 10 scores for top 10 diff --git a/commands/train.js b/commands/train.js index d050dbd..98fb1f1 100644 --- a/commands/train.js +++ b/commands/train.js @@ -6,6 +6,7 @@ const axios = require('axios'); const userScore = require('../models/userScore'); +const { log } = require('../helpers/log.js'); const { updateScore } = require('../helpers/db.js'); module.exports = { @@ -42,7 +43,7 @@ module.exports = { score = obj.score; } else { - console.log(err); + log({ logger: 'train', content: `Getting user score failed: ${err}`, level: 'error' }); } }); @@ -102,7 +103,6 @@ module.exports = { max: 1, }) .then(collected => { - console.log(collected.first()); const answerMsg = collected.first(); let predicted = null; @@ -159,11 +159,11 @@ module.exports = { updateScore(true, score, authorId).then((msgToReply) => answerMsg.reply(msgToReply), ); - }).catch(console.error); - }).catch(console.error); + }).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' })); + }).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' })); } - }).catch(console.error); - }).catch(console.error); - }).catch(console.error); + }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' })); + }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' })); + }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' })); }, };