Ejemplo n.º 1
0
    def irc_PART(self, prefix, params):
        """
		Called when a user leaves a channel.
		"""
        nick, ident, host = processHostmask(prefix)
        channel = params[0]
        if nick == self.nickname:
            # take note of our prefix! (for message length calculation
            self.prefixlen = len(prefix)
            if self.state: self.state._leavechannel(channel)
            self.dispatch(self,
                          "left",
                          prefix=prefix,
                          params=params,
                          hostmask=prefix,
                          target=channel,
                          nick=nick,
                          ident=ident,
                          host=host)
        else:
            if self.state:
                self.state._userpart(channel, nick, ident, host, prefix)
            self.dispatch(self,
                          "userLeft",
                          prefix=prefix,
                          params=params,
                          hostmask=prefix,
                          target=channel,
                          nick=nick,
                          ident=ident,
                          host=host)
Ejemplo n.º 2
0
	def irc_MODE(self, prefix, params):
		"""
		Parse a server mode change message.
		"""
		channel, modes, args = params[0], params[1], params[2:]

		if modes[0] not in '-+':
			modes = '+' + modes

		if channel == self.nickname:
			# This is a mode change to our individual user, not a channel mode
			# that involves us.
			paramModes = self.getUserModeParams()
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
		else:
			paramModes = self.getChannelModeParams()

		try:
			added, removed = parseModes(modes, args, paramModes)
		except IRCBadModes:
			log.err(None, 'An error occured while parsing the following '
						  'MODE message: MODE %s' % (' '.join(params),))
		else:
			nick, ident, host = processHostmask(prefix)
			if self.state and (channel != self.nickname):
				self.state._modechange(channel, nick, added, removed)
			self.dispatch(self, "modeChanged", prefix=prefix, params=params, hostmask=prefix, target=channel,
				added=added, removed=removed, modes=modes, args=args, nick=nick, ident=ident, host=host)
Ejemplo n.º 3
0
	def irc_MODE(self, prefix, params):
		"""
		Parse a server mode change message.
		"""
		channel, modes, args = params[0], params[1], params[2:]

		if modes[0] not in '-+':
			modes = '+' + modes

		if channel == self.nickname:
			# This is a mode change to our individual user, not a channel mode
			# that involves us.
			paramModes = self.getUserModeParams()
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
		else:
			paramModes = self.getChannelModeParams()

		try:
			added, removed = parseModes(modes, args, paramModes)
		except IRCBadModes:
			log.err(None, 'An error occured while parsing the following '
						  'MODE message: MODE %s' % (' '.join(params),))
		else:
			nick, ident, host = processHostmask(prefix)
			if self.state and (channel != self.nickname):
				self.state._modechange(channel, nick, added, removed)
			self.dispatch(self, "modeChanged", prefix=prefix, params=params, hostmask=prefix, target=channel,
				added=added, removed=removed, modes=modes, args=args, nick=nick, ident=ident, host=host)
Ejemplo n.º 4
0
	def irc_PRIVMSG(self, prefix, params):
		"""
		Called when we get a message.
		"""
		user = prefix
		channel = params[0]
		message = params[-1]

		if not message:
			# Don't raise an exception if we get blank message.
			return

		if message[0] == X_DELIM:
			m = ctcpExtract(message)
			if m['extended']:
				self.ctcpQuery(user, channel, m['extended'], params)

			if not m['normal']:
				return

			message = ' '.join(m['normal'])
		
		nick, ident, host = processHostmask(prefix)
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
		# These are actually messages, ctcp's aren't dispatched here
		self.dispatch(self, "privmsged", prefix=prefix, params=params, hostmask=user, target=channel, msg=message, 
			nick=nick, ident=ident, host=host)
Ejemplo n.º 5
0
    def ctcpReply(self, user, channel, messages, params):
        """
		Dispatch method for any CTCP replies received.
		Duplicate tags ignored.
		Override from IRCClient
		"""
        seen = set()
        nick, ident, host = processHostmask(user)
        ###
        # Commented because the prefix variable here will throw a NameError
        # and not sure how to fix
        ###
        # if nick == self.nickname:
        # take note of our prefix! (for message length calculation
        # self.prefixlen = len(prefix)
        for tag, data in messages:
            if tag not in seen:
                #dispatch event
                self.dispatch(self,
                              "ctcpReply",
                              prefix=user,
                              params=params,
                              hostmask=user,
                              target=channel,
                              tag=tag,
                              data=data,
                              nick=nick,
                              ident=ident,
                              host=host)
            seen.add(tag)
Ejemplo n.º 6
0
    def ctcpQuery(self, user, channel, messages, params):
        """
		Dispatch method for any CTCP queries received.
		Duplicate tags ignored.
		Override from IRCClient
		"""
        seen = set()
        nick, ident, host = processHostmask(user)
        if nick == self.nickname:
            # take note of our prefix! (for message length calculation
            self.prefixlen = len(prefix)
        for tag, data in messages:
            if tag not in seen:
                #dispatch event
                self.dispatch(self,
                              "ctcpQuery",
                              prefix=user,
                              params=params,
                              hostmask=user,
                              target=channel,
                              tag=tag,
                              data=data,
                              nick=nick,
                              ident=ident,
                              host=host)
                #call handler if defined:
                method = getattr(self, 'ctcpQueryB_%s' % tag, None)
                if method is not None: method(user, channel, data)
                else: self.ctcp_unknownQuery(user, channel, tag, data)
            seen.add(tag)
Ejemplo n.º 7
0
    def irc_NICK(self, prefix, params):
        """
		Called when a user changes their nickname.
		"""
        nick, ident, host = processHostmask(prefix)

        if nick == self.nickname:
            # take note of our prefix! (for message length calculation
            self.prefixlen = len(prefix)
            self.nickChanged(params[0])
            self.dispatch(self,
                          "nickChanged",
                          prefix=prefix,
                          params=params,
                          hostmask=prefix,
                          newname=params[0])
        else:
            if self.state:
                self.state._userrename(nick, params[0], ident, host, prefix)
            self.dispatch(self,
                          "userRenamed",
                          prefix=prefix,
                          params=params,
                          hostmask=prefix,
                          newname=params[0],
                          nick=nick,
                          ident=ident,
                          host=host)
Ejemplo n.º 8
0
    def irc_NOTICE(self, prefix, params):
        """
		Called when a user gets a notice.
		"""
        if self.debug >= 2: print "INCOMING NOTICE:", prefix, params
        user = prefix
        channel = params[0]
        message = params[-1]

        if message[0] == X_DELIM:
            m = ctcpExtract(message)
            if m['extended']:
                self.ctcpReply(user, channel, m['extended'], params)
            if not m['normal']:
                return
            message = ' '.join(m['normal'])

        nick, ident, host = processHostmask(prefix)
        if nick == self.nickname:
            # take note of our prefix! (for message length calculation
            self.prefixlen = len(prefix)
        self.dispatch(self,
                      "noticed",
                      prefix=prefix,
                      params=params,
                      hostmask=user,
                      target=channel,
                      msg=message,
                      nick=nick,
                      ident=ident,
                      host=host)
Ejemplo n.º 9
0
	def irc_PRIVMSG(self, prefix, params):
		"""
		Called when we get a message.
		"""
		if self.debug >= 2: print "INCOMING PRIVMSG:", prefix, params
		user = prefix
		channel = params[0]
		message = params[-1]
		if not message:
			# Don't raise an exception if we get blank message.
			return

		if message[0] == X_DELIM:
			m = ctcpExtract(message)
			if m['extended']:
				self.ctcpQuery(user, channel, m['extended'], params)

			if not m['normal']:
				return

			message = ' '.join(m['normal'])
		
		nick, ident, host = processHostmask(prefix)
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
		# These are actually messages, ctcp's aren't dispatched here
		self.dispatch(self, "privmsged", prefix=prefix, params=params, hostmask=user, target=channel, msg=message, 
			nick=nick, ident=ident, host=host)
Ejemplo n.º 10
0
    def irc_JOIN(self, prefix, params):
        """
		Called when a user joins a channel.
		"""
        nick, ident, host = processHostmask(prefix)
        channel = params[-1]
        if nick == self.nickname:
            # take note of our prefix! (for message length calculation
            self.prefixlen = len(prefix)
            if self.state:
                self.state._joinchannel(channel)
                self.sendLine("MODE %s" % channel)
            self.dispatch(self,
                          "joined",
                          prefix=prefix,
                          params=params,
                          hostmask=prefix,
                          target=channel,
                          nick=nick,
                          ident=ident,
                          host=host)
        else:
            if self.state:
                self.state._userjoin(channel, nick, ident, host, prefix)
            self.dispatch(self,
                          "userJoined",
                          prefix=prefix,
                          params=params,
                          hostmask=prefix,
                          target=channel,
                          nick=nick,
                          ident=ident,
                          host=host)
Ejemplo n.º 11
0
	def irc_QUIT(self, prefix, params):
		"""
		Called when a user has quit.
		"""
		nick, ident, host = processHostmask(prefix)
		if self.state: self.state._userquit(nick)
		self.dispatch(self, "userQuit", prefix=prefix, params=params, hostmask=prefix, msg=params[0], 
			nick=nick, ident=ident, host=host)
Ejemplo n.º 12
0
	def irc_QUIT(self, prefix, params):
		"""
		Called when a user has quit.
		"""
		nick, ident, host = processHostmask(prefix)
		if self.state: self.state._userquit(nick)
		self.dispatch(self, "userQuit", prefix=prefix, params=params, hostmask=prefix, msg=params[0], 
			nick=nick, ident=ident, host=host)
Ejemplo n.º 13
0
	def irc_RPL_NOTOPIC(self, prefix, params):
		"""
		...
		"""
		nick, ident, host = processHostmask(prefix)
		channel = params[1]
		newtopic = ""
		if self.state: self.state._settopic(channel, newtopic, nick, ident, host)
		self.dispatch(self, "topicUpdated", prefix=prefix, params=params, hostmask=prefix, target=channel, newtopic=newtopic, 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 14
0
	def irc_RPL_NOTOPIC(self, prefix, params):
		"""
		...
		"""
		nick, ident, host = processHostmask(prefix)
		channel = params[1]
		newtopic = ""
		if self.state: self.state._settopic(channel, newtopic, nick, ident, host)
		self.dispatch(self, "topicUpdated", prefix=prefix, params=params, hostmask=prefix, target=channel, newtopic=newtopic, 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 15
0
	def irc_RPL_TOPIC(self, prefix, params):
		"""
		Called when the topic for a channel is initially reported or when it
		subsequently changes.
		"""
		nick, ident, host = processHostmask(prefix)
		channel = params[1]
		newtopic = params[2]
		
		if self.state: self.state._settopic(channel, newtopic, nick, ident, host)
		self.dispatch(self, "topicUpdated", prefix=prefix, params=params, hostmask=prefix, target=channel, newtopic=newtopic, 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 16
0
	def irc_RPL_TOPIC(self, prefix, params):
		"""
		Called when the topic for a channel is initially reported or when it
		subsequently changes.
		"""
		nick, ident, host = processHostmask(prefix)
		channel = params[1]
		newtopic = params[2]
		
		if self.state: self.state._settopic(channel, newtopic, nick, ident, host)
		self.dispatch(self, "topicUpdated", prefix=prefix, params=params, hostmask=prefix, target=channel, newtopic=newtopic, 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 17
0
	def irc_NICK(self, prefix, params):
		"""
		Called when a user changes their nickname.
		"""
		nick, ident, host = processHostmask(prefix)
		
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
			self.nickChanged(params[0])
			self.dispatch(self, "nickChanged", prefix=prefix, params=params, hostmask=prefix, newname=params[0])
		else:
			if self.state: self.state._userrename(nick, params[0], ident, host, prefix)
			self.dispatch(self, "userRenamed", prefix=prefix, params=params, hostmask=prefix, newname=params[0], 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 18
0
	def irc_PART(self, prefix, params):
		"""
		Called when a user leaves a channel.
		"""
		nick, ident, host = processHostmask(prefix)
		channel = params[0]
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
			if self.state: self.state._leavechannel(channel)
			self.dispatch(self, "left", prefix=prefix, params=params, hostmask=prefix, target=channel, 
				nick=nick, ident=ident, host=host)
		else:
			if self.state: self.state._userpart(channel, nick, ident, host, prefix)
			self.dispatch(self, "userLeft", prefix=prefix, params=params, hostmask=prefix, target=channel, 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 19
0
	def irc_JOIN(self, prefix, params):
		"""
		Called when a user joins a channel.
		"""
		nick, ident, host = processHostmask(prefix)
		channel = params[-1]
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
			if self.state: 
				self.state._joinchannel(channel)
				self.sendLine("MODE %s" % channel)
			self.dispatch(self, "joined", prefix=prefix, params=params, hostmask=prefix, target=channel, 
				nick=nick, ident=ident, host=host)
		else:
			if self.state: self.state._userjoin(channel, nick, ident, host, prefix)
			self.dispatch(self, "userJoined", prefix=prefix, params=params, hostmask=prefix, target=channel, 
				nick=nick, ident=ident, host=host)
Ejemplo n.º 20
0
	def ctcpQuery(self, user, channel, messages, params):
		"""
		Dispatch method for any CTCP queries received.
		Duplicate tags ignored.
		Override from IRCClient
		"""
		seen = set()
		nick, ident, host = processHostmask(user)
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
		for tag, data in messages:
			if tag not in seen:
				#dispatch event					
				self.dispatch(self, "ctcpQuery", prefix=user, params=params, hostmask=user, target=channel, tag=tag, 
					data=data, nick=nick, ident=ident, host=host)
				#call handler if defined:
				method = getattr(self, 'ctcpQueryB_%s' % tag, None)
				if method is not None: method(user, channel, data)
				else: self.ctcp_unknownQuery(user, channel, tag, data)
			seen.add(tag)
Ejemplo n.º 21
0
	def ctcpReply(self, user, channel, messages, params):
		"""
		Dispatch method for any CTCP replies received.
		Duplicate tags ignored.
		Override from IRCClient
		"""
		seen = set()
		nick, ident, host = processHostmask(user)
		###
		# Commented because the prefix variable here will throw a NameError
		# and not sure how to fix
		###
		# if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			# self.prefixlen = len(prefix)
		for tag, data in messages:
			if tag not in seen:
				#dispatch event
				self.dispatch(self, "ctcpReply", prefix=user, params=params, hostmask=user, target=channel, tag=tag, 
					data=data, nick=nick, ident=ident, host=host)
			seen.add(tag)
Ejemplo n.º 22
0
	def irc_NOTICE(self, prefix, params):
		"""
		Called when a user gets a notice.
		"""
		if self.debug >= 2: print "INCOMING NOTICE:", prefix, params
		user = prefix
		channel = params[0]
		message = params[-1]

		if message[0] == X_DELIM:
			m = ctcpExtract(message)
			if m['extended']:
				self.ctcpReply(user, channel, m['extended'], params)
			if not m['normal']:
				return
			message = ' '.join(m['normal'])
		
		nick, ident, host = processHostmask(prefix)
		if nick == self.nickname:
			# take note of our prefix! (for message length calculation
			self.prefixlen = len(prefix)
		self.dispatch(self, "noticed", prefix=prefix, params=params, hostmask=user, target=channel, msg=message,
			nick=nick, ident=ident, host=host)