|
@@ -0,0 +1,45 @@
|
|
|
+import asyncio
|
|
|
+from datetime import datetime
|
|
|
+
|
|
|
+import rollbot
|
|
|
+from commands import config
|
|
|
+
|
|
|
+
|
|
|
+class TerminalBot(rollbot.Rollbot[str]):
|
|
|
+ def __init__(self):
|
|
|
+ super().__init__(config.extend(rollbot.CommandConfiguration(bangs=("!",))), "/tmp/terminalbot.db")
|
|
|
+
|
|
|
+ def read_config(self, key):
|
|
|
+ return key
|
|
|
+
|
|
|
+ def parse(self, raw):
|
|
|
+ return rollbot.Message(
|
|
|
+ origin_id="REPL",
|
|
|
+ channel_id=".",
|
|
|
+ sender_id=".",
|
|
|
+ timestamp=datetime.now(),
|
|
|
+ origin_admin=True,
|
|
|
+ channel_admin=True,
|
|
|
+ text="!" + raw,
|
|
|
+ attachments=[],
|
|
|
+ )
|
|
|
+
|
|
|
+ async def respond(self, res):
|
|
|
+ print(res.text, flush=True)
|
|
|
+ for att in res.attachments:
|
|
|
+ print(f"Attached: {att.name}", flush=True)
|
|
|
+
|
|
|
+
|
|
|
+async def run():
|
|
|
+ bot = TerminalBot()
|
|
|
+ await bot.on_startup()
|
|
|
+ try:
|
|
|
+ while True:
|
|
|
+ await bot.on_message(input("> !"))
|
|
|
+ except EOFError:
|
|
|
+ pass
|
|
|
+ finally:
|
|
|
+ await bot.on_shutdown()
|
|
|
+
|
|
|
+
|
|
|
+asyncio.run(run())
|