Esempio n. 1
0
    def irc_KICK(self, prefix, params):
      '''Calleed when a user is kicked
      '''
      # Start building a kick dict
      kickd = {}

      kickee = params[1] 
      if kickee in self._clientd[params[0]]:
          user, host = self._clientd[params[0]][kickee]
          kickee = '{}!~{}@{}'.format(kickee, user, host)

      kickd[u'ts'] = int(time.time())
      kickd[u'channel'] = params[0]
      kickd.update(ui.parse_client_name(kickee, safe=True))
      kickd.update(ui.find_ip_info(kickd[u'host']))

      kickd[u'event'] = { u'type': u'kick'
                        , u'by': ui.parse_client_name(prefix)
                        , u'reason': params[-1]
                        }

      if params[1] in self._clientd[params[0]]:
          del self._clientd[params[0]][params[1]]

      # Add the kickd to the queue
      self.q.put(kickd)

      # Dutiful logging
      if self.logging:
          log.msg('kickd: {}'.format(kickd))
          log.msg('KICK prefix: {} with params {}'.format(prefix, params))

      # See if we've been kicked
      if params[1].lower() == self.nickname.lower():
          self.kickedFrom(params[0], prefix.split('!')[0], params[-1])
Esempio n. 2
0
def parse_mode(line):
    '''
    '''
    #print('Mode line: {}'.format(line))
    m = MODE_RE.search(line)
    if m is None:
        m = MODE_RE2.search(line)
    gd = m.groupdict()
    if 'plus' in gd:
        args = gd['args'].split()
        pluses = [gd['plus'] == '+' for _ in range(len(args))]
        flags = gd['flags']
    else:
        allm = gd['all'].split()
        prev_plus = None
        pluses = []
        for plus in allm[0]:
            if plus in '+-':
                prev_plus = plus
            else:
                pluses.append(prev_plus)
        flags = filter(str.isalpha, allm[0])
        args = allm[1:]

    modeds = []
    for i, flag in enumerate(flags):
        if flag not in ('b', 'o', 'q', 'v'):
            continue

        moded = {}
        try:
            moded.update(ui.parse_client_name(args[i]))
        except AttributeError:
            moded[u'nick'] = args[i]
            moded[u'user'] = u''
            moded[u'host'] = u''

        try:
            by = ui.parse_client_name(gd['by'])
        except AttributeError:
            by = { u'nick': gd['by']
                 , u'user': u''
                 , u'host': u''
                 }

        moded[u'event'] = { u'type': u'mode'
                          , u'plus': pluses[i]
                          , u'by': by
                          , u'flag': flag
                          }
        modeds.append(moded)

    return modeds
Esempio n. 3
0
def parse_mode(line):
    '''
    '''
    #print('Mode line: {}'.format(line))
    m = MODE_RE.search(line)
    if m is None:
        m = MODE_RE2.search(line)
    gd = m.groupdict()
    if 'plus' in gd:
        args = gd['args'].split()
        pluses = [gd['plus'] == '+' for _ in range(len(args))]
        flags = gd['flags']
    else:
        allm = gd['all'].split()
        prev_plus = None
        pluses = []
        for plus in allm[0]:
            if plus in '+-':
                prev_plus = plus
            else:
                pluses.append(prev_plus)
        flags = filter(str.isalpha, allm[0])
        args = allm[1:]

    modeds = []
    for i, flag in enumerate(flags):
        if flag not in ('b', 'o', 'q', 'v'):
            continue

        moded = {}
        try:
            moded.update(ui.parse_client_name(args[i]))
        except AttributeError:
            moded[u'nick'] = args[i]
            moded[u'user'] = u''
            moded[u'host'] = u''

        try:
            by = ui.parse_client_name(gd['by'])
        except AttributeError:
            by = {u'nick': gd['by'], u'user': u'', u'host': u''}

        moded[u'event'] = {
            u'type': u'mode',
            u'plus': pluses[i],
            u'by': by,
            u'flag': flag
        }
        modeds.append(moded)

    return modeds
Esempio n. 4
0
    def modeChanged(self, user, channel, mset, modes, args):
        '''Called when users or channel modes are changed
        '''
        # Don't want any pure channel modes which
        # don't take any arguments in the IRC RFC
        if None in args:
            return

        for arg in args:
            # Don't want modes set on a channel
            if re.match('[&#+!]', arg) is not None:
                return

        # Need a list of mode dicts
        modeds = []

        for i, mode in enumerate(modes):
            # Check for the flags we care about
            if mode not in ('b', 'o', 'q', 'v'):
                continue

            # Build a mode dict
            moded = {}

            moded[u'ts'] = int(time.time())
            moded[u'channel'] = channel
            if args[i] in self._clientd[channel]:
                u, h = self._clientd[channel][args[i]]
                client_name = u'{}!~{}@{}'.format(args[i], u, h)
            else:
                client_name = args[i]
            moded.update(ui.parse_client_name(client_name, safe=True))
            moded.update(ui.find_ip_info(moded[u'host']))

            moded[u'event'] = {
                u'type': u'mode',
                u'plus': mset,
                u'by': ui.parse_client_name(user),
                u'flag': mode
            }
            modeds.append(moded)
            if self.logging:
                log.msg('moded: {}'.format(moded))

        # Added the modeds to the queue
        self.q.put(modeds)

        if self.logging:
            log.msg('User {} in {} has {}{} set with args {}'.\
                    format(user, channel, '+' if mset else '-', modes, args))
Esempio n. 5
0
    def modeChanged(self, user, channel, mset, modes, args):
        '''Called when users or channel modes are changed
        '''
        # Don't want any pure channel modes which
        # don't take any arguments in the IRC RFC
        if None in args:
            return

        for arg in args:
            # Don't want modes set on a channel
            if re.match('[&#+!]', arg) is not None:
                return

        # Need a list of mode dicts
        modeds = []

        for i, mode in enumerate(modes):
            # Check for the flags we care about
            if mode not in ('b', 'o', 'q', 'v'):
                continue 

            # Build a mode dict
            moded = {}

            moded[u'ts'] = int(time.time())
            moded[u'channel'] = channel
            if args[i] in self._clientd[channel]:
                u, h = self._clientd[channel][args[i]]
                client_name = u'{}!~{}@{}'.format(args[i], u, h)
            else:
                client_name = args[i]
            moded.update(ui.parse_client_name(client_name, safe=True))
            moded.update(ui.find_ip_info(moded[u'host']))

            moded[u'event'] = { u'type': u'mode'
                              , u'plus': mset
                              , u'by': ui.parse_client_name(user)
                              , u'flag': mode
                              }
            modeds.append(moded) 
            if self.logging:
                log.msg('moded: {}'.format(moded))

        # Added the modeds to the queue
        self.q.put(modeds)

        if self.logging:
            log.msg('User {} in {} has {}{} set with args {}'.\
                    format(user, channel, '+' if mset else '-', modes, args))
Esempio n. 6
0
def parse_kick(line):
    '''
    '''
    #print('Kick line: {}'.format(line))
    m = KICK_ALL_RE.search(line)
    gd = m.groupdict()

    kickd = {}
    kickd[u'nick'] = gd['nick']
    kickd[u'user'] = u''
    kickd[u'host'] = u''

    try:
        by = ui.parse_client_name(gd['by'])
    except AttributeError:
        by = { u'nick': gd['by']
             , u'user': u''
             , u'host': u''
             }

    kickd[u'event'] = { u'type': u'kick'
                      , u'by': by
                      , u'reason': gd['reason']
                      }
    return kickd
Esempio n. 7
0
    def irc_QUIT(self, prefix, params):
      '''Called when a user quits
      '''
      # Start building a quit dict
      quitd = {}

      quitd[u'ts'] = int(time.time())
      quitd[u'channel'] = u''   # Applies to every channel the client is on
      quitd.update(ui.parse_client_name(prefix))
      quitd.update(ui.find_ip_info(quitd[u'host']))

      quitd[u'event'] = { u'type': u'quit'
                        , u'reason': params[-1]
                        }

      for channel in self._clientd:
          if quitd[u'nick'] in self._clientd[channel]:
              del self._clientd[channel][quitd[u'nick']]

      # Add the quitd to the queue
      self.q.put(quitd)

      if self.logging:
          log.msg('quitd: {}'.format(quitd))
          log.msg('QUIT prefix: {} with params: {}'.format(prefix, params))
Esempio n. 8
0
    def irc_NICK(self, prefix, params):
      '''Called when a nick change is made.
      '''
      # Start building a nick dict
      nickd = {}

      nickd[u'ts'] = int(time.time())
      nickd[u'channel'] = '' # Applies to every channel the client is on
      nickd.update(ui.parse_client_name(prefix))
      nickd.update(ui.find_ip_info(nickd[u'host']))

      nickd[u'event'] = { u'type': u'rename'
                        , u'newname': params[0]
                        }

      # Update the client dict
      for channel in self._clientd:
        if nickd[u'nick'] in self._clientd[channel]:
            self._clientd[channel][params[0]] = self._clientd[channel][nickd[u'nick']]
            del self._clientd[channel][nickd[u'nick']]

      # Add the nickd to the queue
      self.q.put(nickd)

      if self.logging:
          log.msg('nickd: {}'.format(nickd))
          log.msg('NICK prefix: {} with params {}'.format(prefix, params))
Esempio n. 9
0
    def irc_JOIN(self, prefix, params):
      '''Called when a user joins a channel
      '''
      # Start building a join dict
      joind = {}

      joind[u'ts'] = int(time.time())
      joind[u'channel'] = params[0]

      joind.update(ui.parse_client_name(prefix))
      joind.update(ui.find_ip_info(joind[u'host']))

      joind[u'event'] = { u'type': u'join' }

      # Store this user's mapping based on channel
      if not joind[u'channel'] in self._clientd:
          self._clientd[joind[u'channel']] = {}
      self._clientd[joind[u'channel']][joind[u'nick']] = \
                                (joind[u'user'], joind[u'host'])

      # Put the joind on the queue
      self.q.put(joind)

      if self.logging:
          log.msg('joind: {}'.format(joind))
          log.msg('JOIN prefix: {} with params {}'.format(prefix, params))
Esempio n. 10
0
    def irc_NICK(self, prefix, params):
        '''Called when a nick change is made.
      '''
        # Start building a nick dict
        nickd = {}

        nickd[u'ts'] = int(time.time())
        nickd[u'channel'] = ''  # Applies to every channel the client is on
        nickd.update(ui.parse_client_name(prefix))
        nickd.update(ui.find_ip_info(nickd[u'host']))

        nickd[u'event'] = {u'type': u'rename', u'newname': params[0]}

        # Update the client dict
        for channel in self._clientd:
            if nickd[u'nick'] in self._clientd[channel]:
                self._clientd[channel][params[0]] = self._clientd[channel][
                    nickd[u'nick']]
                del self._clientd[channel][nickd[u'nick']]

        # Add the nickd to the queue
        self.q.put(nickd)

        if self.logging:
            log.msg('nickd: {}'.format(nickd))
            log.msg('NICK prefix: {} with params {}'.format(prefix, params))
Esempio n. 11
0
    def irc_JOIN(self, prefix, params):
        '''Called when a user joins a channel
      '''
        # Start building a join dict
        joind = {}

        joind[u'ts'] = int(time.time())
        joind[u'channel'] = params[0]

        joind.update(ui.parse_client_name(prefix))
        joind.update(ui.find_ip_info(joind[u'host']))

        joind[u'event'] = {u'type': u'join'}

        # Store this user's mapping based on channel
        if not joind[u'channel'] in self._clientd:
            self._clientd[joind[u'channel']] = {}
        self._clientd[joind[u'channel']][joind[u'nick']] = \
                                  (joind[u'user'], joind[u'host'])

        # Put the joind on the queue
        self.q.put(joind)

        if self.logging:
            log.msg('joind: {}'.format(joind))
            log.msg('JOIN prefix: {} with params {}'.format(prefix, params))
Esempio n. 12
0
    def irc_KICK(self, prefix, params):
        '''Calleed when a user is kicked
      '''
        # Start building a kick dict
        kickd = {}

        kickee = params[1]
        if kickee in self._clientd[params[0]]:
            user, host = self._clientd[params[0]][kickee]
            kickee = '{}!~{}@{}'.format(kickee, user, host)

        kickd[u'ts'] = int(time.time())
        kickd[u'channel'] = params[0]
        kickd.update(ui.parse_client_name(kickee, safe=True))
        kickd.update(ui.find_ip_info(kickd[u'host']))

        kickd[u'event'] = {
            u'type': u'kick',
            u'by': ui.parse_client_name(prefix),
            u'reason': params[-1]
        }

        if params[1] in self._clientd[params[0]]:
            del self._clientd[params[0]][params[1]]

        # Add the kickd to the queue
        self.q.put(kickd)

        # Dutiful logging
        if self.logging:
            log.msg('kickd: {}'.format(kickd))
            log.msg('KICK prefix: {} with params {}'.format(prefix, params))

        # See if we've been kicked
        if params[1].lower() == self.nickname.lower():
            self.kickedFrom(params[0], prefix.split('!')[0], params[-1])
Esempio n. 13
0
def parse_kick(line):
    '''
    '''
    #print('Kick line: {}'.format(line))
    m = KICK_ALL_RE.search(line)
    gd = m.groupdict()

    kickd = {}
    kickd[u'nick'] = gd['nick']
    kickd[u'user'] = u''
    kickd[u'host'] = u''

    try:
        by = ui.parse_client_name(gd['by'])
    except AttributeError:
        by = {u'nick': gd['by'], u'user': u'', u'host': u''}

    kickd[u'event'] = {u'type': u'kick', u'by': by, u'reason': gd['reason']}
    return kickd
Esempio n. 14
0
    def irc_PART(self, prefix, params):
        '''Called when a part message is sent
      '''
        # Start building a part dict
        partd = {}

        partd[u'ts'] = int(time.time())
        partd[u'channel'] = params[0]
        partd.update(ui.parse_client_name(prefix))
        partd.update(ui.find_ip_info(partd[u'host']))

        partd[u'event'] = {u'type': u'part', u'reason': params[-1]}

        if partd[u'nick'] in self._clientd[params[0]]:
            del self._clientd[params[0]][partd[u'nick']]

        # Add the partd to the queue
        self.q.put(partd)

        if self.logging:
            log.msg('partd: {}'.format(partd))
            log.msg('PART prefix: {} with params {}'.format(prefix, params))
Esempio n. 15
0
    def irc_QUIT(self, prefix, params):
        '''Called when a user quits
      '''
        # Start building a quit dict
        quitd = {}

        quitd[u'ts'] = int(time.time())
        quitd[u'channel'] = u''  # Applies to every channel the client is on
        quitd.update(ui.parse_client_name(prefix))
        quitd.update(ui.find_ip_info(quitd[u'host']))

        quitd[u'event'] = {u'type': u'quit', u'reason': params[-1]}

        for channel in self._clientd:
            if quitd[u'nick'] in self._clientd[channel]:
                del self._clientd[channel][quitd[u'nick']]

        # Add the quitd to the queue
        self.q.put(quitd)

        if self.logging:
            log.msg('quitd: {}'.format(quitd))
            log.msg('QUIT prefix: {} with params: {}'.format(prefix, params))
Esempio n. 16
0
    def irc_PART(self, prefix, params):
      '''Called when a part message is sent
      '''
      # Start building a part dict
      partd = {}

      partd[u'ts'] = int(time.time())
      partd[u'channel'] = params[0]
      partd.update(ui.parse_client_name(prefix))
      partd.update(ui.find_ip_info(partd[u'host']))

      partd[u'event'] = { u'type': u'part'
                        , u'reason': params[-1]
                        }

      if partd[u'nick'] in self._clientd[params[0]]:
          del self._clientd[params[0]][partd[u'nick']]

      # Add the partd to the queue
      self.q.put(partd)

      if self.logging:
          log.msg('partd: {}'.format(partd))
          log.msg('PART prefix: {} with params {}'.format(prefix, params))