From 3dae16d2090515e8316897c02df34cc9b6483270 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Fri, 26 Feb 2021 19:36:25 -0600 Subject: [PATCH] Add scoring functionality --- bot/awesomescibo.mjs | 22 +++++- bot/package-lock.json | 153 +++++++++++++++++++++++++++++++++++++++++- bot/package.json | 2 +- bot/userScore/id | 1 + 4 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 bot/userScore/id diff --git a/bot/awesomescibo.mjs b/bot/awesomescibo.mjs index c2e81f8..5ea93ef 100755 --- a/bot/awesomescibo.mjs +++ b/bot/awesomescibo.mjs @@ -255,6 +255,17 @@ client.on('message', async message => { }) .then(message => { message = message.first(); + var score = 0; + if (fs.existsSync(`userScore/${message.author.id}`)) { + fs.readFile(`userScore/${message.author.id}`, 'utf8', function (err, data) { + score = Number(data); + if (err) { + console.log(err); + } + }); + } else { + fs.writeFile(`userScore/${message.author.id}`, score.toString(), (error) => { if (error) { console.log(error); } }); + } var predicted = "unsure"; if (data.question.tossup_format === "Multiple Choice") { if (message.content.charAt(0).toLowerCase() === data.question.tossup_answer.charAt(0).toLowerCase()) { @@ -279,16 +290,20 @@ client.on('message', async message => { .then(reaction => { var reaction = reaction.first(); if (reaction.emoji.name === "❌") { - message.reply("nice try!"); + fs.writeFile(`userScore/${message.author.id}`, score.toString(), (error) => { if (error) { console.log(error); } }); + message.reply(`nice try! Your score is now ${score}`); } else { - message.reply("nice job!"); + score += 4; + fs.writeFile(`userScore/${message.author.id}`, score.toString(), (error) => { if (error) { console.log(error); } }); + message.reply(`nice job! Your score is now ${score}`); + fs.writeFile(`userScore/${message.author.id}`, score.toString(), (error) => { if (error) { console.log(error); } }); } }) .catch(collected => { //message.channel.send("\n**REACTION TIMEOUT**"); }) }) - .catch (collected => { + .catch ((collected, error) => { message.reply('\n**ANSWER TIMEOUT**'); }) }) @@ -297,3 +312,4 @@ client.on('message', async message => { }); client.login(process.argv[2]).catch(error => console.log(error)); + diff --git a/bot/package-lock.json b/bot/package-lock.json index fc09199..48cf7d5 100644 --- a/bot/package-lock.json +++ b/bot/package-lock.json @@ -1,8 +1,157 @@ { "name": "awscibo", - "version": "0.1.0", - "lockfileVersion": 1, + "version": "0.2.4", + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "awscibo", + "version": "0.2.4", + "license": "Apache 2.0", + "dependencies": { + "discord.js": "^12.5.1", + "fs": "^0.0.1-security", + "node-fetch": "^2.6.1" + }, + "bin": { + "awscibo": "awesomescibo.mjs" + } + }, + "node_modules/@discordjs/collection": { + "version": "0.1.6", + "resolved": "https://registry.npmjs.org/@discordjs/collection/-/collection-0.1.6.tgz", + "integrity": "sha512-utRNxnd9kSS2qhyivo9lMlt5qgAUasH2gb7BEOn6p0efFh24gjGomHzWKMAPn2hEReOPQZCJaRKoURwRotKucQ==" + }, + "node_modules/@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==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/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==", + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/discord.js": { + "version": "12.5.1", + "resolved": "https://registry.npmjs.org/discord.js/-/discord.js-12.5.1.tgz", + "integrity": "sha512-VwZkVaUAIOB9mKdca0I5MefPMTQJTNg0qdgi1huF3iwsFwJ0L5s/Y69AQe+iPmjuV6j9rtKoG0Ta0n9vgEIL6w==", + "dependencies": { + "@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" + }, + "engines": { + "node": ">=12.0.0" + } + }, + "node_modules/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==", + "engines": { + "node": ">=6" + } + }, + "node_modules/fs": { + "version": "0.0.1-security", + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz", + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ=" + }, + "node_modules/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==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/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==", + "dependencies": { + "mime-db": "1.46.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/prism-media": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/prism-media/-/prism-media-1.2.7.tgz", + "integrity": "sha512-thS1z3L6BDmf724sqLC73bHGjSYArFTYHa7cqInyS3EdDNTHKgDCXy7l+IhRvlnX7aFNiUb8jJcC+R8ezxwgMA==" + }, + "node_modules/setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, + "node_modules/ws": { + "version": "7.4.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.3.tgz", + "integrity": "sha512-hr6vCR76GsossIRsr8OLR9acVVm1jyfEWvhbNjtgPOrfvAlKzvyeg/P6r8RuDjRyrcQoPQT7K0DGEPc7Ae6jzA==", + "engines": { + "node": ">=8.3.0" + } + } + }, "dependencies": { "@discordjs/collection": { "version": "0.1.6", diff --git a/bot/package.json b/bot/package.json index 6678f60..16e50f5 100644 --- a/bot/package.json +++ b/bot/package.json @@ -5,7 +5,7 @@ "node-fetch": "^2.6.1" }, "name": "awscibo", - "version": "0.2.4", + "version": "0.3.4", "main": "awesomescibo.mjs", "bin": { "awscibo": "./awesomescibo.mjs" diff --git a/bot/userScore/id b/bot/userScore/id new file mode 100644 index 0000000..573541a --- /dev/null +++ b/bot/userScore/id @@ -0,0 +1 @@ +0