예제 #1
0
파일: slack.py 프로젝트: cjones/madcow
 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')
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
파일: gateway.py 프로젝트: Havvy/madcow
    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)
예제 #6
0
    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)
예제 #7
0
파일: cli.py 프로젝트: seunboi4u/madcow
    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)
예제 #8
0
 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)
예제 #9
0
    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)