Browse Source

Use new logger for commands

pull/28/head
Abheek Dhawan 3 years ago
parent
commit
ad1f6c3139
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 3
      commands/rounds.js
  2. 5
      commands/top.js
  3. 14
      commands/train.js

3
commands/rounds.js

@ -3,6 +3,7 @@ const { MessageEmbed } = require('discord.js');
const axios = require('axios'); const axios = require('axios');
const { log } = require('../helpers/log');
const generatedRound = require('../models/generateRound'); const generatedRound = require('../models/generateRound');
module.exports = { module.exports = {
@ -66,7 +67,7 @@ module.exports = {
newGeneratedRound.save((err, round) => { newGeneratedRound.save((err, round) => {
if (err) { if (err) {
console.log(err); log({ logger: 'rounds', content: `Saving round to DB failed: ${err}`, level: 'error' });
return; return;
} }
interaction.reply(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true }); interaction.reply(`Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, { ephemeral: true });

5
commands/top.js

@ -1,6 +1,7 @@
const { SlashCommandBuilder } = require('@discordjs/builders'); const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js'); const { MessageEmbed } = require('discord.js');
const { log } = require('../helpers/log');
const userScore = require('../models/userScore'); const userScore = require('../models/userScore');
module.exports = { module.exports = {
@ -14,10 +15,8 @@ module.exports = {
.sort({ score: -1 }) // Sort by descending order .sort({ score: -1 }) // Sort by descending order
.exec((err, obj) => { .exec((err, obj) => {
if (err) { if (err) {
log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' });
console.log(err); console.log(err);
return interaction.reply(
'Uh oh! :( There was an internal error. Please try again.',
);
} }
if (obj.length < 10) { if (obj.length < 10) {
// Need at least 10 scores for top 10 // Need at least 10 scores for top 10

14
commands/train.js

@ -6,6 +6,7 @@ const axios = require('axios');
const userScore = require('../models/userScore'); const userScore = require('../models/userScore');
const { log } = require('../helpers/log.js');
const { updateScore } = require('../helpers/db.js'); const { updateScore } = require('../helpers/db.js');
module.exports = { module.exports = {
@ -42,7 +43,7 @@ module.exports = {
score = obj.score; score = obj.score;
} }
else { else {
console.log(err); log({ logger: 'train', content: `Getting user score failed: ${err}`, level: 'error' });
} }
}); });
@ -102,7 +103,6 @@ module.exports = {
max: 1, max: 1,
}) })
.then(collected => { .then(collected => {
console.log(collected.first());
const answerMsg = collected.first(); const answerMsg = collected.first();
let predicted = null; let predicted = null;
@ -159,11 +159,11 @@ module.exports = {
updateScore(true, score, authorId).then((msgToReply) => updateScore(true, score, authorId).then((msgToReply) =>
answerMsg.reply(msgToReply), answerMsg.reply(msgToReply),
); );
}).catch(console.error); }).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' }));
}).catch(console.error); }).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' }));
} }
}).catch(console.error); }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' }));
}).catch(console.error); }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' }));
}).catch(console.error); }).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' }));
}, },
}; };

Loading…
Cancel
Save