Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
maubot-exec-cmd
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
isgphys
maubot-exec-cmd
Commits
9260e829
Commit
9260e829
authored
5 years ago
by
Tulir Asokan
Browse files
Options
Downloads
Patches
Plain Diff
Add usage instructions
parent
33cec41d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+36
-0
36 additions, 0 deletions
README.md
base-config.yaml
+2
-0
2 additions, 0 deletions
base-config.yaml
exec/bot.py
+5
-2
5 additions, 2 deletions
exec/bot.py
with
43 additions
and
2 deletions
README.md
+
36
−
0
View file @
9260e829
# 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.
This diff is collapsed.
Click to expand it.
base-config.yaml
+
2
−
0
View file @
9260e829
...
...
@@ -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
This diff is collapsed.
Click to expand it.
exec/bot.py
+
5
−
2
View file @
9260e829
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment