@sopel.module.commands(u'console')
def interactive_shell(bot, trigger):
 global console
 if (not trigger.admin):
  bot.say(u'Only admins can start the interactive console')
  return
 if ((u'iconsole_running' in bot.memory) and bot.memory[u'iconsole_running']):
  bot.say(u'Console already running')
  return
 if (not sys.__stdout__.isatty()):
  bot.say(u'A tty is required to start the console')
  return
 if bot._daemon:
  bot.say(u"Can't start console when running as a daemon")
  return
 old_stdout = sys.stdout
 old_stderr = sys.stderr
 sys.stdout = sys.__stdout__
 sys.stderr = sys.__stderr__
 banner1 = u'Sopel interactive shell (embedded IPython)'
 banner2 = u'`bot` and `trigger` are available. To exit, type exit'
 exitmsg = u'Interactive shell closed'
 console = InteractiveShellEmbed(banner1=banner1, banner2=banner2, exit_msg=exitmsg)
 bot.memory[u'iconsole_running'] = True
 bot.say(u'console started')
 console()
 bot.memory[u'iconsole_running'] = False
 sys.stdout = old_stdout
 sys.stderr = old_stderr

@ sopel . module . commands ( u'console' ) def interactive_shell ( bot , trigger ) : global console if ( not trigger . admin ) : bot . say ( u'Only admins can start the interactive console' ) return if ( ( u'iconsole_running' in bot . memory ) and bot . memory [ u'iconsole_running' ] ) : bot . say ( u'Console already running' ) return if ( not sys . __stdout__ . isatty ( ) ) : bot . say ( u'A tty is required to start the console' ) return if bot . _daemon : bot . say ( u"Can't start console when running as a daemon" ) return old_stdout = sys . stdout old_stderr = sys . stderr sys . stdout = sys . __stdout__ sys . stderr = sys . __stderr__ banner1 = u'Sopel interactive shell (embedded IPython)' banner2 = u'`bot` and `trigger` are available. To exit, type exit' exitmsg = u'Interactive shell closed' console = InteractiveShellEmbed ( banner1 = banner1 , banner2 = banner2 , exit_msg = exitmsg ) bot . memory [ u'iconsole_running' ] = True bot . say ( u'console started' ) console ( ) bot . memory [ u'iconsole_running' ] = False sys . stdout = old_stdout sys . stderr = old_stderr
starts an interactive ipython console .