From 6ae88b1061396c3ece35799dea981d6e34994ae5 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Sat, 1 May 2021 21:59:01 -0500 Subject: [PATCH] Add score migrate script to prepare for merge to master --- .gitignore | 3 ++- bot/awesomescibo.mjs | 7 ++++-- bot/migrateScores.js | 38 ++++++++++++++++++++++++++++++++ bot/package-lock.json | 6 ++--- bot/userScore/745063586422063214 | 1 - 5 files changed, 47 insertions(+), 8 deletions(-) create mode 100644 bot/migrateScores.js delete mode 100644 bot/userScore/745063586422063214 diff --git a/.gitignore b/.gitignore index c607f42..6ec2bb9 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ round.pdf bot/README.md .eslintrc .json -.env \ No newline at end of file +.env +userScore/* diff --git a/bot/awesomescibo.mjs b/bot/awesomescibo.mjs index b58996c..6da91f5 100755 --- a/bot/awesomescibo.mjs +++ b/bot/awesomescibo.mjs @@ -16,13 +16,15 @@ const helpMessage = "`do be helping`: display this help message\n`do be roundgen`: send a pdf round to the channel\n`do be roundgen dm`: dm a pdf round to you\n`do be scoring`: start a scoring session\n > `do be scoring (a/b)(4/10)`: add points to Team A or Team B\n > `do be scoring stop`: end scoring session and post final points\n > `do be servers`: send the number of servers this bot is a part of\n > `do be iss`: show the current location of the International Space Station\n`do be training`: send a quick practice problem (you **must** react to your answer, or the bot will yell at you)\n > subject options: astro, phys, chem, math, bio, ess, energy\n`do be top`: list cross-server top 10 players\n `do be about`: List people who contributed to this bot\n Source Code: https://github.com/ADawesomeguy/AwesomeSciBo (don't forget to star!)"; client.once("ready", () => { + // Connect to MongoDB using mongoose mongoose .connect(process.env.MONGO_URI, { useUnifiedTopology: true, useNewUrlParser: true, }) .then(() => { - console.log(client.user.username); + // Log client tag and set status + console.log(`Logged in as: ${client.user.username}!`); client.user.setActivity( 'for "do be helping" | Add me to your own server: adat.link/awscibo', { type: "WATCHING" } @@ -35,6 +37,7 @@ client.on("guildCreate", (guild) => { guild.channels.cache .find( (channel) => + // Find channel by name channel.name === process.env.WELCOME_CHANNEL && channel.type === "text" ) .send("'Sup, I'm the AwesomeSciBo bot!") @@ -496,7 +499,7 @@ function showLeaderboard(message) { function aboutMessage(message) { message.channel.send( new Discord.MessageEmbed().setTitle("Contributors: ").setDescription(` - <@745063586422063214> + <@745063586422063214> <@650525101048987649> `) // Add more contributors here, first one is Abheek, second one is Tejas ); diff --git a/bot/migrateScores.js b/bot/migrateScores.js new file mode 100644 index 0000000..2e208bb --- /dev/null +++ b/bot/migrateScores.js @@ -0,0 +1,38 @@ +const fs = require("fs"); +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const dirName = "userScore"; + +const fileNames = fs.readdirSync(dirName); + +const userScoreSchema = new Schema({ + authorID: { + type: String, + required: true, + }, + score: { + type: Number, + required: true, + }, +}); + +const userScore = mongoose.model("UserScore", userScoreSchema); + +mongoose + .connect(process.env.MONGO_URI, { + useUnifiedTopology: true, + useNewUrlParser: true, + }) + .then(() => { + fileNames.forEach(file => { + fs.readFile(dirName + "/" + file, 'utf-8', (err, content) => { + const migrateScore = new userScore({ + authorID: file, + score: content, + }); + migrateScore.save(); + }); + }); + }) + .catch((err) => console.log(err)); diff --git a/bot/package-lock.json b/bot/package-lock.json index 8207f1a..df633ab 100644 --- a/bot/package-lock.json +++ b/bot/package-lock.json @@ -391,7 +391,6 @@ "node": ">=0.10" } }, - "node_modules/discord.js": { "version": "12.5.1", "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz", @@ -944,8 +943,7 @@ "bson": "^1.1.4", "denque": "^1.4.1", "optional-require": "^1.0.2", - "safe-buffer": "^5.1.2", - "saslprep": "^1.0.0" + "safe-buffer": "^5.1.2" }, "engines": { "node": ">=4" @@ -2578,7 +2576,7 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" } } - }, + }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", diff --git a/bot/userScore/745063586422063214 b/bot/userScore/745063586422063214 deleted file mode 100644 index 301160a..0000000 --- a/bot/userScore/745063586422063214 +++ /dev/null @@ -1 +0,0 @@ -8 \ No newline at end of file