Browse Source

Adhere to TS and Markdown Style Guidelines (#46)

* Update package.json

* Adhere to Markdown and TS Style Guidelines

* Adhere to ESLint

* Some more edits to adhere to the ESLint standard

* style: modify slightly to adhere to ESLint spec

Co-authored-by: Piyush Acharya <acharyapiyush1@outlook.com>

Co-authored-by: Abheek <abheekd@protonmail.com>
pull/48/head
Piyush Acharya 2 years ago
committed by GitHub
parent
commit
b0763f7524
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 102
      .eslintrc.json
  2. 16
      .github/CONTRIBUTING.md
  3. 23
      README.md
  4. 1
      src/commands/help.ts
  5. 5
      src/commands/rounds.ts
  6. 5
      src/commands/score.ts
  7. 28
      src/commands/settings.ts
  8. 27
      src/commands/train.ts
  9. 6
      src/helpers/db.ts
  10. 17
      src/helpers/util/pagination.ts
  11. 41
      tsconfig.json

102
.eslintrc.json

@ -10,39 +10,106 @@
"node": true,
"es6": true
},
"ignorePatterns": ["src/deploy-commands.js"],
"ignorePatterns": [
"src/deploy-commands.js"
],
"rules": {
"arrow-spacing": ["error", { "before": true, "after": true }],
"brace-style": ["error", "stroustrup", { "allowSingleLine": true }],
"comma-dangle": ["error", "always-multiline"],
"arrow-spacing": [
"error",
{
"before": true,
"after": true
}
],
"brace-style": [
"error",
"stroustrup",
{
"allowSingleLine": true
}
],
"comma-dangle": [
"error",
"always-multiline"
],
"comma-spacing": "error",
"comma-style": "error",
"curly": ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"curly": [
"error",
"multi-line",
"consistent"
],
"dot-location": [
"error",
"property"
],
"handle-callback-err": "off",
"indent": ["error", "tab"],
"indent": [
"error",
"tab"
],
"keyword-spacing": "error",
"max-nested-callbacks": ["error", { "max": 4 }],
"max-statements-per-line": ["error", { "max": 2 }],
"max-nested-callbacks": [
"error",
{
"max": 4
}
],
"max-statements-per-line": [
"error",
{
"max": 2
}
],
"no-console": "off",
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-lonely-if": "error",
"no-multi-spaces": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
"no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }],
"no-trailing-spaces": ["error"],
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxEOF": 1,
"maxBOF": 0
}
],
"no-shadow": [
"error",
{
"allow": [
"err",
"resolve",
"reject"
]
}
],
"no-trailing-spaces": [
"error"
],
"no-var": "error",
"object-curly-spacing": ["error", "always"],
"object-curly-spacing": [
"error",
"always"
],
"prefer-const": "error",
"quotes": ["error", "single"],
"semi": ["error", "always"],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"space-before-blocks": "error",
"space-before-function-paren": ["error", {
"space-before-function-paren": [
"error",
{
"anonymous": "never",
"named": "never",
"asyncArrow": "always"
}],
}
],
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
@ -50,4 +117,3 @@
"yoda": "error"
}
}

16
.github/CONTRIBUTING.md

@ -1,22 +1,32 @@
# 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.
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.
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.
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.
---

23
README.md

@ -1,4 +1,3 @@
![logo](https://user-images.githubusercontent.com/67982792/160637166-b8c3a390-e4f9-46d1-8738-dcb2d8b9baa7.png)
<h1 align="center">AwesomeSciBo</h1>
@ -16,23 +15,35 @@
<p align="center">Open-source Discord bot that aims to aid up-and-coming Scibowlers with randomly generated (non-stock) rounds and training. It has many features, including subject-targeted training, a cross-server leaderboard, and a plethora of slash commands!</p>
## Deployment
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).
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](https://github.com/ADawesomeguy/AwesomeSciBo/blob/master/.github/CONTRIBUTING.md).
Please see [CONTRIBUTING.md](https://github.com/ADawesomeguy/AwesomeSciBo/blob/master/.github/CONTRIBUTING.md).
## Installation
There are basically two ways to install it:
### 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`.
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`.
### 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).
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).
## 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!
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!

1
src/commands/help.ts

@ -7,6 +7,7 @@ export const data = new SlashCommandBuilder()
export async function execute(interaction: CommandInteraction) {
await interaction.deferReply();
await interaction.deferReply();
const helpEmbed = new MessageEmbed()
.setDescription('AwesomeSciBo has migrated to using slash commands! You can take a look at the different commands by typing `/` and clicking on the AwesomeSciBo icon.')

5
src/commands/rounds.ts

@ -72,7 +72,10 @@ export async function execute(interaction : CommandInteraction) {
log({ logger: 'rounds', content: `Saving round to DB failed: ${err}`, level: 'error' });
return;
}
interaction.followUp({ content: `Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`, ephemeral: true });
interaction.followUp({
content: `Here's your round: https://api.adawesome.tech/round/${round._id.toString()}`,
ephemeral: true,
});
});
});
break;

5
src/commands/score.ts

@ -27,7 +27,10 @@ export async function execute(interaction : CommandInteraction) {
}
if (!score) {
await interaction.reply({ content: 'Unfortunately, that user does not seem to have used AwesomeSciBo yet.', ephemeral: true });
await interaction.reply({
content: 'Unfortunately, that user does not seem to have used AwesomeSciBo yet.',
ephemeral: true,
});
return;
}

28
src/commands/settings.ts

@ -70,7 +70,11 @@ export async function execute(interaction : CommandInteraction) {
const vals = dispChoice.values;
const config = await userConfig.findById(interaction.user.id);
if (!config) {
await interaction.editReply({ content: 'You don\'t have a configuration!', embeds: [], components: [] });
await interaction.editReply({
content: 'You don\'t have a configuration!',
embeds: [],
components: [],
});
}
else if (vals.length === 1 && vals.at(0) === 'subjects') {
await interaction.editReply({
@ -138,7 +142,10 @@ export async function execute(interaction : CommandInteraction) {
.then(async lvlChoice => {
const vals = lvlChoice.values;
const levels = new Array<string>();
await userConfig.findOneAndUpdate({ _id: interaction.user.id }, { gradeLevels: vals }, { upsert: true, new: true });
await userConfig.findOneAndUpdate({ _id: interaction.user.id }, { gradeLevels: vals }, {
upsert: true,
new: true,
});
await vals.forEach(v => {
switch (v) {
case 'MS':
@ -148,7 +155,11 @@ export async function execute(interaction : CommandInteraction) {
levels.push('High School');
}
});
await interaction.editReply({ content: `Level set to: ${levels.toString().split(',').join(', ')}`, embeds: [], components: [] });
await interaction.editReply({
content: `Level set to: ${levels.toString().split(',').join(', ')}`,
embeds: [],
components: [],
});
});
}));
break;
@ -219,12 +230,19 @@ export async function execute(interaction : CommandInteraction) {
(subjectMsg as Message).awaitMessageComponent({ filter: subjectFilter, componentType: 'SELECT_MENU' })
.then(async subjectChoice => {
const vals = subjectChoice.values;
await userConfig.findOneAndUpdate({ _id: interaction.user.id }, { subjects: vals }, { upsert: true, new: true });
await userConfig.findOneAndUpdate({ _id: interaction.user.id }, { subjects: vals }, {
upsert: true,
new: true,
});
const subjects = new Array<string>();
await vals.forEach(v => {
subjects.push(v.toLowerCase().split(' ').map(w => w[0].toUpperCase() + w.substring(1)).join(' '));
});
await interaction.editReply({ content: `Subjects set to: ${subjects.toString().split(',').join(', ')}`, components: [], embeds: [] });
await interaction.editReply({
content: `Subjects set to: ${subjects.toString().split(',').join(', ')}`,
components: [],
embeds: [],
});
});
}));
break;

27
src/commands/train.ts

@ -44,7 +44,10 @@ export async function execute(interaction : CommandInteraction) {
if (!obj) {
score = 0;
const firstTimeEmbed = new MessageEmbed()
.setAuthor({ name: interaction.client.user?.tag ? interaction.client.user?.tag : '', iconURL: interaction.client.user?.displayAvatarURL() })
.setAuthor({
name: interaction.client.user?.tag ? interaction.client.user?.tag : '',
iconURL: interaction.client.user?.displayAvatarURL(),
})
.setDescription('Hey! It seems like it\'s your first time using AwesomeSciBo. Here\'s some information regarding the bot if you need it (for issues, contributions, etc.):')
.addField('Creator', '<@745063586422063214> [@abheekd#3602]')
.addField('GitHub', '[Link](https://github.com/ADawesomeguy/AwesomeSciBo) (a star couldn\'t hurt...)')
@ -154,7 +157,10 @@ export async function execute(interaction : CommandInteraction) {
}
else {
const overrideEmbed = new MessageEmbed()
.setAuthor({ name: answerMsg?.author.tag ? answerMsg.author.tag : '', iconURL: answerMsg?.author.displayAvatarURL() })
.setAuthor({
name: answerMsg?.author.tag ? answerMsg.author.tag : '',
iconURL: answerMsg?.author.displayAvatarURL(),
})
.addField('Correct answer', `\`${tossupAnswer}\``)
.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')
@ -186,8 +192,16 @@ export async function execute(interaction : CommandInteraction) {
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' }));
}).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',
}));
}
interaction.editReply({ components: [sourceButton] });
}).catch(err => log({ logger: 'train', content: `${err}`, level: 'error' }));
@ -224,7 +238,10 @@ export async function execute(interaction : CommandInteraction) {
}
else {
const incorrectEmbed = new MessageEmbed()
.setAuthor({ name: interaction.user.tag, iconURL: interaction.user.displayAvatarURL() })
.setAuthor({
name: interaction.user.tag,
iconURL: interaction.user.displayAvatarURL(),
})
.addField('Correct answer', `\`${tossupAnswer}\``)
.setDescription(`It seems your answer ${mcChoice.customId.toUpperCase()} was incorrect.`)
.setColor('#ffffff')

6
src/helpers/db.ts

@ -42,6 +42,10 @@ export async function connect(mongoUri) {
useNewUrlParser: true,
})
.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' }));
.catch(err => log({
logger: 'db',
content: `Failed to connect to the database at ${mongoUri}: ${err}`,
level: 'fatal',
}));
}

17
src/helpers/util/pagination.ts

@ -19,7 +19,10 @@ export async function paginateMessage(message : Message, embeds : MessageEmbed[]
.then(async paginatorMessage => {
const filter = m => m.author.id === message.author.id;
const paginatorCollector = paginatorMessage.createMessageComponentCollector({ componentType: 'BUTTON', filter: filter });
const paginatorCollector = paginatorMessage.createMessageComponentCollector({
componentType: 'BUTTON',
filter: filter,
});
paginatorCollector.on('collect', async i => {
switch (i.customId) {
@ -52,12 +55,20 @@ export async function paginateInteraction(interaction : CommandInteraction, embe
.setStyle('SECONDARY')
);
await interaction.followUp({ content: `Page 1 of ${embeds.length}:`, embeds: [embeds[index]], components: [row], fetchReply: true })
await interaction.followUp({
content: `Page 1 of ${embeds.length}:`,
embeds: [embeds[index]],
components: [row],
fetchReply: true,
})
.then(async p => {
const paginatorMessage = p as Message;
const filter = i => i.user.id === interaction.user.id;
const paginatorCollector = paginatorMessage.createMessageComponentCollector({ componentType: 'BUTTON', filter: filter });
const paginatorCollector = paginatorMessage.createMessageComponentCollector({
componentType: 'BUTTON',
filter: filter,
});
paginatorCollector.on('collect', async i => {
switch (i.customId) {

41
tsconfig.json

@ -1,17 +1,17 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Projects */
"incremental": true, /* Enable incremental compilation */
"incremental": true,
/* Enable incremental compilation */
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
// "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2016",
/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
@ -22,11 +22,12 @@
// "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "commonjs", /* Specify what module code is generated. */
"module": "commonjs",
/* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "node",
/* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@ -35,19 +36,19 @@
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`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`. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "./built", /* Specify an output folder for all emitted files. */
"outDir": "./built",
/* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@ -65,17 +66,19 @@
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
"esModuleInterop": true,
/* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,
/* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
"strict": true,
/* Enable all strict type-checking options. */
"noImplicitAny": false,
/* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
@ -93,9 +96,9 @@
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
"skipLibCheck": true
/* Skip type checking all .d.ts files. */
}
}
Loading…
Cancel
Save