Nos78 / MrData

Discord Bot providing some simple scoring using postgres
GNU General Public License v3.0
3 stars 1 forks source link

Re-factor bot.js, level of abstraction, extract code into library functions #23

Open Nos78 opened 4 years ago

Nos78 commented 4 years ago

Background

There is some code in bot.js that should be extracted into new (or existing) libraries.

Modular command system

When the bot loads, the modular command system loads the commands from disk collates them into a collection. This is currently done within the main bot code, in bot.js. During development, if command files are modified, the bot has to be restarted.

Since the command system is supposed to be modular, one would be forgiven for thinking this means that commands are plug and play - you just drop a new file into the commands folder and a new command is accessible via discord. But that is not the case.

New functionality However, if the command initialisation code where extracted into a library, a new command to reinitialise the bot could be created - meaning commands could be updated at runtime, and the bot would not have to be restarted every time there is a change to a command.

Alternatively, there are a range of events that could be hooked - one of these might be able to perform a similar task.

Pretty stack traces

There is some code that outputs a stack trace to the channel if an error is caught. This code should be extracted into a library function, so it can be used elsewhere.