Fixed module reload command.
This commit is contained in:
parent
39295f3818
commit
78487edd56
10
bot.py
10
bot.py
|
@ -155,15 +155,16 @@ async def cmd_import( bot, p, ctx ):
|
||||||
if ctx['nick'] != con.cfg['usr']['owner']: return
|
if ctx['nick'] != con.cfg['usr']['owner']: return
|
||||||
dst = ctx['dst']
|
dst = ctx['dst']
|
||||||
if p and p[0] in _MOD_MAP.keys():
|
if p and p[0] in _MOD_MAP.keys():
|
||||||
prev_mod = None
|
|
||||||
try:
|
|
||||||
prev_mod = _MOD_MAP.pop( p[0], None )
|
prev_mod = _MOD_MAP.pop( p[0], None )
|
||||||
# if not reloading root bot module, re-append the modules. package name
|
# if not reloading root bot module, re-append the modules. package name
|
||||||
if p[0] != 'bot': p[0] = 'modules.' + p[0]
|
sys_mod = p[0]
|
||||||
importlib.reload( sys.modules[p[0]] )
|
if p[0] != 'bot': sys_mod = 'modules.' + sys_mod
|
||||||
|
try:
|
||||||
|
importlib.reload( sys.modules[sys_mod] )
|
||||||
con.say_to( dst, 'Success!' )
|
con.say_to( dst, 'Success!' )
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
con.say_to( dst, str( e ) )
|
con.say_to( dst, str( e ) )
|
||||||
|
# reinsert using original fixed name
|
||||||
_MOD_MAP[p[0]] = prev_mod
|
_MOD_MAP[p[0]] = prev_mod
|
||||||
else: con.say_to( dst, 'Module not found' )
|
else: con.say_to( dst, 'Module not found' )
|
||||||
|
|
||||||
|
@ -199,4 +200,5 @@ async def cmd_discon( b, p, c ):
|
||||||
# custom modules
|
# custom modules
|
||||||
importlib.import_module( '.qdb', 'modules' )
|
importlib.import_module( '.qdb', 'modules' )
|
||||||
importlib.import_module( '.misc', 'modules' )
|
importlib.import_module( '.misc', 'modules' )
|
||||||
|
#importlib.import_module( '.kai', 'modules' )
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ def do_eval( evstr ):
|
||||||
|
|
||||||
@command( 'eval' )
|
@command( 'eval' )
|
||||||
async def cmd_eval( b, p, c ):
|
async def cmd_eval( b, p, c ):
|
||||||
""" Evaluate a python expression. Trust me, it's safe. """
|
""" Evaluates Python code. Trust me, it's safe. """
|
||||||
evstr = urllib.parse.quote( ' '.join( p ) )
|
evstr = urllib.parse.quote( ' '.join( p ) )
|
||||||
# do the actual request in a separate thread
|
# do the actual request in a separate thread
|
||||||
rstr = await b._loop.run_in_executor( None, functools.partial( do_eval, evstr ) ) #do_eval, evstr, c )
|
rstr = await b._loop.run_in_executor( None, functools.partial( do_eval, evstr ) ) #do_eval, evstr, c )
|
||||||
|
|
Loading…
Reference in New Issue