Skip to content

Commit 21f9856

Browse files
committed
add command: run_command
1 parent 8afa778 commit 21f9856

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

hooks/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,24 @@ def man_run_task(task: str, env_str: str, src: CommandSource, server: PluginServ
147147
def clear_tasks(server: PluginServerInterface, src: CommandSource):
148148
for tsk in cfg.temp_config.task.copy().keys():
149149
tasks.delete_task(tsk, src, server)
150+
151+
152+
@new_thread('hooks - run_command')
153+
def run_command(command: str, task_type: str, server: PluginServerInterface, src: CommandSource):
154+
try:
155+
task_type_var1: tasks.TaskType = tasks.TaskType(task_type)
156+
except ValueError:
157+
src.reply(RTextMCDRTranslation('hooks.create.task_type_wrong', task_type))
158+
return
159+
160+
if task_type_var1 == tasks.TaskType.shell_command:
161+
os.system(command)
162+
elif task_type_var1 == tasks.TaskType.server_command:
163+
server.execute(command)
164+
elif task_type_var1 == tasks.TaskType.mcdr_command:
165+
server.execute_command(command)
166+
elif task_type_var1 == tasks.TaskType.python_code:
167+
exec(command)
150168

151169

152170
def _parse_and_apply_scripts(script: str, server: PluginServerInterface):
@@ -396,6 +414,18 @@ def on_load(server: PluginServerInterface, old_module):
396414
.requires(lambda src: src.has_permission(3))
397415
.runs(lambda src: clear_tasks(server, src))
398416
)
417+
.then(
418+
Literal('run_command')
419+
.then(
420+
Text('task_type')
421+
.suggests(lambda: tasks.TaskType.__members__)
422+
.then(
423+
GreedyText('command')
424+
.requires(lambda src: src.has_permission(3))
425+
.runs(lambda src, ctx: run_command(ctx['command'], ctx['task_type'], server, src))
426+
)
427+
)
428+
)
399429
)
400430

401431
trigger_hooks(mount.Hooks.on_plugin_loaded, server,

0 commit comments

Comments
 (0)