From 42ba1775d75c9456865f1ad94954eac21d665bee Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 4 Mar 2017 21:59:42 -0800 Subject: [PATCH] exec: add irc, source, and args to isolated locals scopes This allows basic things like irc.reply() to work in 'iexec'. --- plugins/exec.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/exec.py b/plugins/exec.py index da90253..44aa1b7 100644 --- a/plugins/exec.py +++ b/plugins/exec.py @@ -34,6 +34,12 @@ def _exec(irc, source, args, locals_dict=None): irc.getHostmask(source)) if locals_dict is None: locals_dict = locals() + else: + # Add irc, source, and args to the given locals_dict, to allow basic things like irc.reply() + # to still work. + locals_dict['irc'] = irc + locals_dict['source'] = source + locals_dict['args'] = args exec(args, globals(), locals_dict) @@ -44,9 +50,12 @@ utils.add_cmd(_exec, 'exec') def iexec(irc, source, args): """ - Admin-only. Executes in the current PyLink instance, using a persistent, isolated + Admin-only. Executes in the current PyLink instance with a persistent, isolated locals scope (world.plugins['exec'].exec_local_dict). + Note: irc, source, and args are added into this locals dict to allow things like irc.reply() + to still work. + \x02**WARNING: THIS CAN BE DANGEROUS IF USED IMPROPERLY!**\x02 """ _exec(irc, source, args, locals_dict=exec_locals_dict)