def menu(self): while True: self.data.load() self.write('Current configuration:') # Display config data! info = self.data.info self.write('Bot {0} = {1}'.format('username', info.username)) self.write('Bot {0} = {1}'.format('password', info.password)) self.write('Bot {0} = {1}'.format('owner', info.owner)) self.write('Bot {0} = {1}'.format('trigger', info.trigger)) self.write('Autojoin:') self.write(', '.join(self.data.autojoin)) self.write('') self.write('Choose one of the following options:') self.write('info - Set the bot\'s configuration information.') self.write('autojoin - Set the bot\'s autojoin list.') self.write('all - Set all configuration data.') self.write('exit - Leave the configuration file.') ins = '' while not ins in ('all', 'autojoin', 'exit', 'info'): ins = get_input('>> ').lower() if ins == 'exit': return if ins == 'all': self.run_all() continue if ins == 'info': self.get_info() self.save() continue if ins == 'autojoin': self.get_autojoin() self.save()
def run(args, restartable=True): args = args[2:].lower() if not args in ('bot', 'debug', 'config', 'exit') or args == 'menu': restartable = False sys.stdout.write('===========> Main Menu <============\n>>> Welcome!\n>>> Please select an option!\n') sys.stdout.write('>> Bot - Run the bot.\n') sys.stdout.write('>> Debug - Run the bot in debug mode.\n') sys.stdout.write('>> Config - Configure the bot.\n') sys.stdout.write('>> Exit - Close this program.\n') sys.stdout.flush() while not args in ('bot', 'debug', 'config', 'exit'): args = get_input().lower() if args in ('bot', 'debug'): from terra import core ret = core.Main(args == 'debug', restartable) sys.stdout.write(('='*80) + '\n') if ret.close and not (ret.restart and restartable): return argv = [(str(i) if not k else i) for k, i in enumerate(sys.argv)] if ret.restart and restartable: subprocess.Popen([sys.executable] + argv) return resp = '' while not resp in ('y', 'n'): resp = get_input('>> Would you like to reboot?[Y|N]: ').lower() if resp == 'y': sys.stdout.write(('='*80) + '\n') subprocess.Popen([sys.executable] + argv) return input('>> Press enter to continue...') return if args == 'config': from terra.config import Configure Configure() if restartable: return if args == 'exit': return run('--menu', False)
def get_autojoin(self): self.write( 'Next we need to know which channels you want your' ) self.write( 'bot to join on startup. Please enter a list of' ) self.write( 'channels below, separated by commas. Each channel' ) self.write( 'must begin with a hash (#) or chat:. Leave blank' ) self.write( 'to use the default (#Botdom).' ) aj = get_input('> ', True) if aj: aj = aj.split(',') if aj: self.data.autojoin = [ns.strip() for ns in aj if ns.strip()] if not self.data.autojoin: self.data.autojoin.append('#Botdom')
def get_info(self): for option in ['username', 'password', 'owner', 'trigger']: setattr(self.data.info, option, get_input('> Bot ' + option + ': '))