Browse Source

Clean up code

pull/22/head
Abheek Dhawan 3 years ago
parent
commit
fb4e0afc4e
Signed by: abheekd GPG Key ID: 7BE81B8C14475B67
  1. 81
      index.js
  2. 38
      migrateScores.js
  3. 0
      models/generateRound.js
  4. 0
      models/userScore.js

81
index.js

@ -3,20 +3,20 @@
require('dotenv').config(); require('dotenv').config();
const Discord = require("discord.js"); const Discord = require("discord.js");
const Intents = Discord.Intents;
const client = new Discord.Client({ const client = new Discord.Client({
intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "DIRECT_MESSAGES", "DIRECT_MESSAGE_REACTIONS"/*, "GUILD_MEMBERS", "GUILD_PRESENCES"*/], intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS", "DIRECT_MESSAGES", "DIRECT_MESSAGE_REACTIONS"/*, "GUILD_MEMBERS", "GUILD_PRESENCES"*/],
partials: ["MESSAGE", "CHANNEL", "REACTION"], partials: ["MESSAGE", "CHANNEL", "REACTION"],
}); });
const fetch = require("node-fetch");
const axios = require("axios"); const axios = require("axios");
const userScore = require("./mongooseModels/mongooseUserScoreModel.js");
const generatedRound = require("./mongooseModels/mongooseGeneratedRoundModel.js");
const mongoose = require("mongoose"); const mongoose = require("mongoose");
const gitlog = require("gitlog").default; const gitlog = require("gitlog").default;
const config = require("./config.json");
const decode = require('html-entities').decode; const decode = require('html-entities').decode;
const userScore = require("./models/userScore");
const generatedRound = require("./models/generateRound");
const config = require("./config.json");
const helpMessage = "AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon." const helpMessage = "AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon."
const slashCommands = require('./slashCommands.json') const slashCommands = require('./slashCommands.json')
@ -62,7 +62,7 @@ client.on("guildCreate", (guild) => {
} }
}); });
client.on("guildDelete", guild => { client.on("guildDelete", () => {
const topggAuthHeader = { const topggAuthHeader = {
headers: { headers: {
'Authorization': config.topggauth 'Authorization': config.topggauth
@ -204,7 +204,7 @@ async function training(subject, interaction) {
.setDescription(`It seems your answer was incorrect. Please react with <:override:842778128966615060> to override your answer if you think you got it right.`) .setDescription(`It seems your answer was incorrect. Please react with <:override:842778128966615060> to override your answer if you think you got it right.`)
.setColor("#ffffff") .setColor("#ffffff")
.setTimestamp(); .setTimestamp();
const overrideMsg = answerMsg.channel.send({ answerMsg.channel.send({
embeds: [overrideEmbed] embeds: [overrideEmbed]
}) })
.then(overrideMsg => { .then(overrideMsg => {
@ -220,7 +220,7 @@ async function training(subject, interaction) {
filter, filter,
max: 1 max: 1
}) })
.then((userReaction) => { .then(() => {
updateScore(true, score, authorId).then((msgToReply) => updateScore(true, score, authorId).then((msgToReply) =>
answerMsg.reply(msgToReply) answerMsg.reply(msgToReply)
); );
@ -237,71 +237,6 @@ function sendHelpMessage(interaction) {
interaction.reply({ embeds: [helpEmbed] }); interaction.reply({ embeds: [helpEmbed] });
} }
async function startScoring(message) {
let scoreA = 0;
let scoreB = 0;
await message.channel
.send(`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`)
.then((scoreboard) => {
const filter = (m) => m.content.includes("do be");
const collector = message.channel.createMessageCollector(filter, {
time: 1500000,
});
collector.on("collect", (m) => {
if (m.content.toLowerCase() === "/scoring a 4") {
// A team gets toss-up
m.delete({ timeout: 1000 }).catch(console.error);
scoreA += 4;
scoreboard.channel.send(
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
);
} else if (m.content.toLowerCase() === "/scoring a 10") {
// A team gets bonus
m.delete({ timeout: 1000 }).catch(console.error);
scoreA += 10;
scoreboard.channel.send(
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
);
} else if (m.content.toLowerCase() === "/scoring b 4") {
// B team gets toss up
m.delete({ timeout: 1000 }).catch(console.error);
scoreB += 4;
scoreboard.channel.send(
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
);
} else if (m.content.toLowerCase() === "/scoring b 10") {
// B team gets bonus
m.delete({ timeout: 1000 }).catch(console.error);
scoreB += 10;
scoreboard.channel.send(
`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
);
} else if (m.content === "/scoring stop") {
m.delete({ timeout: 1000 }).catch(console.error);
scoreboard.delete({ timeout: 1000 });
m.channel.send(
`**FINAL SCORE:**\nTeam A: ${scoreA}\nTeam B: ${scoreB}`
);
collector.stop();
}
});
});
}
function dontWorryBeHappy(message) {
message.channel.send(
new Discord.MessageEmbed()
.setTitle(`Don't Worry Be Happy!`)
.setImage("https://media.giphy.com/media/7OKC8ZpTT0PVm/giphy.gif")
.setURL("https://youtu.be/d-diB65scQU")
.setColor("#ffffff")
);
}
function showServerNumber(message) {
message.channel.send(client.guilds.cache.size);
}
function showLeaderboard(interaction) { function showLeaderboard(interaction) {
let messageContent = ""; let messageContent = "";
userScore userScore

38
migrateScores.js

@ -1,38 +0,0 @@
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));

0
mongooseModels/mongooseGeneratedRoundModel.js → models/generateRound.js

0
mongooseModels/mongooseUserScoreModel.js → models/userScore.js

Loading…
Cancel
Save