Ejemplo n.º 1
0
 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')
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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 = 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)
Ejemplo n.º 5
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)