# 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 twisted.words.protocols import irc
from txircd.modbase import Mode

class ModeratedMode(Mode):
    def checkPermission(self, user, cmd, data):
        if cmd not in ["PRIVMSG", "NOTICE"]:
            return data
        targetChannels = data["targetchan"]
        chanModList = data["chanmod"]
        removeChannels = []
        for channel in targetChannels:
            if "m" in channel.mode and not user.hasAccess(channel, "v"):
                removeChannels.append(channel)
                user.sendMessage(irc.ERR_CANNOTSENDTOCHAN, channel.name, ":Cannot send to channel (+m)")
        for channel in removeChannels:
            index = targetChannels.index(channel)
            targetChannels.pop(index)
            chanModList.pop(index)

# 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/cmode_m.py
from twisted.words.protocols import irc
from txircd.modbase import Mode


class ModeratedMode(Mode):
    def checkPermission(self, user, cmd, data):
        if cmd not in ["PRIVMSG", "NOTICE"]:
            return data
        targetChannels = data["targetchan"]
        chanModList = data["chanmod"]
        removeChannels = []
        for channel in targetChannels:
            if "m" in channel.mode and not user.hasAccess(channel, "v"):
                removeChannels.append(channel)
                user.sendMessage(irc.ERR_CANNOTSENDTOCHAN, channel.name, ":Cannot send to channel (+m)")
        for channel in removeChannels:
            index = targetChannels.index(channel)
            targetChannels.pop(index)
            chanModList.pop(index)

        data["targetchan"] = targetChannels