command_driver.py 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import asyncio
  2. from datetime import datetime
  3. import rollbot
  4. from commands import config
  5. class TerminalBot(rollbot.Rollbot[str]):
  6. def __init__(self):
  7. super().__init__(
  8. config.extend(rollbot.CommandConfiguration(bangs=("!",))), "/tmp/terminalbot.db"
  9. )
  10. def read_config(self, key):
  11. return key
  12. def parse(self, raw):
  13. return rollbot.Message(
  14. origin_id="REPL",
  15. channel_id=".",
  16. sender_id=".",
  17. timestamp=datetime.now(),
  18. origin_admin=True,
  19. channel_admin=True,
  20. text="!" + raw,
  21. attachments=[],
  22. )
  23. async def respond(self, res):
  24. print(res.text, flush=True)
  25. for att in res.attachments:
  26. print(f"Attached: {att.name}", flush=True)
  27. async def run():
  28. bot = TerminalBot()
  29. await bot.on_startup()
  30. try:
  31. while True:
  32. await bot.on_message(input("> !"))
  33. except EOFError:
  34. pass
  35. finally:
  36. await bot.on_shutdown()
  37. asyncio.run(run())