示例#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)