def __init__(self): """Initialize brain class of Sara.""" self.log = logging.getLogger() self.log.info('initialize brain...') self.config = configs.default_obj() if os.path.exists('user.json'): self.config = configs.update(self.config, 'user.json') self.speech = Speech(self.config.speech) self.speech.speak("Load language: " + self.config.language.name[self.config.language.code]) self.phrases = configs.language_obj(self.config.language.languages_dir, self.config.language.code) self.help = Help(self.config.language, self.phrases) self.speech.speak(self.phrases.general.start) self.generals = {'quit': False, 'text': '', 'arg': None} self.bd = Databases(self.config.sqlite) self.assist = Assistant(self.speech, self.config, self.phrases, self.bd) if True if "true" == self.config.general.setup else False: self.assist.setup() self.backups = Backups(self.config.backups, self.bd) self.hotkeys = Hotkeys(self.config.hotkeys, self.generals) self.recognizer = Recognizer(self.config.recognition, self.config.language.code, self.generals, self.speech, self.phrases.recognition)
def __init__(self, device_model_id=None, device_id=None, credentials=None, token=None, dbl_token=None): super(AssistantDiscordBot, self).__init__(command_prefix=None, fetch_offline_members=False) self.dbl_token = dbl_token self.assistant = Assistant(device_model_id=device_model_id, device_id=device_id, credentials=credentials, token=token)
class AssistantDiscordBot(AutoShardedBot): """Responds to Discord User Queries""" def __init__( self, device_model_id=None, device_id=None, credentials=None, token=None, dbl_token=None): super(AssistantDiscordBot, self).__init__( command_prefix=None, fetch_offline_members=False ) self.dbl_token = dbl_token self.assistant = Assistant( device_model_id=device_model_id, device_id=device_id, credentials=credentials, token=token ) async def on_ready(self): print('Logged in as') print(self.user.name) print(self.user.id) print('------') if(self.dbl_token): top_setup(self, self.dbl_token) async def on_message(self, message): if message.author.bot: return lower_content = message.content.lower() # if message does not begin with an invocation prefix if list(filter(lower_content.startswith, INVOCATION_PREFIXES)) == []: return if 'help' in lower_content[:18]: await message.channel.send(HELP_MESSAGE) assistant_response = self.assistant.text_assist(lower_content) if assistant_response: await message.channel.send(assistant_response)
class AssistantDiscordBot(AutoShardedBot): """Responds to Discord User Queries""" def __init__(self, device_model_id=None, device_id=None, credentials=None, token=None, dbl_token=None): super(AssistantDiscordBot, self).__init__(command_prefix=None, fetch_offline_members=False) self.dbl_token = dbl_token self.assistant = Assistant(device_model_id=device_model_id, device_id=device_id, credentials=credentials, token=token) async def on_ready(self): print('Logged in as') print(self.user.name) print(self.user.id) print('------') if (self.dbl_token): top_setup(self, self.dbl_token) async def on_message(self, message): if message.author.bot: return lower_content = message.content.lower() if message.channel.id != '823581709064077373': return assistant_response = self.assistant.text_assist(lower_content) if assistant_response: await message.channel.send(assistant_response)
class Brain: """The brain class of Sara.""" def __init__(self): """Initialize brain class of Sara.""" self.log = logging.getLogger() self.log.info('initialize brain...') self.config = configs.default_obj() if os.path.exists('user.json'): self.config = configs.update(self.config, 'user.json') self.speech = Speech(self.config.speech) self.speech.speak("Load language: " + self.config.language.name[self.config.language.code]) self.phrases = configs.language_obj(self.config.language.languages_dir, self.config.language.code) self.help = Help(self.config.language, self.phrases) self.speech.speak(self.phrases.general.start) self.generals = {'quit': False, 'text': '', 'arg': None} self.bd = Databases(self.config.sqlite) self.assist = Assistant(self.speech, self.config, self.phrases, self.bd) if True if "true" == self.config.general.setup else False: self.assist.setup() self.backups = Backups(self.config.backups, self.bd) self.hotkeys = Hotkeys(self.config.hotkeys, self.generals) self.recognizer = Recognizer(self.config.recognition, self.config.language.code, self.generals, self.speech, self.phrases.recognition) def mainloop(self): """Run main loop method.""" self.log.info('run brain mainloop...') while True: self.recognizer.recognize() if self.generals['quit']: break self.check(self.generals['text']) self.assist.check(self.generals['text'], self.generals['arg']) self.generals['text'] = '' self.generals['arg'] = None time.sleep(0.1) self.quit() def quit(self): """Quit method from Sara.""" self.log.info('quit Sara...') self.speech.speak(self.phrases.general.finish) self.bd.disconnect() self.hotkeys.clear() self.recognizer.finish() def reset(self): """Reset assistant brain of Sara.""" self.log.info('reset assistant...') self.speech.speak(self.phrases.general.reset) self.assist.reset() def check(self, text): """Check need actions for use.""" if 'abort' == text: self.speech.abort() elif 'help' == text: self.help.show_help() elif 'help_browser' == text: self.help.show_browser() elif 'features' == text: self.help.show_features() elif 'backup_bd' == text: self.speech.speak(self.phrases.backup.bd) self.backups.backup_bd() elif 'backup_user_data' == text: self.speech.speak(self.phrases.backup.user_data) self.backups.backup_user_data() elif 'backup_all' == text: self.speech.speak(self.phrases.backup.all) self.backups.backup_all() elif 'restore_bd' == text: self.speech.speak(self.phrases.restore.bd) self.backups.restore_bd() self.reset() elif 'restore_user_data' == text: self.speech.speak(self.phrases.restore.user_data) self.backups.restore_user_data() elif 'restore_all' == text: self.speech.speak(self.phrases.restore.all) self.backups.restore_all() self.reset()