fulvia/modules/ipython.py

32 lines
858 B
Python
Raw Permalink Normal View History

2018-03-16 03:13:43 -04:00
#!/usr/bin/env python3
"""
An iPython interactive console for debugging purposes.
"""
from IPython.terminal.embed import InteractiveShellEmbed
import module
def setup(bot):
bot.memory["iconsole_running"] = False
@module.require_admin("Only admins can start the interactive console")
@module.commands('console')
def interactive_shell(bot, trigger):
"""
Starts an interactive IPython console
"""
if bot.memory['iconsole_running']:
2018-05-25 15:21:18 -04:00
return bot.msg('Console already running')
2018-03-16 03:13:43 -04:00
banner1 = 'Fulvia interactive shell (embedded IPython)'
2018-03-16 03:13:43 -04:00
banner2 = '`bot` and `trigger` are available. To exit, type exit'
exitmsg = 'Interactive shell closed'
console = InteractiveShellEmbed(banner1=banner1, banner2=banner2,
exit_msg=exitmsg)
bot.memory['iconsole_running'] = True
2018-05-25 15:21:18 -04:00
bot.msg('console started')
2018-03-16 03:13:43 -04:00
console()
bot.memory['iconsole_running'] = False