MrHedmad / Milton

Home of Milton Lab Assistant - the Discord Bot for laboratories.
MIT License
1 stars 1 forks source link

The CLI module is terrible #2

Closed MrHedmad closed 1 year ago

MrHedmad commented 4 years ago

The CLI module (cli.py) should be overhauled.

A possible solution would be to use an appropriate library such as click or similar, but they would need to be capable of async.

It is best to move the CLI out of the cogs and into the bot itself, and schedule its execution with asyncio.Loop.create_task as the bot starts (run) and stop it as the bot closes (close).

MrHedmad commented 1 year ago

I asked on Pydis for how to make this module better. A suggestion was to use prompt-toolkit (perhaps instead of aioconsole?).

Another useful tip is to wrap stdout to not override the CLI prompt on message:

class WrappedStdout:
  def __init__(self, stream):
    self.stream = stream
  def write(self, message):
    # handle it
    pass

sys.stdout = WrappedStdout(sys.stdout)