From 9260e8291f72de3b28d1fc3883cf0c3d37e238f1 Mon Sep 17 00:00:00 2001 From: Tulir Asokan <tulir@maunium.net> Date: Thu, 29 Aug 2019 00:32:45 +0300 Subject: [PATCH] Add usage instructions --- README.md | 36 ++++++++++++++++++++++++++++++++++++ base-config.yaml | 2 ++ exec/bot.py | 7 +++++-- 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7ac6162..e097ee5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,38 @@ # exec A [maubot](https://github.com/maubot/maubot) that executes code. + +# This does not work yet + +## Usage +The bot is triggered by a specific message prefix (defaults to `!exec`) and +executes the code in the first code block. + +<pre> +!exec +```python +print("Hello, World!") +``` +</pre> + +Standard input can be added with another code block that has `stdin` as the +language: + +<pre> +!exec +```python +print(f"Hello, {input()}") +``` + +```stdin +maubot +``` +</pre> + +When the bot executes the code, it'll reply immediately and then update the +output using edits until the command finishes. After it finishes, the reply +will be edited to contain the return values. + +If running in userbot mode, the bot will edit your original message instead of +making a new reply message. + +Currently, the bot supports `python` and `shell` as languages. diff --git a/base-config.yaml b/base-config.yaml index b62ac94..a91e618 100644 --- a/base-config.yaml +++ b/base-config.yaml @@ -8,3 +8,5 @@ userbot: false # sandboxing in maubot or this plugin, keep this list small. whitelist: - '@user:example.com' +# Number of seconds to wait between output update edits. +output_interval: 5 diff --git a/exec/bot.py b/exec/bot.py index 68d0530..eb10c64 100644 --- a/exec/bot.py +++ b/exec/bot.py @@ -35,12 +35,14 @@ class Config(BaseProxyConfig): helper.copy("prefix") helper.copy("userbot") helper.copy("whitelist") + helper.copy("output_interval") class ExecBot(Plugin): whitelist: Set[UserID] userbot: bool prefix: str + output_interval: int @classmethod def get_config_class(cls) -> Type[BaseProxyConfig]: @@ -54,6 +56,7 @@ class ExecBot(Plugin): self.whitelist = set(self.config["whitelist"]) self.userbot = self.config["userbot"] self.prefix = self.config["prefix"] + self.output_interval = self.config["output_interval"] @event.on(EventType.ROOM_MESSAGE) async def exec(self, evt: MessageEvent) -> None: @@ -72,12 +75,12 @@ class ExecBot(Plugin): for entity in command.entities: if entity.type != EntityType.PREFORMATTED: continue - current_lang = entity.extra_info["language"] + current_lang = entity.extra_info["language"].lower() value = command.text[entity.offset:entity.offset+entity.length] if not code: code = value lang = current_lang - elif lang == "stdin": + elif lang == "stdin" or lang == "input": stdin += value if not code or not lang: return -- GitLab