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 # exec
A [maubot](https://github.com/maubot/maubot) that executes code. 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 ...@@ -8,3 +8,5 @@ userbot: false
# sandboxing in maubot or this plugin, keep this list small. # sandboxing in maubot or this plugin, keep this list small.
whitelist: whitelist:
- '@user:example.com' - '@user:example.com'
# Number of seconds to wait between output update edits.
output_interval: 5
...@@ -35,12 +35,14 @@ class Config(BaseProxyConfig): ...@@ -35,12 +35,14 @@ class Config(BaseProxyConfig):
helper.copy("prefix") helper.copy("prefix")
helper.copy("userbot") helper.copy("userbot")
helper.copy("whitelist") helper.copy("whitelist")
helper.copy("output_interval")
class ExecBot(Plugin): class ExecBot(Plugin):
whitelist: Set[UserID] whitelist: Set[UserID]
userbot: bool userbot: bool
prefix: str prefix: str
output_interval: int
@classmethod @classmethod
def get_config_class(cls) -> Type[BaseProxyConfig]: def get_config_class(cls) -> Type[BaseProxyConfig]:
...@@ -54,6 +56,7 @@ class ExecBot(Plugin): ...@@ -54,6 +56,7 @@ class ExecBot(Plugin):
self.whitelist = set(self.config["whitelist"]) self.whitelist = set(self.config["whitelist"])
self.userbot = self.config["userbot"] self.userbot = self.config["userbot"]
self.prefix = self.config["prefix"] self.prefix = self.config["prefix"]
self.output_interval = self.config["output_interval"]
@event.on(EventType.ROOM_MESSAGE) @event.on(EventType.ROOM_MESSAGE)
async def exec(self, evt: MessageEvent) -> None: async def exec(self, evt: MessageEvent) -> None:
...@@ -72,12 +75,12 @@ class ExecBot(Plugin): ...@@ -72,12 +75,12 @@ class ExecBot(Plugin):
for entity in command.entities: for entity in command.entities:
if entity.type != EntityType.PREFORMATTED: if entity.type != EntityType.PREFORMATTED:
continue continue
current_lang = entity.extra_info["language"] current_lang = entity.extra_info["language"].lower()
value = command.text[entity.offset:entity.offset+entity.length] value = command.text[entity.offset:entity.offset+entity.length]
if not code: if not code:
code = value code = value
lang = current_lang lang = current_lang
elif lang == "stdin": elif lang == "stdin" or lang == "input":
stdin += value stdin += value
if not code or not lang: if not code or not lang:
return 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