Exemple #1
0
    def log(self, text):

        if self.config.get('log', False):

            self.say(self.config['log'], text)

        print(style.remove(text))
Exemple #2
0
    def parse_loop(self):
        while self.connected:
            msg = self.iqueue.get()

            if msg == StopIteration:
                self.connect()
                continue

            if self.debug and msg: print(msg)

            regex = re.compile(
                r'(?::(([^@! ]+)!?([^@ ]+)?@?([^ ]+)?))? ?([^ ]+) ?([^: ]*) :?(.*)?'
            )

            try:
                prefix, nick, ident, host, type, chan, message = re.findall(
                    regex, msg)[0]

            except:
                continue

            message = style.remove(message)

            params = re.findall(r'(?<=")\w[^"]+(?=")|[^" ]+', message)

            # do response waiting
            for waiting in self.waiting:
                if type in waiting['keys']:
                    if waiting['prefix'] and not self.match(
                            waiting['prefix'], prefix):
                        continue
                    if waiting['chan'] and not self.match(
                            waiting['chan'], chan):
                        continue
                    if waiting['message'] and not self.match(
                            waiting['message'], message):
                        continue

                    waiting['values'].append([(nick, ident, host), chan,
                                              params])

                    if type not in waiting['end']: break

                if type in waiting['end'] and waiting['values']:
                    self.waiting.remove(waiting)

                    break

            # do events

            if type in self.events:
                for func in self.events[type]:
                    # must be performed in specific channel
                    if hasattr(func, '_channel'):
                        if getattr(func, '_channel') != chan:
                            continue

                    self.thread(func, ((nick, ident, host), chan, params))

            # do commands
            if type == 'PRIVMSG' and params and params[0].startswith(
                    self.config.get('prefix', '$')):
                command = params[0][1:]

                params.pop(0)

                ignore = self.config.get('ignore', [])

                if command in self.commands and not self.match(ignore, prefix):
                    if chan != self.config.get('log'):
                        self.log('%s %s called by %s in %s (%s)' %
                                 (style.color('Command:', style.GREEN),
                                  command, nick, chan, ', '.join(params)))

                    if chan == self.nick:
                        chan = nick

                    for func in self.commands[command]:
                        self.thread(
                            self.command,
                            (func, chan, prefix, nick, ident, host, params))

        print('Exited parse loop.')
Exemple #3
0
    def parse_loop(self):

        while self.connected:
            msg = self.iqueue.get()

            if msg == StopIteration:
                self.connect()

                continue

            if self.debug and msg: print(msg)

            regex = re.compile(r'(?::(([^@! ]+)!?([^@ ]+)?@?([^ ]+)?))? ?([^ ]+) ?([^: ]*) :?(.*)?')

            try:
                prefix, nick, ident, host, type, chan, message = re.findall(regex, msg)[0]

            except: continue

            message = style.remove(message)

            params = re.findall(r'(?<=")\w[^"]+(?=")|[^" ]+', message)

            # do events

            if type in self.events:
                for func in self.events[type]:

                    # must be performed in specific channel

                    if hasattr(func, '_channel'):
                        if getattr(func, '_channel') != chan:
                            continue

                    self.thread(func, ((nick, ident, host), chan, params))

            # do commands

            if type == 'PRIVMSG' and params and params[0].startswith(self.config.get('prefix', '$')):
                command = params[0][1:]

                params.pop(0)

                ignore = self.config.get('ignore', [])

                if command in self.commands and not self.match(ignore, prefix):

                    if chan != self.config.get('log'):

                        self.log('%s %s called by %s in %s (%s)' % (
                            style.color('Command:', style.GREEN),
                            command,
                            nick,
                            chan,
                            ', '.join(params)
                            ))

                    if chan == self.nick:
                        chan = nick

                    for func in self.commands[command]:

                        # must or must not be a PM

                        if hasattr(func, '_pm'):
                            if getattr(func, '_pm'):
                                if chan.startswith('#'):
                                    continue

                            elif not chan.startswith('#'):
                                continue

                        # must be performed in specific channel

                        if hasattr(func, '_channel'):
                            if getattr(func, '_channel') != chan:
                                continue

                        # command can or must be diverted

                        where = chan

                        divert = self.config.get('divert', {})

                        if hasattr(func, '_divert'):
                            if chan in divert:
                                where = divert[chan]

                            if where not in self.chans:
                                continue

                        if hasattr(func, '_control'):
                            if not chan in divert or where not in self.chans:
                                continue

                        # admin perm overrides all

                        admin = self.config['perms'].get('admin', {})

                        if self.match(admin, prefix):
                            pass

                        # user must have permission, overrides flags

                        elif hasattr(func, '_perm'):
                            perm = getattr(func, '_perm')

                            if perm not in self.config['perms']:
                                continue

                            if not self.match(self.config['perms'][perm], prefix):
                                continue

                        # user must have specific flag(s)

                        elif hasattr(func, '_flags'):
                            self.perms_check.append({
                                'nick': nick,
                                'func': func,
                                'perm': getattr(func, '_flags'),
                                'chan': where,
                                'args': ((nick, ident, host), where, params)
                            })

                            self.do('WHO', where)

                            continue

                        self.thread(func, args=((nick, ident, host), where, params))

        print('Exited parse loop.')
Exemple #4
0
    def parse_loop(self):
        while self.connected:
            msg = self.iqueue.get()

            if msg == StopIteration:
                self.connect()
                continue

            if self.debug and msg: print(msg)

            regex = re.compile(r'(?::(([^@! ]+)!?([^@ ]+)?@?([^ ]+)?))? ?([^ ]+) ?([^: ]*) :?(.*)?')

            try:
                prefix, nick, ident, host, type, chan, message = re.findall(regex, msg)[0]

            except: continue

            message = style.remove(message)

            params = re.findall(r'(?<=")\w[^"]+(?=")|[^" ]+', message)

            # do response waiting
            for waiting in self.waiting:
                if type in waiting['keys']:
                    if waiting['prefix'] and not self.match(waiting['prefix'], prefix):
                        continue
                    if waiting['chan'] and not self.match(waiting['chan'], chan):
                        continue
                    if waiting['message'] and not self.match(waiting['message'], message):
                        continue

                    waiting['values'].append([(nick, ident, host), chan, params])

                    if type not in waiting['end']: break

                if type in waiting['end'] and waiting['values']:
                    self.waiting.remove(waiting)

                    break

            # do events

            if type in self.events:
                for func in self.events[type]:
                    # must be performed in specific channel
                    if hasattr(func, '_channel'):
                        if getattr(func, '_channel') != chan:
                            continue

                    self.thread(func, ((nick, ident, host), chan, params))

            # do commands
            if type == 'PRIVMSG' and params and params[0].startswith(self.config.get('prefix', '$')):
                command = params[0][1:]

                params.pop(0)

                ignore = self.config.get('ignore', [])

                if command in self.commands and not self.match(ignore, prefix):
                    if chan != self.config.get('log'):
                        self.log('%s %s called by %s in %s (%s)' % (
                            style.color('Command:', style.GREEN),
                            command,
                            nick,
                            chan,
                            ', '.join(params)
                            ))

                    if chan == self.nick:
                        chan = nick

                    for func in self.commands[command]:
                        self.thread(self.command, (func, chan, prefix, nick, ident, host, params))

        print('Exited parse loop.')