Skip to content
Snippets Groups Projects
Commit 9260e829 authored by Tulir Asokan's avatar Tulir Asokan
Browse files

Add usage instructions

parent 33cec41d
No related branches found
No related tags found
No related merge requests found
# 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.
......@@ -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
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment