Giter Site home page Giter Site logo

tomassirio / listbot Goto Github PK

View Code? Open in Web Editor NEW
23.0 5.0 49.0 5.33 MB

ListBot is a Discord Bot which let's you create community lists on each channel.

Home Page: https://discord.io/siriobots

License: MIT License

JavaScript 90.46% Shell 9.22% Dockerfile 0.32%
hacktoberfest hacktoberfest2020 listbot discord-bot mongo docker hacktoberfest2021 hacktoberfest-accepted

listbot's Issues

Add a Multi Add command to the Bot

The Add command let's you add only one element to the list. Add a MultiAdd command that lets you add more than one on a single command

[FEATURE] Refactor for a clear, single-source of configuration for the bot.

Is your feature request related to a problem? Please describe.
This is more of a code refactoring request than a feature request. The use of process.env is sprinkled throughout the ListBot code base instead of utilizing the main config object (from src/config/index.js).

Describe the solution you'd like
It would be better if all configuration for the bot was accessed through the main config object instead of using process.env. This makes all possible settings/configuration for the bot "knowable" by reading through the config file settings (i.e. no need to search for usages of process.env in the code to see what can/should be set in the .env file or external environment variables).

This refactoring would need the following:

  1. Find all usages of process.env and, where possible, update them so that the setting value is using the corresponding property from the main config object.
  2. If it is not possible to update the use of process.env to come from the main config file, document the reason why and include a section explaining how the setting should be set in an environemnet variable and what the setting controls in the src/config/.env.example file.
  3. Ensure all settings/config are documented in the .env.example file

[BUG] Poll is broken

2020-10-15T12:29:17.044062+00:00 app[worker.1]: /app/src/commands/poll.js:127
2020-10-15T12:29:17.044089+00:00 app[worker.1]: }
2020-10-15T12:29:17.044089+00:00 app[worker.1]: ^
2020-10-15T12:29:17.044089+00:00 app[worker.1]:
2020-10-15T12:29:17.044090+00:00 app[worker.1]: SyntaxError: Unexpected token '}'
2020-10-15T12:29:17.044091+00:00 app[worker.1]: at wrapSafe (internal/modules/cjs/loader.js:979:16)
2020-10-15T12:29:17.044091+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1027:27)
2020-10-15T12:29:17.044138+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2020-10-15T12:29:17.044139+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:928:32)
2020-10-15T12:29:17.044140+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2020-10-15T12:29:17.044140+00:00 app[worker.1]: at Module.require (internal/modules/cjs/loader.js:952:19)
2020-10-15T12:29:17.044140+00:00 app[worker.1]: at require (internal/modules/cjs/helpers.js:88:18)
2020-10-15T12:29:17.044141+00:00 app[worker.1]: at module.exports (/app/src/handlers/command.js:12:22)
2020-10-15T12:29:17.044141+00:00 app[worker.1]: at /app/src/index.js:16:37
2020-10-15T12:29:17.044141+00:00 app[worker.1]: at Array.forEach ()
2020-10-15T12:29:17.044142+00:00 app[worker.1]: at Object. (/app/src/index.js:14:14)
2020-10-15T12:29:17.044142+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1063:30)
2020-10-15T12:29:17.044142+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
2020-10-15T12:29:17.044142+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:928:32)
2020-10-15T12:29:17.044143+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:769:14)
2020-10-15T12:29:17.044149+00:00 app[worker.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
2020-10-15T12:29:17.117259+00:00 heroku[worker.1]: Process exited with status 1

Remove the .env file from the project

As a good practice, we use to add the .env file to the git repository, this is because the .env file use to have confidential information about the server and connection.

If we want to preserve the possible entries, we should create a .env.example file which has the requires structure.

[BUG] Remove Unused Code

Describe the bug
It seems that after some of the refactoring that's been performed recently, the code in src/commands/info/commands.js is no longer in use. It makes sense to delete this file from the repo.

Add tests for the repo

This repo is getting popular, what do you think if we create a suite of tests to ensure that the incoming pull request does not broke anything?

Wrap the code to be compatible with node 6

Latest features of NodeJS, also known as EcmaScript 2017 and above, won't work in older versions than Node 8.0, in order to run scripts with all the features available, we should wrap the code using babel and polyfill.

The idea is the follwoing:

  • Move all the javascript files to the src directory.
  • Install babel and polyfill as dependencies of the project.
  • For development proposes no changes will needed.
  • For deployment, we should change the script with the following changes:
    1. The environment should forced to be production in order to connect with the real mognodb parameters.
    2. The src directory should be transpiled into the build directory using babel an polyfill.

Repeated code in almost all the commands

In almost all the commands exists a validation for the channel existence, if it does not exists, then it create it, what you think if abstract that code in a util to re-use it in all needed places?

image

The docker-compose file needs updating

As stated by @medusalix:

  • It was a real pain getting the bot to work correctly. The env_file directive in the docker-compose.yaml doesn't make any sense, as dotenv wants to read from a .env file which doesn't exist in the container. Adding a corresponding volume entry fixed that.
    The devMongoUrl should point to the local mongo docker container in my opinion. Makes it way easier to test things without having to create a MongoDB Atlas account.

Add a Multi Remove command

The Remove command let's you remove only one element to the list. Add a MultiRemove command that lets you remove more than one on a single command

[BUG] The devMongoURL string is broken

As apointed by @rgroves:

Also, it looks like the code base is in a somewhat broken state. I had to modify src\commands\polls.js to remove an error and modify the devMongoUrl connection string in src\config\index.js. (Note: I was not using Docker)

[Admins] Add a $demote user

Same as de $promote command. This command should check if the user calling it is an admin. Removes the admin role of the user passed as parameter (if this user was an admin before, of course)

Bug on mongoose

(node:48710) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: Could not connect to any servers in your MongoDB Atlas cluster. One common reason is that you're trying to access the database from an IP that isn't whitelisted. Make sure your current IP address is on your Atlas cluster's IP whitelist: https://docs.atlas.mongodb.com/security-whitelist/
at NativeConnection.Connection.openUri (/Users/tomassirio/Bots/DiscordBot/node_modules/mongoose/lib/connection.js:800:32)
at /Users/tomassirio/Bots/DiscordBot/node_modules/mongoose/lib/index.js:341:10
at /Users/tomassirio/Bots/DiscordBot/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:5
at new Promise ()
at promiseOrCallback (/Users/tomassirio/Bots/DiscordBot/node_modules/mongoose/lib/helpers/promiseOrCallback.js:30:10)
at Mongoose.connect (/Users/tomassirio/Bots/DiscordBot/node_modules/mongoose/lib/index.js:340:10)
at _callee$ (/Users/tomassirio/Bots/DiscordBot/build/utils/mongoose.js:55:31)
at tryCatch (/Users/tomassirio/Bots/DiscordBot/node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (/Users/tomassirio/Bots/DiscordBot/node_modules/regenerator-runtime/runtime.js:293:22)
at Generator.next (/Users/tomassirio/Bots/DiscordBot/node_modules/regenerator-runtime/runtime.js:118:21)
at asyncGeneratorStep (/Users/tomassirio/Bots/DiscordBot/build/utils/mongoose.js:3:103)
at _next (/Users/tomassirio/Bots/DiscordBot/build/utils/mongoose.js:5:194)
at /Users/tomassirio/Bots/DiscordBot/build/utils/mongoose.js:5:364
at new Promise ()
at Object. (/Users/tomassirio/Bots/DiscordBot/build/utils/mongoose.js:5:97)
at Object.init (/Users/tomassirio/Bots/DiscordBot/build/utils/mongoose.js:69:20)
(Use node --trace-warnings ... to show where the warning was created)
(node:48710) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:48710) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[BUG] $Ping command is shutting down the bot

2020-10-09T14:31:08.410764+00:00 app[worker.1]: /app/src/commands/ping.js:17
2020-10-09T14:31:08.410783+00:00 app[worker.1]: } catch (error) {
2020-10-09T14:31:08.410784+00:00 app[worker.1]: ^^^^^
2020-10-09T14:31:08.410784+00:00 app[worker.1]:
2020-10-09T14:31:08.410785+00:00 app[worker.1]: SyntaxError: Unexpected token 'catch'
2020-10-09T14:31:08.410785+00:00 app[worker.1]: at compileFunction ()
2020-10-09T14:31:08.410786+00:00 app[worker.1]: at wrapSafe (internal/modules/cjs/loader.js:931:16)
2020-10-09T14:31:08.410786+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:979:27)
2020-10-09T14:31:08.410786+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-10-09T14:31:08.410787+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-10-09T14:31:08.410787+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-10-09T14:31:08.410787+00:00 app[worker.1]: at Module.require (internal/modules/cjs/loader.js:903:19)
2020-10-09T14:31:08.410788+00:00 app[worker.1]: at require (internal/modules/cjs/helpers.js:74:18)
2020-10-09T14:31:08.410788+00:00 app[worker.1]: at module.exports (/app/src/handlers/command.js:10:16)
2020-10-09T14:31:08.410788+00:00 app[worker.1]: at /app/src/index.js:15:37
2020-10-09T14:31:08.410789+00:00 app[worker.1]: at Array.forEach ()
2020-10-09T14:31:08.410789+00:00 app[worker.1]: at Object. (/app/src/index.js:14:13)
2020-10-09T14:31:08.410789+00:00 app[worker.1]: at Module._compile (internal/modules/cjs/loader.js:1015:30)
2020-10-09T14:31:08.410790+00:00 app[worker.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
2020-10-09T14:31:08.410790+00:00 app[worker.1]: at Module.load (internal/modules/cjs/loader.js:879:32)
2020-10-09T14:31:08.410790+00:00 app[worker.1]: at Function.Module._load (internal/modules/cjs/loader.js:724:14)
2020-10-09T14:31:08.529644+00:00 heroku[worker.1]: Process exited with status 1

Command refactor

The bot is really sloppy since it was a hobby project. If you want to change something or make something look better, then give it a try

[BUG] Poll Command - Bot does not provide the initial emoji reacts when poll has no end time.

Describe the bug
When a poll is started the bot should announce the poll via a message and create the initial reacts that are to be used for voting on that message. Currently, when a poll with no time limit is created the initial reacts are not created.

To Reproduce
Steps to reproduce the behavior:

  1. enter $poll without specifying a time parameter or use zero, $poll 0
  2. The bot creates the poll message, but the initial reacts (1️⃣2️⃣3️⃣4️⃣5️⃣) do not appear under the poll for voting.

Expected behavior
After the poll command is issued, the bot should announce the poll and create the initial reacts that are used to vote, regardless of if the bot has a time duration associated with it.

Screenshots
Here is what a poll without a time parameter looks like currently. Notice there are no reacts available for voting
image

This is what a poll with a time parameter supplied looks like. Notice the bot supplied the initial reacts that are to be used for voting.
image

Improve the project setup

I have noticed that the project require some extra steps to be executed in local environments, as well, as some good practices that we could implement in here.

I have created a PR with 3 main changes:

  • Add a .env.example file to store the constants of the project, this will allow you to have your own copy of .env file with your personal information.
  • Remove node_modules from the git repository, since it could be easilly installes by running the npm install or yarn install command, also, the node_modules is the bigger in all the project.
  • Create a USE_DOCKER_FOR_DEVELOP environment constant, which will change the manual change of the database connection.

The PR with this changes is this one: #15

[FEATURE] The embedded messages look kind of sloppy

image

That's the list command right now. Every notification on the bot shows a similar message. It would look really nice if we could get a message like the queue on groovy

image

Example:

  1. <list element>                        <author>
    
  2. <list element>                        <author>
    

.....
n)

The bot needs to follow a convention

@medusalix:

  • The project should really follow a consistent code style: Semicolons/no semicolons, double quotes/single quotes, let for constant variables, etc... I'd suggest using a combination of Prettier and ESLint. Makes contributing so much easier.

My suggestions would be: No semicolons, single quotes and let for variables.
However, i'm not an experienced Node.js developer. So any suggestions, such as Prettier and ESLint as stated before will be considered

[BUG] Poll Command - Bot does not handle polls with less than 5 options in the list correctly.

Describe the bug
When a poll is started and the list has less than 5 items, the bot provides all 5 reacts for voting.

To Reproduce
Steps to reproduce the behavior:

  1. Make sure your list has less than 5 items in it (1 - 4 items)
  2. Send a poll command like $poll 1
  3. You'll see that when the bot creates the poll message, it creates all 5 initial reacts for voting, when it should stop at the number of items being voted on.

Expected behavior
When a poll is started and the list has less than 5 items, the bot provides should only provide a number of reacts equal to the number of items being voted on. (e.g. if only two items in list, initial reacts should be: 1️⃣ & 2️⃣; for 3 items 1️⃣, 2️⃣, 3️⃣; etc.)

Screenshots
Here you can see a 1 minute poll run in a channel where there are only two items available in the list, yet the bot supplies all 5 reacts for voting, when it should only have two so that it matches the number of items being voted on.

image

[BUG] $ping command is still faulty.

(node:4) UnhandledPromiseRejectionWarning: ReferenceError: client is not defined
2020-10-09T23:33:01.843042+00:00 app[worker.1]: at Object.execute (/app/src/commands/ping.js:11:45)
2020-10-09T23:33:01.843044+00:00 app[worker.1]: at processTicksAndRejections (internal/process/task_queues.js:97:5)
2020-10-09T23:33:01.843137+00:00 app[worker.1]: (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
2020-10-09T23:33:01.847679+00:00 app[worker.1]: (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
That was the issue with ping

That was the issue with ping in heroku's log

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.