def input(self, data): try: if data.get('username') == 'slackbot': return user = data.get('user') or data.get('message', {}).get('user') if user == self.uuid: return kind = data.get('type') if kind == 'message': ch = data.get('channel') text = data.get('text', '').lower() direct = channels.ChannelsDal.is_direct(ch) mention = text.startswith('jarvis') if direct or mention: self.handle_message(ch, text, user) return if kind in ('team_join', 'user_change'): if user['is_bot']: return user = helper.get_user_fields(self.slack, user) users.UsersDal.update(*user) return except Exception: logger.error('Error handling message %s', str(data)) sentry.captureException() raise
def init(self): logger.debug('Initializing database...') schema.initialize() logger.debug('Initializing plugins...') for name in sorted(os.listdir('/plugins')): plugin = importlib.machinery.SourceFileLoader( name, '/plugins/{}/__init__.py'.format(name)).load_module() plugin = getattr(plugin, plugin.__all__[0])(self.slack) plugin.initialize() logger.debug('Initializing users...') user_list = self.slack.api_call('users.list') for user in user_list['members']: if user['deleted']: continue if user['is_bot'] or user['id'] == 'USLACKBOT': continue user = helper.get_user_fields(self.slack, user) users.UsersDal.create(*user) c = helper.get_channel_or_fail(logger, self.slack, user[-1]) c.send_message(messages.GREET_USER(user))
def init(self): schema.initialize() user_list = self.slack.api_call('users.list') for user in user_list['members']: if user['deleted']: continue if user['is_bot'] or user['id'] == 'USLACKBOT': continue user = helper.get_user_fields(self.slack, user) users.UsersDal.create(*user)
def input(self, data): user = data.get('user') if user == self.uuid: return kind = data.get('type') if kind == 'message': ch = data.get('channel') text = data.get('text', '').lower() if channels.ChannelsDal.is_direct(ch) or text.startswith('jarvis'): self.handle_message(ch, text, user) return if kind in ('team_join', 'user_change'): user = helper.get_user_fields(self.slack, user) users.UsersDal.update(*user) return