Exemplo n.º 1
0
    def dispatch(self,data):
        origin,data = packets.parse_packet(data)
        packet_id = origin[0]
        #print 'trying to dispatch',hex(packet_id)

        for priority in ('high', 'medium', 'low'): 
            items = self.commands[priority].items()
            for regexp, funcs in items: 
                for func in funcs: 
                    if packet_id not in func.event: continue
                    if regexp is None:
                        func(self,packet_id,data)
                    elif isinstance(data,unicode):
                        text = data
                        #print (origin, text)
                        #print (regexp.pattern)
                        match = regexp.match(text)
                        if match: 
                            #not sure what that limit is about
                            #if self.limit(origin, func): continue

                            phenny = self.wrapped(origin, text, match)
                            input = self.input(origin, text, data, match)

                            if func.thread: 
                                targs = (func, origin, phenny, input)
                                t = threading.Thread(target=self.call, args=targs)
                                t.start()
                            else: self.call(func, origin, phenny, input)
Exemplo n.º 2
0
    def dispatch(self, data):
        origin, data = packets.parse_packet(data)
        packet_id = origin[0]
        #print 'trying to dispatch',hex(packet_id)

        for priority in ('high', 'medium', 'low'):
            items = self.commands[priority].items()
            for regexp, funcs in items:
                for func in funcs:
                    if packet_id not in func.event: continue
                    if regexp is None:
                        func(self, packet_id, data)
                    elif isinstance(data, unicode):
                        text = data
                        #print (origin, text)
                        #print (regexp.pattern)
                        match = regexp.match(text)
                        if match:
                            #not sure what that limit is about
                            #if self.limit(origin, func): continue

                            phenny = self.wrapped(origin, text, match)
                            input = self.input(origin, text, data, match)

                            if func.thread:
                                targs = (func, origin, phenny, input)
                                t = threading.Thread(target=self.call,
                                                     args=targs)
                                t.start()
                            else:
                                self.call(func, origin, phenny, input)
Exemplo n.º 3
0
    def dispatch(self, data):
        self.connection_timeout = time.time()

        origin, data = packets.parse_packet(data)
        packet_id = origin[0]

        for priority in ('high', 'medium', 'low'):
            items = self.commands[priority].items()
            for regexp, funcs in items:
                for func in funcs:
                    if packet_id not in func.event: continue
                    if regexp is None:
                        if func.thread:
                            targs = (func, list(origin), self, list(origin),
                                     data)
                            t = threading.Thread(target=self.call, args=targs)
                            t.start()
                        else:
                            self.call(func, list(origin), self, list(origin),
                                      data)
                    elif isinstance(data, unicode):
                        text = data
                        match = regexp.match(text)
                        if match:

                            input = self.input(list(origin), text, data, match)
                            if input.nick.lower() in self.config.ignore:
                                continue
                            phenny = self.wrapped(list(origin), input, text,
                                                  match)
                            t = time.time()
                            if input.admin or input.nick not in self.cooldowns or\
                                    (input.nick in self.cooldowns \
                                    and \
                                    t - self.cooldowns[input.nick]\
                                    >= self.config.cooldown):
                                self.cooldowns[input.nick] = t
                                if func.thread:
                                    targs = (func, list(origin), phenny, input)
                                    t = threading.Thread(target=self.call,
                                                         args=targs)
                                    t.start()
                                else:
                                    self.call(func, list(origin), phenny,
                                              input)
Exemplo n.º 4
0
    def dispatch(self,data):
        self.connection_timeout = time.time()

        origin,data = packets.parse_packet(data)
        packet_id = origin[0]

        source = normalize_nick(origin[1]).lower() if origin[1] != None and isinstance(origin[1], unicode) else None
        owner = self.config.owner.lower()
        if source == owner and isinstance(data, unicode) and len(data) > 0 and data[0] not in ['!', '.']:
            self.post_to_twitch(data)
        else:
            for priority in ('high', 'medium', 'low'):
                items = self.commands[priority].items()
                for regexp, funcs in items:
                    for func in funcs:
                        if packet_id not in func.event: continue
                        if regexp is None:
                            if func.thread:
                                targs = (func, list(origin), self,list(origin), data)
                                t = threading.Thread(target=self.call, args=targs)
                                t.start()
                            else: self.call(func, list(origin), self, list(origin),data)
                        elif isinstance(data,unicode):
                            text = data
                            match = regexp.match(text)
                            if match:
                                input = self.input(list(origin), text, data, match)
                                if input.nick.lower() in self.config.ignore:
                                    continue
                                phenny = self.wrapped(list(origin), input, text, match)
                                t = time.time()
                                if input.admin or input.nick not in self.cooldowns or\
                                        (input.nick in self.cooldowns \
                                        and \
                                        t - self.cooldowns[input.nick]\
                                        >= self.config.cooldown):
                                    self.cooldowns[input.nick] = t
                                    if func.thread:
                                        targs = (func, list(origin), phenny, input)
                                        t = threading.Thread(target=self.call, args=targs)
                                        t.start()
                                    else: self.call(func, list(origin), phenny, input)