def run(self): while self.running: try: self.check_response_queue() try: event = self.slack._eventq.pop(0) except IndexError: time.sleep(.2) else: self.log.info(u'[SLACK] * %s', event.json) event_type = event.event.get('type', 'unknown') if event_type == 'hello': self.online = True elif self.online: if event_type == 'message': private = False # TODO need to determine if this is in DM req = Request(message=self.fixlinks(event.event['text'])) req.nick = event.event['user'] req.channel = event.event['channel'] req.private = private if private: req.sendto = req.nick req.addressed = True else: req.sendto = req.channel req.addressed = False req.message = decode(req.message) self.check_addressing(req) req.colorize = False self.process_message(req) except KeyboardInterrupt: self.running = False except: self.log.exception('Error in slack event loop')
def process_queue(self): """Process queue""" now = time.time() for mod_name, mod in self.bot.tasks.modules.iteritems(): obj = mod[u'obj'] if (now - self.last_run[mod_name]) < obj.frequency: continue self.last_run[mod_name] = now req = Request() req.sendto = obj.output request = (obj, None, None, {u'req': req}) self.bot.request_queue.put(request)
def run(self): """Runs madcow loop""" while self.running: self.check_response_queue() line = decode(raw_input('>>> '), sys.stdin.encoding).rstrip() req = Request(message=line) req.nick = os.environ['USER'] req.channel = u'none' req.addressed = True req.private = True self.check_addressing(req) self.process_message(req)
def process_message(self): # see if we can reverse lookup sender modules = self.server.bot.modules.modules if 'learn' in modules: dbm = modules['learn']['obj'].get_db('email') for user, email in dbm.iteritems(): if self.hdrs['from'] == email: self.hdrs['from'] = user break if u'payload' in self.hdrs: self.save_payload() if u'message' in self.hdrs: output = u'message from %s: %s' % (self.hdrs[u'from'], self.hdrs[u'message']) req = Request(message=output) req.colorize = False req.sendto = self.hdrs[u'to'] self.server.bot.output(output, req)
def run(self): self.output(u"type 'help' for a list of commands") while self.running: self.check_response_queue() try: input = self.shell.readline(self._prompt) except IOError: # this happens when you get EINTR from SIGHUP handling continue input = decode(input, sys.stdin.encoding) if input.lower() == u'quit': break if input.lower() == u'history': print u'history: %s' % repr(self.shell.history) continue if input.lower() == u'clear': sys.stdout.write(self._clear) continue if len(input) > 0: req = Request(message=input) req.nick = self.user_nick req.channel = u'cli' req.private = True req.addressed = True self.check_addressing(req) if req.message.startswith(u'^'): req.colorize = True req.message = req.message[1:] try: self.user_nick = self._new_nick.search( req.message).group(1) self.output(u'nick changed to: %s' % self.user_nick, req) continue except: pass self.process_message(req)
def run(self): self.output(u"type 'help' for a list of commands") while self.running: self.check_response_queue() try: input = self.shell.readline(self._prompt) except IOError: # this happens when you get EINTR from SIGHUP handling continue input = input.decode(sys.stdin.encoding, 'replace') if input.lower() == u'quit': break if input.lower() == u'history': print u'history: %s' % repr(self.shell.history) continue if input.lower() == u'clear': sys.stdout.write(self._clear) continue if len(input) > 0: req = Request(message=input) req.nick = self.user_nick req.channel = u'cli' req.private = True req.addressed = True self.check_addressing(req) if req.message.startswith(u'^'): req.colorize = True req.message = req.message[1:] try: self.user_nick = self._new_nick.search(req.message).group(1) self.output(u'nick changed to: %s' % self.user_nick, req) continue except: pass self.process_message(req)