コード例 #1
0
    def setMetadata(self, key, value, visibility, setByUser, fromServer=None):
        """
		Sets metadata for the user. If initiated by a remote server, that
		server should be specified in the fromServer parameter.
		If the value is None, deletes the metadata at the provided key.
		"""
        if not isValidMetadataKey(key):
            return False
        oldData = None
        if key in self._metadata:
            oldData = self._metadata[key]
        if setByUser and oldData and not oldData[3]:
            return False
        if setByUser and self.ircd.runActionUntilValue(
                "usercansetmetadata", key, users=[self]) is False:
            return False
        if value is None:
            if key in self._metadata:
                del self._metadata[key]
        elif not visibility:
            return False
        else:
            self._metadata[key] = (key, value, visibility, setByUser)
        oldValue = oldData[1] if oldData else None
        self.ircd.runActionStandard("usermetadataupdate",
                                    self,
                                    key,
                                    oldValue,
                                    value,
                                    visibility,
                                    setByUser,
                                    fromServer,
                                    users=[self])
        return True
コード例 #2
0
ファイル: channel.py プロジェクト: ElementalAlchemist/txircd
	def setMetadata(self, key, value, visibility, setByUser, fromServer = None):
		"""
		Sets metadata for the channel. Returns True if the set is successful or
		False if it is not. If the metadata set is caused by a message from a
		remote server, pass the server object as the fromServer parameter.
		If value is None, deletes the key provided.
		"""
		if not isValidMetadataKey(key):
			return False
		oldData = None
		if key in self._metadata:
			oldData = self._metadata[key]
		if setByUser and oldData and not oldData[3]:
			return False
		if setByUser and self.ircd.runActionUntilValue("usercansetmetadata", key, channels=[self]) is False:
			return False
		if value is None:
			del self._metadata[key]
		elif not visibility:
			return False
		else:
			self._metadata[key] = (key, value, visibility, setByUser)
		oldValue = oldData[1] if oldData else None
		self.ircd.runActionStandard("channelmetadataupdate", self, key, oldValue, value, visibility, setByUser, fromServer, channels=[self])
		return True
コード例 #3
0
    def setMetadata(self, key, value, visibility, setByUser, fromServer=None):
        """
		Sets metadata for the channel. Returns True if the set is successful or
		False if it is not. If the metadata set is caused by a message from a
		remote server, pass the server object as the fromServer parameter.
		If value is None, deletes the key provided.
		"""
        if not isValidMetadataKey(key):
            return False
        oldData = None
        if key in self._metadata:
            oldData = self._metadata[key]
        if setByUser and oldData and not oldData[3]:
            return False
        if setByUser and self.ircd.runActionUntilValue(
                "usercansetmetadata", key, channels=[self]) is False:
            return False
        if value is None:
            del self._metadata[key]
        elif not visibility:
            return False
        else:
            self._metadata[key] = (key, value, visibility, setByUser)
        oldValue = oldData[1] if oldData else None
        self.ircd.runActionStandard("channelmetadataupdate",
                                    self,
                                    key,
                                    oldValue,
                                    value,
                                    visibility,
                                    setByUser,
                                    fromServer,
                                    channels=[self])
        return True
コード例 #4
0
ファイル: user.py プロジェクト: Heufneutje/txircd
	def setMetadata(self, key, value, visibility, setByUser, fromServer = None):
		"""
		Sets metadata for the user. If initiated by a remote server, that
		server should be specified in the fromServer parameter.
		If the value is None, deletes the metadata at the provided key.
		"""
		if not isValidMetadataKey(key):
			return False
		oldData = None
		if key in self._metadata:
			oldData = self._metadata[key]
		if setByUser and oldData and not oldData[3]:
			return False
		if setByUser and self.ircd.runActionUntilValue("usercansetmetadata", key, users=[self]) is False:
			return False
		if value is None:
			if key in self._metadata:
				del self._metadata[key]
		elif not visibility:
			return False
		else:
			self._metadata[key] = (key, value, visibility, setByUser)
		oldValue = oldData[1] if oldData else None
		self.ircd.runActionStandard("usermetadataupdate", self, key, oldValue, value, visibility, setByUser, fromServer, users=[self])
		return True
コード例 #5
0
ファイル: metadata.py プロジェクト: ElementalAlchemist/txircd
	def execute(self, user, data):
		if "targetuser" in data:
			target = data["targetuser"]
			if target == user:
				targetName = "*"
			else:
				targetName = target.nick
			targetIsChannel = False
		elif "targetchan" in data:
			target = data["targetchan"]
			targetName = target.name
			targetIsChannel = True
		else:
			return None
		
		subcmd = data["subcmd"]
		if subcmd == "LIST":
			metadataList = target.metadataList()
			for key, value, visibility, setByUser in metadataList:
				if user.canSeeMetadataVisibility(visibility):
					user.sendMessage(irc.RPL_KEYVALUE, targetName, key, visibility, value)
			user.sendMessage(irc.RPL_METADATAEND, "end of metadata")
			return True
		if subcmd == "CLEAR":
			if not targetIsChannel and target != user and not self.ircd.runActionUntilValue("metadatasetpermission", user, target, "*"):
				user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, "*", "permission denied")
				return True
			if targetIsChannel and (not self.ircd.runActionUntilValue("checkchannellevel", "metadata", target, user, users=[user], channels=[target]) or self.ircd.runActionUntilValue("metadatasetpermission", user, target, "*") is False):
				user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, "*", "permission denied")
				return True
			metadataList = target.metadataList()
			for key, value, visibility, setByUser in metadataList:
				if not user.canSeeMetadataVisibility(visibility):
					continue
				if target.setMetadata(key, None, visibility, True):
					user.sendMessage(irc.RPL_KEYVALUE, targetName, key, visibility)
				else:
					user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key, "permission denied")
			user.sendMessage(irc.RPL_METADATAEND, "end of metadata")
			return True
		if subcmd == "GET":
			keyList = data["keys"]
			for key in keyList:
				if not isValidMetadataKey(key):
					user.sendMessage(irc.ERR_KEYINVALID, key, "invalid metadata key")
					continue
				if not target.metadataKeyExists(key):
					user.sendMessage(irc.ERR_NOMATCHINGKEY, targetName, key, "no matching key")
					continue
				realKey = target.metadataKeyCase(key)
				visibility = target.metadataVisibility(key)
				if not user.canSeeMetadataVisibility(visibility):
					user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, realKey, "permission denied")
					continue
				value = target.metadataValue(key)
				user.sendMessage(irc.RPL_KEYVALUE, targetName, realKey, visibility, value)
			return True
		if subcmd == "SET":
			key = data["key"]
			if not isValidMetadataKey(key):
				user.sendMessage(irc.ERR_KEYINVALID, key, "invalid metadata key")
				return True
			if not targetIsChannel and target != user and not self.ircd.runActionUntilValue("metadatasetpermission", user, target, key):
				user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key, "permission denied")
				return True
			if targetIsChannel and (not self.ircd.runActionUntilValue("checkchannellevel", "metadata", target, user, users=[user], channels=[target]) or self.ircd.runActionUntilValue("metadatasetpermission", user, target, key) is False):
				user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key, "permission denied")
				return True
			visibility = self.ircd.runActionUntilValue("metadatavisibility", key)
			if visibility is None:
				visibility = "*"
			if not user.canSeeMetadataVisibility(visibility):
				user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key, "permission denied")
				return True
			alreadySet = 0
			for metadataData in target.metadataList():
				if metadataData[3]:
					alreadySet += 1
			if alreadySet >= self.ircd.config["metadata_limit"]:
				user.sendMessage(irc.ERR_METADATALIMIT, targetName, "metadata limit reached")
				return True
			value = data["value"] if "value" in data else None
			if target.setMetadata(key, value, visibility, True):
				if value is None:
					user.sendMessage(irc.RPL_KEYVALUE, targetName, key, visibility)
				else:
					user.sendMessage(irc.RPL_KEYVALUE, targetName, key, visibility, value)
				user.sendMessage(irc.RPL_METADATAEND, "end of metadata")
			else:
				user.sendMessage(irc.ERR_KEYNOTSET, targetName, key, "key not set")
			return True
		return None
コード例 #6
0
ファイル: metadata.py プロジェクト: luxaritas/txircd
    def execute(self, user, data):
        if "targetuser" in data:
            target = data["targetuser"]
            if target == user:
                targetName = "*"
            else:
                targetName = target.nick
            targetIsChannel = False
        elif "targetchan" in data:
            target = data["targetchan"]
            targetName = target.name
            targetIsChannel = True
        else:
            return None

        subcmd = data["subcmd"]
        if subcmd == "LIST":
            metadataList = target.metadataList()
            for key, value, visibility, setByUser in metadataList:
                if user.canSeeMetadataVisibility(visibility):
                    user.sendMessage(irc.RPL_KEYVALUE, targetName, key,
                                     visibility, value)
            user.sendMessage(irc.RPL_METADATAEND, "end of metadata")
            return True
        if subcmd == "CLEAR":
            if not targetIsChannel and target != user and not self.ircd.runActionUntilValue(
                    "metadatasetpermission", user, target, "*"):
                user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, "*",
                                 "permission denied")
                return True
            if targetIsChannel and (not self.ircd.runActionUntilValue(
                    "checkchannellevel",
                    "metadata",
                    target,
                    user,
                    users=[user],
                    channels=[target]) or self.ircd.runActionUntilValue(
                        "metadatasetpermission", user, target, "*") is False):
                user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, "*",
                                 "permission denied")
                return True
            metadataList = target.metadataList()
            for key, value, visibility, setByUser in metadataList:
                if not user.canSeeMetadataVisibility(visibility):
                    continue
                if target.setMetadata(key, None, visibility, True):
                    user.sendMessage(irc.RPL_KEYVALUE, targetName, key,
                                     visibility)
                else:
                    user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key,
                                     "permission denied")
            user.sendMessage(irc.RPL_METADATAEND, "end of metadata")
            return True
        if subcmd == "GET":
            keyList = data["keys"]
            for key in keyList:
                if not isValidMetadataKey(key):
                    user.sendMessage(irc.ERR_KEYINVALID, key,
                                     "invalid metadata key")
                    continue
                if not target.metadataKeyExists(key):
                    user.sendMessage(irc.ERR_NOMATCHINGKEY, targetName, key,
                                     "no matching key")
                    continue
                realKey = target.metadataKeyCase(key)
                visibility = target.metadataVisibility(key)
                if not user.canSeeMetadataVisibility(visibility):
                    user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName,
                                     realKey, "permission denied")
                    continue
                value = target.metadataValue(key)
                user.sendMessage(irc.RPL_KEYVALUE, targetName, realKey,
                                 visibility, value)
            return True
        if subcmd == "SET":
            key = data["key"]
            if not isValidMetadataKey(key):
                user.sendMessage(irc.ERR_KEYINVALID, key,
                                 "invalid metadata key")
                return True
            if not targetIsChannel and target != user and not self.ircd.runActionUntilValue(
                    "metadatasetpermission", user, target, key):
                user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key,
                                 "permission denied")
                return True
            if targetIsChannel and (not self.ircd.runActionUntilValue(
                    "checkchannellevel",
                    "metadata",
                    target,
                    user,
                    users=[user],
                    channels=[target]) or self.ircd.runActionUntilValue(
                        "metadatasetpermission", user, target, key) is False):
                user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key,
                                 "permission denied")
                return True
            visibility = self.ircd.runActionUntilValue("metadatavisibility",
                                                       key)
            if visibility is None:
                visibility = "*"
            if not user.canSeeMetadataVisibility(visibility):
                user.sendMessage(irc.ERR_KEYNOPERMISSION, targetName, key,
                                 "permission denied")
                return True
            alreadySet = 0
            for metadataData in target.metadataList():
                if metadataData[3]:
                    alreadySet += 1
            if alreadySet >= self.ircd.config["metadata_limit"]:
                user.sendMessage(irc.ERR_METADATALIMIT, targetName,
                                 "metadata limit reached")
                return True
            value = data["value"] if "value" in data else None
            if target.setMetadata(key, value, visibility, True):
                if value is None:
                    user.sendMessage(irc.RPL_KEYVALUE, targetName, key,
                                     visibility)
                else:
                    user.sendMessage(irc.RPL_KEYVALUE, targetName, key,
                                     visibility, value)
                user.sendMessage(irc.RPL_METADATAEND, "end of metadata")
            else:
                user.sendMessage(irc.ERR_KEYNOTSET, targetName, key,
                                 "key not set")
            return True
        return None