Browse Source

Still need to fix auth issue with Docker

pull/7/head
TejasOS 4 years ago
parent
commit
0dc7ca6219
  1. 32
      bot/awesomescibo.mjs

32
bot/awesomescibo.mjs

@ -11,16 +11,19 @@ import * as path from "path";
import axios from "axios"; import axios from "axios";
import userScore from "./mongooseModels/mongooseUserScoreModel.js"; import userScore from "./mongooseModels/mongooseUserScoreModel.js";
import {} from 'dotenv/config.js'; import {} from 'dotenv/config.js';
import mongoose from "mongoose";
const helpMessage = 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\nSource 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\nSource Code: https://github.com/ADawesomeguy/AwesomeSciBo (don't forget to star!)";
client.once("ready", () => { client.once("ready", () => {
console.log(client.user.username); mongoose.connect(process.env.MONGO_URI, {useUnifiedTopology: true, useNewUrlParser: true}).then(() => {
client.user.setActivity( console.log(client.user.username);
'for "do be helping" | Add me to your own server: adat.link/awscibo', client.user.setActivity(
{ type: "WATCHING" } 'for "do be helping" | Add me to your own server: adat.link/awscibo',
); { type: "WATCHING" }
)
}).catch(err => console.log(err))
}); });
client.on("guildCreate", (guild) => { client.on("guildCreate", (guild) => {
@ -35,6 +38,8 @@ client.on("message", async (message) => {
return; return;
} }
const formattedMessage = message.content.toLowerCase().replace(/\s+/g, ""); const formattedMessage = message.content.toLowerCase().replace(/\s+/g, "");
if (formattedMessage.startsWith("dobe")) { if (formattedMessage.startsWith("dobe")) {
switch (formattedMessage) { switch (formattedMessage) {
@ -75,7 +80,7 @@ client.on("message", async (message) => {
const announcement = message.content.substring(17); const announcement = message.content.substring(17);
client.guilds.cache.forEach((guild) => { client.guilds.cache.forEach((guild) => {
const channel = guild.channels.cache.find( const channel = guild.channels.cache.find(
(channel) => channel.name === "general" (channelGeneral) => channelGeneral.name === "general"
); );
if (channel) { if (channel) {
if (channel.type === "text") { if (channel.type === "text") {
@ -97,8 +102,8 @@ client.on("message", async (message) => {
errors: ["time"], errors: ["time"],
}); });
}) })
.then((message) => { .then(resMessage => {
const responseAuthorID = message.first().author.id; const responseAuthorID = resMessage.first().author.id;
}); });
}); });
} else { } else {
@ -135,7 +140,6 @@ client.on("message", async (message) => {
default: default:
message.channel.send("Not a valid subject!"); message.channel.send("Not a valid subject!");
return; return;
break;
} }
const authorId = message.author.id; const authorId = message.author.id;
fetch(subjectURL) fetch(subjectURL)
@ -152,9 +156,9 @@ client.on("message", async (message) => {
}) })
.then((answerMsg) => { .then((answerMsg) => {
answerMsg = answerMsg.first(); answerMsg = answerMsg.first();
let score = const userDocScore = userScore.findOne({authorID: authorId}).select("score");
userScore.findOne({ authorID: authorId }).select("score") || let score = userDocScore || 0;
0;
let predicted = null; let predicted = null;
if (data[questionNum].tossup_format === "Multiple Choice") { if (data[questionNum].tossup_format === "Multiple Choice") {
if ( if (
@ -195,7 +199,7 @@ client.on("message", async (message) => {
.then(async (userReaction) => { .then(async (userReaction) => {
const reaction = userReaction.first(); const reaction = userReaction.first();
if (reaction.emoji.name === "❌") { if (reaction.emoji.name === "❌") {
answerMsg.reply(`nice try! Your score is now ${score}`); answerMsg.reply(`nice try! Your score is now ${score.toString()}`);
} else { } else {
score += 4; score += 4;
if (score == 4) { if (score == 4) {
@ -220,7 +224,7 @@ client.on("message", async (message) => {
doc.save(); doc.save();
} }
answerMsg.reply(`nice job! Your score is now ${score}`); answerMsg.reply(`nice job! Your score is now ${score.toString()}`);
} }
}) })
.catch((collected) => {}); .catch((collected) => {});

Loading…
Cancel
Save