Browse Source

Initial commit

Added all the files, working bot, some commented out code, glhf
pull/1/head
Abheek Dhawan 4 years ago
commit
606f7f9a3a
  1. 6
      .gitignore
  2. 112
      package-lock.json
  3. 18
      package.json
  4. 231
      roundbot.mjs

6
.gitignore

@ -0,0 +1,6 @@
index.html
numhits.txt
node_modules
round.html
round.md
round.pdf

112
package-lock.json

@ -0,0 +1,112 @@
{
"name": "roundbot2",
"version": "1.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@discordjs/collection": {
"version": "0.1.6",
"resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz",
"integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ=="
},
"@discordjs/form-data": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@discordjs/form-data/-/form-data-3.0.1.tgz",
"integrity": "sha512-ZfFsbgEXW71Rw/6EtBdrP5VxBJy4dthyC0tpQKGKmYFImlmmrykO14Za+BiIVduwjte0jXEBlhSKf0MWbFp9Eg==",
"requires": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"abort-controller": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
"requires": {
"event-target-shim": "^5.0.0"
}
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
},
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"requires": {
"delayed-stream": "~1.0.0"
}
},
"delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
},
"discord.js": {
"version": "12.5.1",
"resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz",
"integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==",
"requires": {
"@discordjs/collection": "^0.1.6",
"@discordjs/form-data": "^3.0.1",
"abort-controller": "^3.0.0",
"node-fetch": "^2.6.1",
"prism-media": "^1.2.2",
"setimmediate": "^1.0.5",
"tweetnacl": "^1.0.3",
"ws": "^7.3.1"
}
},
"event-target-shim": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ=="
},
"fs": {
"version": "0.0.1-security",
"resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
"integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
},
"mime-db": {
"version": "1.46.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.46.0.tgz",
"integrity": "sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ=="
},
"mime-types": {
"version": "2.1.29",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz",
"integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==",
"requires": {
"mime-db": "1.46.0"
}
},
"node-fetch": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
"integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
},
"prism-media": {
"version": "1.2.7",
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.7.tgz",
"integrity": "sha512-thS1z3L6BDmf724sqLC73bHGjSYArFTYHa7cqInyS3EdDNTHKgDCXy7l+IhRvlnX7aFNiUb8jJcC+R8ezxwgMA=="
},
"setimmediate": {
"version": "1.0.5",
"resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz",
"integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU="
},
"tweetnacl": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz",
"integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw=="
},
"ws": {
"version": "7.4.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.3.tgz",
"integrity": "sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA=="
}
}
}

18
package.json

@ -0,0 +1,18 @@
{
"dependencies": {
"discord.js": "^12.5.1",
"fs": "^0.0.1-security",
"node-fetch": "^2.6.1"
},
"name": "roundbot2",
"version": "1.0.0",
"main": "index.js",
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": ""
}

231
roundbot.mjs

@ -0,0 +1,231 @@
import * as Discord from 'discord.js';
import { execSync } from 'child_process';
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
import fetch from 'node-fetch';
import * as fs from 'fs';
var hits = 0;
fs.readFile('numhits.txt', 'utf8', function(err, data){
hits = data;
if (err) {
console.log(error);
}
});
client.once('ready', () => {
console.log('Ready!');
client.user.setActivity("for \"do be helping\"", { type: "WATCHING" });
});
client.on('guildCreate', guild => {
guild.channels.cache.find(channel => channel.name === 'general').send("what is up peeps I am roundbutt");
});
client.on('message', async message => {
if (message.content.toLowerCase() === "do be hits") {
message.channel.send(hits);
fs.writeFile('numhits.txt', hits, (error) => { if (error) { console.log(error); } });
}
if (message.content.toLowerCase() === ("do be helping")) {
message.channel.send(new Discord.MessageEmbed().setTitle("Help").setDescription("`do be helping`: display this help message\n`do be roundgen html`: send a round to the channel\n`do be roundgen html dm`: dm a round to you\n`do be roundgen pdf`: send a pdf round to the channel\n`do be roundgen pdf 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 hits`: send the number of round requests"));
}
if (message.content.toLowerCase() === ("do be roundgen html dm")) {
fs.writeFile('round.html', "<h1>Here's your round!</h1>", (error) => { if (error) { console.log(error); } });
var person = client.users.cache.get(message.author.id);
var i;
let generatingMsg = await message.channel.send("Generating...");
for (i = 1; i < 26; i++) {
var tossup_question;
var question_category;
var tossup_format;
var tossup_answer;
var bonus_question;
var bonus_format;
var bonus_answer;
var htmlContent = "";
await fetch('https://scibowldb.com/api/questions/random')
.then(response => response.json())
.then(data => {
tossup_question = data.question.tossup_question;
tossup_answer = data.question.tossup_answer;
question_category = data.question.category;
tossup_format = data.question.tossup_format;
bonus_question = data.question.bonus_question;
bonus_answer = data.question.bonus_answer;
bonus_format = data.question.bonus_format;
htmlContent = `<br><br>${i}. Tossup\n<br><br>` + `<strong>${question_category}</strong>` + " " + `<em>${tossup_format}</em>` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br><br>";
htmlContent += "<br><br>Bonus\n<br><br>" + `<strong>${question_category}</strong>` + " " + `<em>${bonus_format}</em>` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br>";
htmlContent = htmlContent.replace(/\n/g, "<br>");
fs.appendFile('round.html', htmlContent, (error) => { if (error) { console.log(error); } });
});
}
generatingMsg.delete( {timeout: 1000} );
setTimeout(function () { person.send(new Discord.MessageEmbed().setTitle("Here's your round!").attachFiles("round.html")); }, 1000);
hits++;
}
if (message.content.toLowerCase() === ("do be roundgen html")) {
fs.writeFile('round.html', "<h1>Here's your round!</h1>", (error) => { if (error) { console.log(error); } });
var i;
let generatingMsg = await message.channel.send("Generating...");
for (i = 1; i < 26; i++) {
var tossup_question;
var question_category;
var tossup_format;
var tossup_answer;
var bonus_question;
var bonus_format;
var bonus_answer;
var htmlContent = "";
await fetch('https://scibowldb.com/api/questions/random')
.then(response => response.json())
.then(data => {
tossup_question = data.question.tossup_question;
tossup_answer = data.question.tossup_answer;
question_category = data.question.category;
tossup_format = data.question.tossup_format;
bonus_question = data.question.bonus_question;
bonus_answer = data.question.bonus_answer;
bonus_format = data.question.bonus_format;
htmlContent = `<br><br>${i}. Tossup\n<br><br>` + `<strong>${question_category}</strong>` + " " + `<em>${tossup_format}</em>` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br><br>";
htmlContent += "<br><br>Bonus\n<br><br>" + `<strong>${question_category}</strong>` + " " + `<em>${bonus_format}</em>` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br>";
htmlContent = htmlContent.replace(/\n/g, "<br>");
fs.appendFile('round.html', htmlContent, (error) => { if (error) { console.log(error); } });
});
}
generatingMsg.delete( {timeout: 1000} );
setTimeout(function () { message.channel.send(new Discord.MessageEmbed().setTitle("Here's your round!").attachFiles("round.html")); }, 1000);
hits++;
}
if (message.content.toLowerCase() === ("do be roundgen pdf dm")) {
fs.writeFile('index.html', "<h1>Here's your round!</h1>", (error) => { if (error) { console.log(error); } });
var person = client.users.cache.get(message.author.id);
var i;
let generatingMsg = await message.channel.send("Generating...");
for (i = 1; i < 26; i++) {
var tossup_question;
var question_category;
var tossup_format;
var tossup_answer;
var bonus_question;
var bonus_format;
var bonus_answer;
var htmlContent = "";
await fetch('https://scibowldb.com/api/questions/random')
.then(response => response.json())
.then(data => {
tossup_question = data.question.tossup_question;
tossup_answer = data.question.tossup_answer;
question_category = data.question.category;
tossup_format = data.question.tossup_format;
bonus_question = data.question.bonus_question;
bonus_answer = data.question.bonus_answer;
bonus_format = data.question.bonus_format;
htmlContent = `<br><br>${i}. Tossup\n<br><br>` + `<strong>${question_category}</strong>` + " " + `<em>${tossup_format}</em>` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br><br>";
htmlContent += "<br><br>Bonus\n<br><br>" + `<strong>${question_category}</strong>` + " " + `<em>${bonus_format}</em>` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br>";
htmlContent = htmlContent.replace(/\n/g, "<br>");
fs.appendFile('index.html', htmlContent, (error) => { if (error) { console.log(error); } });
});
}
generatingMsg.delete( {timeout: 1000} );
var output = execSync("curl --request POST --url http://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf", { encoding: 'utf-8' });
//console.log(output);
setTimeout(function () { person.send(new Discord.MessageEmbed().setTitle("Here's your round!").attachFiles("round.pdf")); }, 1000);
hits++;
}
if (message.content.toLowerCase() === ("do be roundgen pdf")) {
fs.writeFile('index.html', "<h1>Here's your round!</h1>", (error) => { if (error) { console.log(error); } });
var i;
let generatingMsg = await message.channel.send("Generating...");
for (i = 1; i < 26; i++) {
var tossup_question;
var question_category;
var tossup_format;
var tossup_answer;
var bonus_question;
var bonus_format;
var bonus_answer;
var htmlContent = "";
await fetch('https://scibowldb.com/api/questions/random')
.then(response => response.json())
.then(data => {
tossup_question = data.question.tossup_question;
tossup_answer = data.question.tossup_answer;
question_category = data.question.category;
tossup_format = data.question.tossup_format;
bonus_question = data.question.bonus_question;
bonus_answer = data.question.bonus_answer;
bonus_format = data.question.bonus_format;
htmlContent = `<br><br>${i}. Tossup\n<br><br>` + `<strong>${question_category}</strong>` + " " + `<em>${tossup_format}</em>` + " " + tossup_question + "<br><br>" + "<strong>ANSWER:</strong> " + tossup_answer + "<br><br>";
htmlContent += "<br><br>Bonus\n<br><br>" + `<strong>${question_category}</strong>` + " " + `<em>${bonus_format}</em>` + " " + bonus_question + "<br><br>" + "<strong>ANSWER:</strong> " + bonus_answer + "<br><br>";
htmlContent = htmlContent.replace(/\n/g, "<br>");
fs.appendFile('index.html', htmlContent, (error) => { if (error) { console.log(error); } });
});
}
generatingMsg.delete( {timeout: 1000} );
var output = execSync("curl --request POST --url http://localhost:3136/convert/html --header 'Content-Type: multipart/form-data' --form files=@index.html -o round.pdf", { encoding: 'utf-8' });
//console.log(output);
message.channel.send(new Discord.MessageEmbed().setTitle("Here's your round!").attachFiles("round.pdf"));
hits++;
}
if (message.content.toLowerCase() === "do be scoring") {
var scoreA = 0;
var scoreB = 0;
let scoreboard = 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() === "do be scoring a 4") {
m.delete( { timeout: 1000 } );
scoreA += 4;
scoreboard.channel.send(`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`);
} else if (m.content.toLowerCase() === "do be scoring a 10") {
m.delete( { timeout: 1000 } );
scoreA += 10;
scoreboard.channel.send(`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`);
} else if (m.content.toLowerCase() === "do be scoring b 4") {
m.delete( { timeout: 1000 } );
scoreB += 4;
scoreboard.channel.send(`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`);
} else if (m.content.toLowerCase() === "do be scoring b 10") {
m.delete( { timeout: 1000 } );
scoreB += 10;
scoreboard.channel.send(`Here's the score:\nTeam A: ${scoreA}\nTeam B: ${scoreB}`);
} else if (m.content === "do be scoring stop") {
m.delete( { timeout: 1000 } );
scoreboard.delete( { timeout: 1000} );
m.channel.send(`**FINAL SCORE:**\nTeam A: ${scoreA}\nTeam B: ${scoreB}`);
collector.stop();
}
});
})
}
if (message.content.toLowerCase() === "do be happy") {
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"));
}
if (message.content.toLowerCase() === "do be servers") {
message.channel.send(client.guilds.cache.size);
}
if (message.content.toLowerCase() === "do be pog") {
message.channel.send(new Discord.MessageEmbed().setTitle("POG POG POG").setURL("https://media.giphy.com/media/c5skRQb3BXp8RwKGKW/giphy.gif").setImage("https://media.giphy.com/media/c5skRQb3BXp8RwKGKW/giphy.gif"));
}
/* if (message.content.toLowerCase() === "do be user channel create") {
const userChannel = await message.guild.channels.create('Users: ' + message.guild.memberCount, {
reason: 'Create channel to track number of users',
type: 'voice'
})
//.then(console.log)
.catch(console.error);
console.log(userChannel.id);
setInterval(async () => { await message.guild.channels.cache.get(userChannel.id).setName('Members: ' + message.guild.memberCount).catch(console.error); }, 10000);
}*/
});
client.login("ODEyMzU2OTI3NzczOTk5MTI2.YC_kWA.QWN3-uWpqF_4xQD_uWr09i2Rdos");
Loading…
Cancel
Save