def get_user(self, redirect): try: file = open(self.cachef, 'r') cache = json.loads(file.read()) file.close() except IOError: self.debug('>> No cache data stored') self.d = defer.Deferred() self.start_auth(redirect) return self.d user = get_input('> Bot account username: '******'username'] self.data.api.symbol = data['symbol'] self.data.api.code = data['code'] self.data.api.token = data['token'] self.data.api.refresh = data['refresh'] self.data.api.damntoken = data['damntoken'] self.debug('** Found cached data for {0}{1}.'.format( data['symbol'], data['username'])) self.save() except KeyError: self.write('>> No cached data stored for \'{0}\''.format(user)) self.write('>> Requires authorization') self.d = defer.Deferred() self.start_auth(redirect) return self.d return None
def get_user(self, redirect): try: file = open(self.cachef, 'r') cache = json.loads(file.read()) file.close() except IOError: self.debug('>> No cache data stored') self.d = defer.Deferred() self.start_auth(redirect) return self.d user = get_input('> Bot account username: '******'username'] self.data.api.symbol = data['symbol'] self.data.api.code = data['code'] self.data.api.token = data['token'] self.data.api.refresh = data['refresh'] self.data.api.damntoken = data['damntoken'] self.debug('** Found cached data for {0}{1}.'.format(data['symbol'], data['username'])) self.save() except KeyError: self.write('>> No cached data stored for \'{0}\''.format(user)) self.write('>> Requires authorization') self.d = defer.Deferred() self.start_auth(redirect) return self.d return None
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_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 menu(self): while True: self.data.load() self.write('** Current configuration:') # Display config data! info = self.data.api self.write('** Bot {0} = {1}'.format('username', info.username)) self.write('** Bot {0} = {1}'.format('owner', self.data.owner)) self.write('** Bot {0} = {1}'.format('trigger', self.data.trigger)) self.write('** Autojoin:') self.write(', '.join(self.data.autojoin)) self.write('') self.write('** Choose one of the following options:') self.write( '*** user - authorize the bot with a different account.') self.write('*** info - Set the bot\'s owner and trigger.') 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', 'user'): ins = get_input('>> ').lower() if ins == 'exit': return if ins == 'all': self.run_all('http://localhost:{0}'.format(self.port)) continue if ins == 'info': self.get_info() self.save() continue if ins == 'autojoin': self.get_autojoin() self.save() if ins == 'user': self.get_user('http://localhost:{0}'.format(self.port)) '''
def menu(self): while True: self.data.load() self.write('** Current configuration:') # Display config data! info = self.data.api self.write('** Bot {0} = {1}'.format('username', info.username)) self.write('** Bot {0} = {1}'.format('owner', self.data.owner)) self.write('** Bot {0} = {1}'.format('trigger', self.data.trigger)) self.write('** Autojoin:') self.write(', '.join(self.data.autojoin)) self.write('') self.write('** Choose one of the following options:') self.write('*** user - authorize the bot with a different account.') self.write('*** info - Set the bot\'s owner and trigger.') 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', 'user'): ins = get_input('>> ').lower() if ins == 'exit': return if ins == 'all': self.run_all('http://localhost:{0}'.format(self.port)) continue if ins == 'info': self.get_info() self.save() continue if ins == 'autojoin': self.get_autojoin() self.save() if ins == 'user': self.get_user('http://localhost:{0}'.format(self.port)) '''
def run(args, restartable=True): args = args[2:].lower() from_menu = False if not args in ('bot', 'debug', 'config', 'exit') or args == 'menu': restartable = False from_menu = True 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 slate import core ret = core.Bot(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 raw_input('>> Press enter to continue...') return if args == 'config': from slate.config import Configure log = ChannelLogger(default_sns=False) c = Configure(reactor, '110', '605c4a06216380fbdff26228c53cf610', agent='slate config', option=1, stdout=log.message, stddebug=log.debug) if c.d is not None: reactor.run() def stop(obj, restartable): try: reactor.stop() except Exception: pass if restartable: run('--menu', False) c.d.addCallback(stop, restartable) reactor.run() return run('--menu', False) return if args == 'exit': return run('--menu', False)
def get_info(self): for option in ['owner', 'trigger']: setattr(self.data, option, get_input('> Bot ' + option + ': '))
def run(args, restartable=True): args = args[2:].lower() from_menu = False if not args in ('bot', 'debug', 'config', 'exit') or args == 'menu': restartable = False from_menu = True 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 slate import core ret = core.Bot(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 raw_input('>> Press enter to continue...') return if args == 'config': from slate.config import Configure log = ChannelLogger(default_sns=False) c=Configure( reactor, '110', '605c4a06216380fbdff26228c53cf610', agent='slate config', option=1, stdout=log.message, stddebug=log.debug ) if c.d is not None: reactor.run() def stop(obj, restartable): try: reactor.stop() except Exception: pass if restartable: run('--menu', False) c.d.addCallback(stop, restartable) reactor.run() return run('--menu', False) return if args == 'exit': return run('--menu', False)