From 13ebaa54bc66b297c365de03880ed418897b1575 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 23 Mar 2022 16:00:05 -0500 Subject: [PATCH 01/22] Use a button instead of reaction for overriding answers --- src/commands/train.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/commands/train.ts b/src/commands/train.ts index c95dc67..b9c5145 100644 --- a/src/commands/train.ts +++ b/src/commands/train.ts @@ -145,25 +145,31 @@ export async function execute(interaction) { .setDescription('It seems your answer was incorrect. Please react with <:override:955265585086857236> to override your answer if you think you got it right.') .setColor('#ffffff') .setTimestamp(); + const overrideButton = new MessageActionRow() + .addComponents( + new MessageButton() + .setCustomId('override') + .setEmoji('<:override:955265585086857236>') + .setStyle('SECONDARY'), + ); answerMsg.channel.send({ embeds: [overrideEmbed], + components: [overrideButton], }) .then(overrideMsg => { - overrideMsg.react('<:override:955265585086857236>'); - const filter = (reaction, user) => { + const overrideFilter = i => { return ( - ['override'].includes(reaction.emoji.name) && - user.id === answerMsg.author.id + ['override'].includes(i.customId) && + i.user.id === answerMsg.author.id ); }; overrideMsg - .awaitReactions({ - filter: filter, - max: 1, + .awaitMessageComponent({ + filter: overrideFilter, }) - .then(() => { + .then(i => { updateScore(true, score, authorId).then((msgToReply) => - answerMsg.reply(msgToReply), + i.reply(msgToReply), ); }).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' })); }).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' })); From 00d9f67248d17800fde2d455eeb5a19da572a4e2 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 23 Mar 2022 16:00:38 -0500 Subject: [PATCH 02/22] v4.2.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a6e3bd..1069356 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "typescript": "^4.6.2" }, "name": "awesomescibo", - "version": "4.1.1", + "version": "4.2.0", "scripts": { "start": "node index.js" }, From 848afcf5d8690dd3a83f39434af5659be3418c11 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 23 Mar 2022 16:30:32 -0500 Subject: [PATCH 03/22] Remove override button after usage --- src/commands/train.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/train.ts b/src/commands/train.ts index b9c5145..ff1227b 100644 --- a/src/commands/train.ts +++ b/src/commands/train.ts @@ -168,9 +168,10 @@ export async function execute(interaction) { filter: overrideFilter, }) .then(i => { - updateScore(true, score, authorId).then((msgToReply) => - i.reply(msgToReply), - ); + updateScore(true, score, authorId).then(async msgToReply => { + await i.reply(msgToReply); + overrideMsg.edit({ components: [] }); + }); }).catch(err => log({ logger: 'train', content: `Failed to override score: ${err}`, level: 'error' })); }).catch(err => log({ logger: 'train', content: `Failed to send override message: ${err}`, level: 'error' })); } From 2323b96dc8d68fd516a5be390f671833f62b85fc Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 23 Mar 2022 16:30:41 -0500 Subject: [PATCH 04/22] v4.2.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1069356..92ec7cd 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "typescript": "^4.6.2" }, "name": "awesomescibo", - "version": "4.2.0", + "version": "4.2.1", "scripts": { "start": "node index.js" }, From da339b4ec2dc6da04c5889f31441156978a4bef7 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan <67982792+ADawesomeguy@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:19:48 -0500 Subject: [PATCH 05/22] Change warn to error for arrow spacing --- .eslintrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.json b/.eslintrc.json index b46b74b..4fc98d9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -12,7 +12,7 @@ "es6": true }, "rules": { - "arrow-spacing": ["warn", { "before": true, "after": true }], + "arrow-spacing": ["error", { "before": true, "after": true }], "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], "comma-dangle": ["error", "always-multiline"], "comma-spacing": "error", From a6590567fd3412310a3811c32eb641859f03f6fc Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 09:27:38 -0500 Subject: [PATCH 06/22] Update scripts for TS in package.json --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 92ec7cd..e1a4ce7 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "name": "awesomescibo", "version": "4.2.1", "scripts": { - "start": "node index.js" + "build": "yarn tsc" }, "keywords": [ "discord", @@ -27,7 +27,8 @@ "science bowl", "discord.js" ], - "author": "Abheek Dhawan&Tejas Chugh", + "author": "Abheek Dhawan", "license": "MIT", "description": "A simple Discord bot that automatically generates Science Bowl rounds using the ScibowlDB API!" } + From e7b5268140ef64762856476706c6c622057b433f Mon Sep 17 00:00:00 2001 From: Abheek Dhawan <67982792+ADawesomeguy@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:46:38 -0500 Subject: [PATCH 07/22] Rewrite README.md with updates --- README.md | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 7415a08..4d74514 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ + +![out](https://user-images.githubusercontent.com/67982792/160637166-b8c3a390-e4f9-46d1-8738-dcb2d8b9baa7.png) +

AwesomeSciBo

+

@@ -12,25 +16,23 @@

A simple Discord bot that automatically generates Science Bowl rounds using the ScibowlDB API!

## Deployment -Deploying this bot to your Discord server is relatively simple: you can add it to your own server by using [this link](http://scibot.adawesome.tech/). +Deploying this bot to your Discord server is relatively simple: you can add it to your own server by using [this link](https://adat.link/awesomescibo). ## Contributing -Please see [the wiki](https://github.com/ADawesomeguy/AwesomeSciBo/wiki/contributing) contributing page. +Please see [CONTRIBUTING.md](). ## Installation -Please see [the wiki](https://github.com/ADawesomeguy/AwesomeSciBo/wiki/installation) install page. - -## Usage -This bot uses slash commands now :). You can just click on the bot icon after typing `/` to see a list of commands. +There are basically two ways to install it: -## Notes -### Creating a Discord Application/Bot -To create your own application and bot using the [Discord Developer Portal](https://discord.com/developers), go to the previous link and sign in. Then create a new application, and click bots on the left. Configure it to your liking, and then copy the token. +### Method 1 (Node): +After cloning the repository, dependencies can be installed with `yarn` or `npm i`. The bot can then be compile to JavaScript with `yarn tsc` or `npx tsc`, and will be deployed in the `built/` directory. Finally, the bot can be run by entering said directory and running `./index.js` or `node index.js`. - ![](images/discord-developer.png) +### Method 2 (Docker): +This bot has a Dockerfile within the repository which can be built using `docker build . -t [tag]`. Alternatively and preferably, the image can be taken from [DockerHub](https://hub.docker.com/r/adawesomeguy/awesomescibo). -That's the most important part of your bot *and don't share it with anyone*. +## Usage +This bot uses slash commands now :). You can just click on the bot icon after typing `/` to see a list of commands. ## Credit The bot was made by [@ADawesomeguy](https://github.com/ADawesomeguy). However, the API was made by [@CQCumbers](https://github.com/CQCumbers). Go give [his API](https://github.com/CQCumbers/ScibowlDB) a star, he totally deserves it! From 872eb63169033d1feb465714421ba6245180a7a4 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan <67982792+ADawesomeguy@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:55:15 -0500 Subject: [PATCH 08/22] Remove unused image --- images/discord-developer.png | Bin 7740 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 images/discord-developer.png diff --git a/images/discord-developer.png b/images/discord-developer.png deleted file mode 100644 index 6d18a4c441ce375a1d1ded14646798ed162eb059..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7740 zcmcI}Wl$VZu2M8=qaCdhLZozeN7I%kb_j2pK zAMe%ub8o$RKjuuIIdx{btNZ)9`%JjX7gz5)Oe`LmpehWtDpq&KrZ z-(EY*>9_#^*5CiUkP?}(NCANSL|*Enx>x!!#M2MgG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uR^w~#T0L}9(iL% z90&^pmEt;@!boJ!C`q3)W%&JnJSvT8K_T#GF27d7A&|6_g#^Fl?H*6(=+Sw|?wCgd zQg68F5_-+w=-9(%odBR!dU`sbpy5a|g5)Df?L%Ms{5u$sm;NGE@yYnxe*g?GX>I@j From 2bac614d94b80eeaf7dd0a6cb82091080ad6b0fe Mon Sep 17 00:00:00 2001 From: Abheek Dhawan <67982792+ADawesomeguy@users.noreply.github.com> Date: Tue, 29 Mar 2022 12:30:47 -0500 Subject: [PATCH 09/22] Add a Code of Conduct --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..e9bb389 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +abheekd@protonmail.com. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. From 9789d477a91e92565669dc1a869c3d6ec0dc5d3e Mon Sep 17 00:00:00 2001 From: Abheek Dhawan <67982792+ADawesomeguy@users.noreply.github.com> Date: Tue, 29 Mar 2022 12:42:50 -0500 Subject: [PATCH 10/22] Add contributing guidelines --- CONTRIBUTING.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..9a197fa --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,25 @@ +# Contributing + +## Cloning for Contribution +To set up the development environment to make changes to the code, clone the repo, install dependencies, and run it directly with `node` as Docker doesn't expose as much. + +## Making Changes +To edit the code please keep a few things in mind: +1. Be able to explain changes you make; they should be legible and understandable. +2. Please try to abide by ESLint's rules, setting up ESLint is quite easy to do and not too difficult to follow. + +## Testing Your Code +For testing, make sure to set up the prerequisites: +1. MongoDB: have a MongoDB server set up. +2. Environment Variables: take a look at the `docker-compose.yml` for examples. + +Once that's done, you can run `yarn tsc` or `npx tsc` to build to JavaScript in the `built` directory. Here you'll find `deploy-commands.js` which you need to deploy the slash commands, and `index.js` which you can run to start the bot. + +## Submitting Your Contribution +Creating a PR is easy enough and there are plenty of tutorials to do so. When contributing, please make sure to highlight and explain your change, with any import information additionally included. + +--- + +# Thank you for any contributions! + +--- From b73a46183c7aea260538888098b5a7aa38b18ce6 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 12:44:00 -0500 Subject: [PATCH 11/22] Move guidelines to .github subdirectory --- CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md | 0 CONTRIBUTING.md => .github/CONTRIBUTING.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename CODE_OF_CONDUCT.md => .github/CODE_OF_CONDUCT.md (100%) rename CONTRIBUTING.md => .github/CONTRIBUTING.md (100%) diff --git a/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md similarity index 100% rename from CODE_OF_CONDUCT.md rename to .github/CODE_OF_CONDUCT.md diff --git a/CONTRIBUTING.md b/.github/CONTRIBUTING.md similarity index 100% rename from CONTRIBUTING.md rename to .github/CONTRIBUTING.md From f732da7de6d38db750a27205cb4adf73475802d1 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 12:46:11 -0500 Subject: [PATCH 12/22] Update README with link to contributing guidelines --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d74514..63f3de4 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -![out](https://user-images.githubusercontent.com/67982792/160637166-b8c3a390-e4f9-46d1-8738-dcb2d8b9baa7.png) +![logo](https://user-images.githubusercontent.com/67982792/160637166-b8c3a390-e4f9-46d1-8738-dcb2d8b9baa7.png)

AwesomeSciBo

@@ -19,7 +19,7 @@ Deploying this bot to your Discord server is relatively simple: you can add it to your own server by using [this link](https://adat.link/awesomescibo). ## Contributing -Please see [CONTRIBUTING.md](). +Please see [CONTRIBUTING.md](https://github.com/ADawesomeguy/AwesomeSciBo/blob/master/.github/CONTRIBUTING.md). ## Installation From 83e9b4d07faa295a9305ddccc3bf390ff4f8757a Mon Sep 17 00:00:00 2001 From: Abheek Dhawan <67982792+ADawesomeguy@users.noreply.github.com> Date: Tue, 29 Mar 2022 12:51:42 -0500 Subject: [PATCH 13/22] Clean up CodeQL analysis --- .github/workflows/codeql-analysis.yml | 66 --------------------------- .github/workflows/codeql.yml | 25 ++++++++++ 2 files changed, 25 insertions(+), 66 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index 86e717d..0000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,66 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "codeql" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '43 14 * * 0' - -jobs: - analyze: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'javascript' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v1 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v1 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..c4e353b --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,25 @@ +name: "codeql" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: '43 14 * * 0' + +jobs: + analyze: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v1 + with: + languages: 'javascript' + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v1 From b52e09a3eb7a695f394aca5dd23f39989cce7094 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:03:09 -0500 Subject: [PATCH 14/22] Use pure JS for deploying the commands --- src/deploy-commands.js | 20 +++++++++++++++++++ ...loy-commands.ts => deploy-commands.ts.bak} | 0 tsconfig.json | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 src/deploy-commands.js rename src/{deploy-commands.ts => deploy-commands.ts.bak} (100%) diff --git a/src/deploy-commands.js b/src/deploy-commands.js new file mode 100644 index 0000000..0b7b816 --- /dev/null +++ b/src/deploy-commands.js @@ -0,0 +1,20 @@ +#!/usr/bin/env node + +const fs = require('node:fs'); +const { REST } = require('@discordjs/rest'); +const { Routes } = require('discord-api-types/v9'); +const { clientId, token } = require('./helpers/env'); + +const commands = []; +const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); + +for (const file of commandFiles) { + const command = require(`./commands/${file}`); + commands.push(command.data.toJSON()); +} + +const rest = new REST({ version: '9' }).setToken(token); + +rest.put(Routes.applicationCommands(clientId), { body: commands }) + .then(() => console.log('Successfully registered application commands.')) + .catch(console.error); diff --git a/src/deploy-commands.ts b/src/deploy-commands.ts.bak similarity index 100% rename from src/deploy-commands.ts rename to src/deploy-commands.ts.bak diff --git a/tsconfig.json b/tsconfig.json index cf9211b..63f9120 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -37,7 +37,7 @@ // "noResolve": true, /* Disallow `import`s, `require`s or ``s from expanding the number of files TypeScript should add to a project. */ /* JavaScript Support */ - // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ + "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */ // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */ From 1ea5c016b4c6fa321f32eefe752637c0876298ca Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:33:00 -0500 Subject: [PATCH 15/22] Add feature for checking scores --- src/commands/score.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/commands/score.ts diff --git a/src/commands/score.ts b/src/commands/score.ts new file mode 100644 index 0000000..c8f3db1 --- /dev/null +++ b/src/commands/score.ts @@ -0,0 +1,40 @@ +import { SlashCommandBuilder } from '@discordjs/builders'; +import { MessageEmbed } from 'discord.js'; + +import log from '../helpers/log'; +import userScore from '../models/userScore'; + +export const data = new SlashCommandBuilder() + .setName('score') + .setDescription('Returns the score of the current user or another') + .addUserOption(option => { + option + .setName('user') + .setDescription('The user to find the score for') + .setRequired(false); + + return option; + }); + +export async function execute(interaction) { + const scoreEmbed = new MessageEmbed() + .setColor('#ffffff'); + + const user = interaction.options.getUser('user') || interaction.user; + userScore.findOne({ authorID: user.id }, async (err, score) => { + if (err) { + log({ logger: 'db', content: `Unable to obtain user: ${err}`, level: 'info' }); + } + + if (!score) { + await interaction.reply({ content: 'Unfortunately, that user does not seem to have used AwesomeSciBo yet.', ephemeral: true }); + return; + } + + scoreEmbed + .setAuthor({ name: user.tag, iconURL: user.displayAvatarURL(true) }) + .setDescription(`Score: \`${score.score}\``); + + await interaction.reply({ embeds: [scoreEmbed] }); + }); +} From 5fe85f3e9af4f5ba46293293ff45b2681a4a2b43 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:33:14 -0500 Subject: [PATCH 16/22] v4.3.0 --- package.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package.json b/package.json index e1a4ce7..a086dee 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "typescript": "^4.6.2" }, "name": "awesomescibo", - "version": "4.2.1", + "version": "4.3.0", "scripts": { "build": "yarn tsc" }, @@ -31,4 +31,3 @@ "license": "MIT", "description": "A simple Discord bot that automatically generates Science Bowl rounds using the ScibowlDB API!" } - From c808364444e275dd91ba8126752c9a594eb162ed Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:39:07 -0500 Subject: [PATCH 17/22] Improve logging for user score creation --- src/helpers/db.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/helpers/db.ts b/src/helpers/db.ts index afd7952..fac2f83 100644 --- a/src/helpers/db.ts +++ b/src/helpers/db.ts @@ -14,11 +14,14 @@ export async function updateScore(isCorrect, score, authorId) { authorID: authorId, score: score, }); - newUserScore.save((err) => - err - ? console.log('Error creating new user for scoring') - : console.log('Sucessfully created user to score.'), - ); + newUserScore.save(err => { + if (err) { + log({ logger: 'db', content: `Error creating new user ${authorId} for scoring`, level: 'error' }); + } + else { + log({ logger: 'db', content: `Successfully created user ${authorId} for scoring`, level: 'debug' }); + } + }); } else { // TODO: Error handling @@ -41,4 +44,4 @@ export async function connect(mongoUri) { }) .then(() => log({ logger: 'db', content: `Connected to the database at ${mongoUri}!`, level: 'info' })) .catch(err => log({ logger: 'db', content: `Failed to connect to the database at ${mongoUri}: ${err}`, level: 'fatal' })); -} \ No newline at end of file +} From 795b73975784d1036a42992254c2d52defa96616 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Tue, 29 Mar 2022 22:39:12 -0500 Subject: [PATCH 18/22] v4.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a086dee..55c3846 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "typescript": "^4.6.2" }, "name": "awesomescibo", - "version": "4.3.0", + "version": "4.3.1", "scripts": { "build": "yarn tsc" }, From 575ceda11215aba122f3450cd58b11f78371d30c Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 30 Mar 2022 08:16:44 -0500 Subject: [PATCH 19/22] Remove backup TS file for deploying commands --- src/deploy-commands.ts.bak | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100755 src/deploy-commands.ts.bak diff --git a/src/deploy-commands.ts.bak b/src/deploy-commands.ts.bak deleted file mode 100755 index 359ac5c..0000000 --- a/src/deploy-commands.ts.bak +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env node - -import fs from 'node:fs'; -import { REST } from '@discordjs/rest'; -import { Routes } from 'discord-api-types/v9'; -import { clientId, token } from './helpers/env'; - -const commands : any[] = []; -const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); - -for (const file of commandFiles) { - import(`./commands/${file}`) - .then(command => { - commands.push(command.data.toJSON()); - }); -} - -const rest = new REST({ version: '9' }).setToken(token); - -rest.put(Routes.applicationCommands(clientId), { body: commands }) - .then(() => console.log('Successfully registered application commands.')) - .catch(console.error); From 756b6965ab67402fbcb471895a18bed0b9ca58f0 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 30 Mar 2022 08:18:10 -0500 Subject: [PATCH 20/22] Ignore the deploy commands JS file from ESLint --- .eslintrc.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.eslintrc.json b/.eslintrc.json index 4fc98d9..a47a5e5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,6 +11,7 @@ "node": true, "es6": true }, + "ignorePatterns": ["src/deploy-commands.js"], "rules": { "arrow-spacing": ["error", { "before": true, "after": true }], "brace-style": ["error", "stroustrup", { "allowSingleLine": true }], From c7e0e14b69cbf5747f79d6830f13f026f19cfc19 Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 30 Mar 2022 08:26:37 -0500 Subject: [PATCH 21/22] v4.3.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 55c3846..dd6560f 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "typescript": "^4.6.2" }, "name": "awesomescibo", - "version": "4.3.1", + "version": "4.3.2", "scripts": { "build": "yarn tsc" }, From 3be7404c90905556ee5eb1db67079749db09752e Mon Sep 17 00:00:00 2001 From: Abheek Dhawan Date: Wed, 30 Mar 2022 15:07:12 +0000 Subject: [PATCH 22/22] Attempt to fix non-null assertions --- src/helpers/env.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/helpers/env.ts b/src/helpers/env.ts index 22b1b3d..c339592 100644 --- a/src/helpers/env.ts +++ b/src/helpers/env.ts @@ -1,6 +1,6 @@ import 'dotenv/config'; -export const clientId : string = process.env.CLIENT_ID!; -export const testingGuild : string = process.env.TESTING_GUILD!; -export const token : string = process.env.TOKEN!; -export const mongoUri : string = process.env.MONGO_URI!; \ No newline at end of file +export const clientId : string = process.env.CLIENT_ID || ''; +export const testingGuild : string = process.env.TESTING_GUILD || ''; +export const token : string = process.env.TOKEN || ''; +export const mongoUri : string = process.env.MONGO_URI || 'mongodb://mongo:27017/awesome'; \ No newline at end of file