repl_driver.py 1022 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from datetime import datetime
  2. import asyncio
  3. import rollbot
  4. class MyBot(rollbot.Rollbot[str]):
  5. def read_config(self, key):
  6. return key
  7. def parse(self, raw):
  8. return rollbot.Message(
  9. origin_id="REPL",
  10. channel_id=".",
  11. sender_id=".",
  12. timestamp=datetime.now(),
  13. origin_admin=True,
  14. channel_admin=True,
  15. text=raw,
  16. attachments=[],
  17. )
  18. async def respond(self, res):
  19. print(res, flush=True)
  20. async def goodbye_command(context):
  21. await context.respond(rollbot.Response.from_message(context.message, "Goodbye!"))
  22. config = rollbot.CommandConfiguration(
  23. bangs=("/",),
  24. commands={
  25. "goodbye": goodbye_command,
  26. },
  27. call_and_response={
  28. "hello": "Hello!",
  29. },
  30. aliases={
  31. "hi": "hello",
  32. "bye": "goodbye",
  33. }
  34. )
  35. bot = MyBot(config, "/tmp/my.db")
  36. async def run():
  37. while True:
  38. await bot.on_message(input("> "))
  39. asyncio.run(run())