# 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 BlockCTCP(Mode):
    def has_CTCP(self, msg):
        if chr(1) not in msg:
            return False
        findpos = msg.find(chr(1))
        in_action = False
        while findpos > -1:
            if in_action or (msg[findpos+1:findpos+7] == "ACTION" and len(msg) > findpos + 7 and msg[findpos+7] == " "):
                in_action = not in_action
                findpos = msg.find(chr(1), findpos + 1)
            else:
                return True
        return False
    
    def checkPermission(self, user, cmd, data):
        if cmd not in ["PRIVMSG", "NOTICE"]:
            return data
        if self.has_CTCP(data["message"]):

# 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/blockctcp.py
from txircd.modbase import Mode


class BlockCTCP(Mode):
    def has_CTCP(self, msg):
        if chr(1) not in msg:
            return False
        findpos = msg.find(chr(1))
        in_action = False
        while findpos > -1:
            if in_action or (msg[findpos+1:findpos+7] == "ACTION" and len(msg) > findpos + 7 and msg[findpos+7] == " "):
                in_action = not in_action
                findpos = msg.find(chr(1), findpos + 1)
            else:
                return True
        return False
    
    def checkPermission(self, user, cmd, data):
        if cmd not in ["PRIVMSG", "NOTICE"]:
            return data
        if self.has_CTCP(data["message"]):

            exempt_chanops = "C" in self.ircd.servconfig["channel_exempt_chanops"]