# Path: txircd/modbase.py
# class Mode(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def checkSet(self, user, target, param):
#         return [True, param]
#     def checkUnset(self, user, target, param):
#         return [True, param]
#     def showParam(self, user, target, param):
#         return param
#     def checkPermission(self, user, cmd, data):
#         return data


from txircd.modbase import Mode

class BlockColor(Mode):
    def checkPermission(self, user, cmd, data):
        if cmd not in ["PRIVMSG", "NOTICE"]:
            return data
        if chr(2) not in data["message"] and chr(3) not in data["message"] and chr(15) not in data["message"] and chr(22) not in data["message"] and chr(29) not in data["message"] and chr(31) not in data["message"]:
            return data
        okchans = []
        okchanmods = []
        exempt_chanops = "c" in self.ircd.servconfig["channel_exempt_chanops"] 
        for index, chan in enumerate(data["targetchan"]):
            if "c" not in chan.mode or (exempt_chanops and user.hasAccess(chan, "o")):
                okchans.append(chan)
                okchanmods.append(data["chanmod"][index])
        data["targetchan"] = okchans
        data["chanmod"] = okchanmods
        return data

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
    
    def spawn(self):
        return {
            "modes": {

# Path: txircd/modbase.py
# class Mode(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def checkSet(self, user, target, param):
#         return [True, param]
#     def checkUnset(self, user, target, param):
#         return [True, param]
#     def showParam(self, user, target, param):
#         return param
#     def checkPermission(self, user, cmd, data):
#         return data


# Path: txircd/modules/blockcolor.py
from txircd.modbase import Mode


class BlockColor(Mode):
    def checkPermission(self, user, cmd, data):
        if cmd not in ["PRIVMSG", "NOTICE"]:
            return data
        if chr(2) not in data["message"] and chr(3) not in data["message"] and chr(15) not in data["message"] and chr(22) not in data["message"] and chr(29) not in data["message"] and chr(31) not in data["message"]:
            return data
        okchans = []
        okchanmods = []
        exempt_chanops = "c" in self.ircd.servconfig["channel_exempt_chanops"] 
        for index, chan in enumerate(data["targetchan"]):
            if "c" not in chan.mode or (exempt_chanops and user.hasAccess(chan, "o")):
                okchans.append(chan)
                okchanmods.append(data["chanmod"][index])
        data["targetchan"] = okchans
        data["chanmod"] = okchanmods
        return data

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
    
    def spawn(self):
        return {
            "modes": {

                "cnc": BlockColor()