# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/utils.py
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import irc_lower
from fnmatch import fnmatch
            # whatever keys in the user-settable namespaces is a major problem. //EA
            if data["value"]:
                target.setMetadata(namespace, key, data["value"])
                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key), ":{}".format(data["value"]))
            else:
                target.delMetadata(namespace, key)
                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
            user.sendMessage(irc.RPL_METADATAEND, ":end of metadata")
        elif subcmd == "CLEAR":
            for namespace in ["client", "user"]:
                removeKeys = target.metadata[namespace].keys()
                for key in removeKeys:
                    target.delMetadata(namespace, key)
                    user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
            user.sendMessage(irc.RPL_METADATAEND, ":end of metadata")
    
    def processParams(self, user, params):
        if user.registered > 0:
            user.sendMessage(irc.ERR_NOTREGISTERED, "METADATA", ":You have not registered")
            return {}
        if not params or len(params) < 2:
            user.sendMessage(irc.ERR_NEEDMOREPARAMS, "METADATA", ":Not enough parameters")
            return {}
        target = None
        targetname = None
        if params[0] in self.ircd.channels:
            target = self.ircd.channels[params[0]]
            targetname = target.name
        elif params[0] in self.ircd.users:
            target = self.ircd.users[params[0]]

# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/utils.py
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


# Path: txircd/modules/ircv3_metadata.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import irc_lower
from fnmatch import fnmatch

            # whatever keys in the user-settable namespaces is a major problem. //EA
            if data["value"]:
                target.setMetadata(namespace, key, data["value"])
                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key), ":{}".format(data["value"]))
            else:
                target.delMetadata(namespace, key)
                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
            user.sendMessage(irc.RPL_METADATAEND, ":end of metadata")
        elif subcmd == "CLEAR":
            for namespace in ["client", "user"]:
                removeKeys = target.metadata[namespace].keys()
                for key in removeKeys:
                    target.delMetadata(namespace, key)
                    user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
            user.sendMessage(irc.RPL_METADATAEND, ":end of metadata")
    
    def processParams(self, user, params):
        if user.registered > 0:
            user.sendMessage(irc.ERR_NOTREGISTERED, "METADATA", ":You have not registered")
            return {}
        if not params or len(params) < 2:
            user.sendMessage(irc.ERR_NEEDMOREPARAMS, "METADATA", ":Not enough parameters")
            return {}
        target = None
        targetname = None
        if params[0] in self.ircd.channels:
            target = self.ircd.channels[params[0]]
            targetname = target.name
        elif params[0] in self.ircd.users:
            target = self.ircd.users[params[0]]

            targetname = target.nickname