diff --git a/backend/dao/bot.js b/backend/dao/bot.ts similarity index 66% rename from backend/dao/bot.js rename to backend/dao/bot.ts index 5fc9b7fc7..7620ceff0 100644 --- a/backend/dao/bot.js +++ b/backend/dao/bot.ts @@ -1,6 +1,7 @@ +import { InsertManyResult, InsertOneResult } from "mongodb"; import db from "../init/db"; -async function addCommand(command, commandArguments) { +async function addCommand(command, commandArguments): Promise { return await db.collection("bot-commands").insertOne({ command, arguments: commandArguments, @@ -9,9 +10,12 @@ async function addCommand(command, commandArguments) { }); } -async function addCommands(commands, commandArguments) { +async function addCommands( + commands, + commandArguments +): Promise { if (commands.length === 0 || commands.length !== commandArguments.length) { - return []; + return; } const normalizedCommands = commands.map((command, index) => { @@ -27,25 +31,31 @@ async function addCommands(commands, commandArguments) { } class BotDAO { - static async updateDiscordRole(discordId, wpm) { + static async updateDiscordRole(discordId, wpm): Promise { return await addCommand("updateRole", [discordId, wpm]); } - static async linkDiscord(uid, discordId) { + static async linkDiscord(uid, discordId): Promise { return await addCommand("linkDiscord", [discordId, uid]); } - static async unlinkDiscord(uid, discordId) { + static async unlinkDiscord(uid, discordId): Promise { return await addCommand("unlinkDiscord", [discordId, uid]); } - static async awardChallenge(discordId, challengeName) { + static async awardChallenge( + discordId, + challengeName + ): Promise { return await addCommand("awardChallenge", [discordId, challengeName]); } - static async announceLbUpdate(newRecords, leaderboardId) { + static async announceLbUpdate( + newRecords, + leaderboardId + ): Promise { if (newRecords.length === 0) { - return []; + return; } const leaderboardCommands = Array(newRecords.length).fill("sayLbUpdate");