diff --git a/backend/dao/botDAO.js b/backend/dao/botDAO.js index 801b8d485..71ee1cde2 100644 --- a/backend/dao/botDAO.js +++ b/backend/dao/botDAO.js @@ -1,11 +1,38 @@ const MonkeyError = require("../handlers/error"); const { mongoDB } = require("../init/mongodb"); -class BotDAO { - static async addCommand(command, arguments) { - return await mongoDB() - .collection("bot-commands") - .insertOne({ command, arguments, executed: false, requestTimestamp: Date.now() }); - } + +async function addCommand(command, arguments) { + return await mongoDB() + .collection("bot-commands") + .insertOne({ + command, + arguments, + executed: false, + requestTimestamp: Date.now(), + }); } -module.exports = BotDAO; \ No newline at end of file +class BotDAO { + static async updateDiscordRole(discordId, wpm) { + return await addCommand("updateRole", [discordId, wpm]); + } + + static async announceLbUpdate(discordId, pos, lb, wpm, raw, acc, con) { + return await addCommand("sayLbUpdate", [ + discordId, + pos, + lb, + wpm, + raw, + acc, + con, + ]); + } + + // this probably will be rewritten but keeping the old code just in case + // static async announceDailyLbResult(lbdata) { + // return await addCommand("announceDailyLbResult", [lbdata]); + // } +} + +module.exports = BotDAO; diff --git a/backend/handlers/bot.js b/backend/handlers/bot.js deleted file mode 100644 index 88fe601a7..000000000 --- a/backend/handlers/bot.js +++ /dev/null @@ -1,31 +0,0 @@ - -function updateDiscordRole(discordId, wpm) { - newBotCommand = new BotCommand({ - command: "updateRole", - arguments: [discordId, wpm], - executed: false, - requestTimestamp: Date.now(), - }); - newBotCommand.save(); -} - -async function announceLbUpdate(discordId, pos, lb, wpm, raw, acc, con) { - newBotCommand = new BotCommand({ - command: "sayLbUpdate", - arguments: [discordId, pos, lb, wpm, raw, acc, con], - executed: false, - requestTimestamp: Date.now(), - }); - newBotCommand.save(); -} - -async function announceDailyLbResult(lbdata) { - newBotCommand = new BotCommand({ - command: "announceDailyLbResult", - arguments: [lbdata], - executed: false, - requestTimestamp: Date.now(), - }); - newBotCommand.save(); -} -