# Path: txircd/modbase.py
# class Module(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
# 
# 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 Module
from txircd.utils import irc_lower
from fnmatch import fnmatch

irc.ERR_CHANNOTALLOWED = "926" # I fully admit that this is an entirely made-up numeric name.

class DenychansModule(Module):
    def denyChannels(self, user, cmd, data):
        if "o" in user.mode:
            return data
        if cmd != "JOIN":
            return data
        channels = data["targetchan"]
        keys = data["keys"]
        remove = []
        for channel in channels:
            lowerName = irc_lower(channel.name)
            safe = False
            if "channel_allowchans" in self.ircd.servconfig:
                for chanmask in self.ircd.servconfig["channel_allowchans"]:

# Path: txircd/modbase.py
# class Module(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
# 
# Path: txircd/utils.py
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


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


irc.ERR_CHANNOTALLOWED = "926" # I fully admit that this is an entirely made-up numeric name.

class DenychansModule(Module):
    def denyChannels(self, user, cmd, data):
        if "o" in user.mode:
            return data
        if cmd != "JOIN":
            return data
        channels = data["targetchan"]
        keys = data["keys"]
        remove = []
        for channel in channels:
            lowerName = irc_lower(channel.name)
            safe = False
            if "channel_allowchans" in self.ircd.servconfig:
                for chanmask in self.ircd.servconfig["channel_allowchans"]:

                    if fnmatch(lowerName, irc_lower(chanmask)):