Browse Source

Add score migrate script to prepare for merge to master

pull/9/head
Abheek Dhawan 4 years ago
parent
commit
6ae88b1061
  1. 1
      .gitignore
  2. 5
      bot/awesomescibo.mjs
  3. 38
      bot/migrateScores.js
  4. 4
      bot/package-lock.json
  5. 1
      bot/userScore/745063586422063214

1
.gitignore

@ -8,3 +8,4 @@ bot/README.md
.eslintrc .eslintrc
.json .json
.env .env
userScore/*

5
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!)"; "`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", () => { client.once("ready", () => {
// Connect to MongoDB using mongoose
mongoose mongoose
.connect(process.env.MONGO_URI, { .connect(process.env.MONGO_URI, {
useUnifiedTopology: true, useUnifiedTopology: true,
useNewUrlParser: true, useNewUrlParser: true,
}) })
.then(() => { .then(() => {
console.log(client.user.username); // Log client tag and set status
console.log(`Logged in as: ${client.user.username}!`);
client.user.setActivity( client.user.setActivity(
'for "do be helping" | Add me to your own server: adat.link/awscibo', 'for "do be helping" | Add me to your own server: adat.link/awscibo',
{ type: "WATCHING" } { type: "WATCHING" }
@ -35,6 +37,7 @@ client.on("guildCreate", (guild) => {
guild.channels.cache guild.channels.cache
.find( .find(
(channel) => (channel) =>
// Find channel by name
channel.name === process.env.WELCOME_CHANNEL && channel.type === "text" channel.name === process.env.WELCOME_CHANNEL && channel.type === "text"
) )
.send("'Sup, I'm the AwesomeSciBo bot!") .send("'Sup, I'm the AwesomeSciBo bot!")

38
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));

4
bot/package-lock.json

@ -391,7 +391,6 @@
"node": ">=0.10" "node": ">=0.10"
} }
}, },
"node_modules/discord.js": { "node_modules/discord.js": {
"version": "12.5.1", "version": "12.5.1",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz", "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz",
@ -944,8 +943,7 @@
"bson": "^1.1.4", "bson": "^1.1.4",
"denque": "^1.4.1", "denque": "^1.4.1",
"optional-require": "^1.0.2", "optional-require": "^1.0.2",
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2"
"saslprep": "^1.0.0"
}, },
"engines": { "engines": {
"node": ">=4" "node": ">=4"

1
bot/userScore/745063586422063214

@ -1 +0,0 @@
8
Loading…
Cancel
Save