command_driver.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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__(config.extend(rollbot.CommandConfiguration(bangs=("!",))), "/tmp/terminalbot.db")
  8. def read_config(self, key):
  9. return key
  10. def parse(self, raw):
  11. return rollbot.Message(
  12. origin_id="REPL",
  13. channel_id=".",
  14. sender_id=".",
  15. timestamp=datetime.now(),
  16. origin_admin=True,
  17. channel_admin=True,
  18. text="!" + raw,
  19. attachments=[],
  20. )
  21. async def respond(self, res):
  22. print(res.text, flush=True)
  23. for att in res.attachments:
  24. print(f"Attached: {att.name}", flush=True)
  25. async def run():
  26. bot = TerminalBot()
  27. await bot.on_startup()
  28. try:
  29. while True:
  30. await bot.on_message(input("> !"))
  31. except EOFError:
  32. pass
  33. finally:
  34. await bot.on_shutdown()
  35. asyncio.run(run())