It's current structure is a direct carryover from v0.9b, which was a much smaller and simpler codebase where it actually made sense. But now, CadenceBot is large, and complicated, and it's getting pretty hard to accurately traverse it - For me. For newcomers, the structure of the code is probably a massive roadblock to development work.
So, we need to put in some work and update the structure of the code in a big way.
Along the way, since I intend this to come after #105, we can afford to take some steps that I formerly haven't taken which will greatly improve the development and maintenance experience, but will add steps to the deployment of the bot that would be impractical (pre-Docker) - Namely, I'd like to at least add support for Typescript, and use Typescript at interfaces between parts of the refactor. New code should be Typescript-correct, but I'm ok for this refactor to not immediately go back and ensure everything makes the fullest use of the type system as long as things compile.
So, goals:
Break up bot.js into several files (perhaps main, commands, config, stream, api, and utils?)
Refactor the commands into individual subroutines (in the appropriate file)
The interface should not just pass a message, but instead should have an appropriate signature - A "term" for prefix commands, a function to send back a message, a function to send back a reply, etc - As required by the specific command.
It would be nice to avoid direct use of globals in these subroutines, and pass them in instead - For example, the search subroutine can return a Promise of the lastSearchedSongs array, and request would have a parameter for it. This would greatly simplify handling of one-step-request.
I'd like to see custom commands also refactored here - Probably one handler for custom commands in general, which dispatches to subroutines for each type of custom command.
Move all direct interactions with the Cadence API into the api file, and use that model of the API appropriately in other files.
Refactor out all use of "mock commands" and instead make appropriate use of the subroutines above.
Try to reduce main as far as possible - A dispatch to get the config set up, a dispatch to get the stream set up, Discord setup, and the command loop command dispatching to commands.
Get all source files using ts extensions and typescript syntax, with type annotations as appropriate especially at interfaces between files (exported functions), and add a step to build all of this during creation of the Dockerfile.
Make sure the refactor runs and has functional parity with the old version.
This will be a big change for CadenceBot with no functional difference to the user, but it will greatly help future development work.
CadenceBot is beyond due for a major refactor.
It's current structure is a direct carryover from v0.9b, which was a much smaller and simpler codebase where it actually made sense. But now, CadenceBot is large, and complicated, and it's getting pretty hard to accurately traverse it - For me. For newcomers, the structure of the code is probably a massive roadblock to development work.
So, we need to put in some work and update the structure of the code in a big way.
Along the way, since I intend this to come after #105, we can afford to take some steps that I formerly haven't taken which will greatly improve the development and maintenance experience, but will add steps to the deployment of the bot that would be impractical (pre-Docker) - Namely, I'd like to at least add support for Typescript, and use Typescript at interfaces between parts of the refactor. New code should be Typescript-correct, but I'm ok for this refactor to not immediately go back and ensure everything makes the fullest use of the type system as long as things compile.
So, goals:
search
subroutine can return aPromise
of thelastSearchedSongs
array, andrequest
would have a parameter for it. This would greatly simplify handling ofone-step-request
.api
file, and use that model of the API appropriately in other files.main
as far as possible - A dispatch to get the config set up, a dispatch to get the stream set up, Discord setup, and the command loopcommand
dispatching to commands.ts
extensions and typescript syntax, with type annotations as appropriate especially at interfaces between files (exported functions), and add a step to build all of this during creation of the Dockerfile.This will be a big change for CadenceBot with no functional difference to the user, but it will greatly help future development work.