Hambergo / 9kmmrbot

MIT License
104 stars 29 forks source link

Change how commands are added to the Twitch client #34

Closed tverghis closed 3 years ago

tverghis commented 5 years ago

/index.js:32: We loop over all the files in the ./lib/commands/ directory, require them, and store the required modules in an array. This array is then passed into the Twitch client to register them as commands. In this process, we need to explicitly avoid loading Command.js, because it's not actually a command that can be called.

This has a few drawbacks I can think of:

  1. If we add files under the ./lib/commands/ directory, we might need to add exceptions to the load process (like Command.js).
  2. Why are we re-inventing what is essentially a module loader?

Why not just create an index.js file in ./lib/commands/ that exports only the appropriate commands from the directory? Then all that needs to be done is a simple require('./lib/commands') in the Twitch client.

tverghis commented 5 years ago

I wrote up this issue because I'm running into problems splitting out sub-commands from Moderation.js for #33. I currently can't put those files under a subfolder in the ./lib/commands/ folder, because it breaks the above loader.

(Temporarily 'fixed' this by also adding a filter for my subfolder's name, but it doesn't seem like the correct solution)

Hambergo commented 5 years ago

You are correct and it should be like that, I think the only reason I wrote it like that was of pure laziness