# Path: txircd/modbase.py
# class Module(object):
#     def hook(self, base):
#         self.ircd = base
#         return self


from txircd.modbase import Module
    def capRequestRemove(self, user, capability):
        return True
    
    def capAcknowledgeRemove(self, user, capability):
        return False
    
    def capClear(self, user, capability):
        return True
    
    def modifyJoinMessage(self, channel, user, joinShowUser):
        if "extended_join_wait" in channel.cache:
            del channel.cache["extended_join_wait"]
            remove = []
            for u in joinShowUser:
                if "cap" in u.cache and "extended-join" in u.cache["cap"]:
                    remove.append(u)
                    u.sendMessage("JOIN", user.metadata["ext"]["accountname"] if "accountname" in user.metadata["ext"] else "*", ":{}".format(user.realname), to=channel.name, prefix=user.prefix())
            for u in remove:
                joinShowUser.remove(u)
            return joinShowUser
        else:
            channel.cache["extended_join_wait"] = True
            return "again" # force this module to have lower priority so it goes last, after any modules that may actually hide the join notice

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.extended_join = None
    
    def spawn(self):

# Path: txircd/modbase.py
# class Module(object):
#     def hook(self, base):
#         self.ircd = base
#         return self


# Path: txircd/modules/ircv3_extended-join.py
from txircd.modbase import Module

    def capRequestRemove(self, user, capability):
        return True
    
    def capAcknowledgeRemove(self, user, capability):
        return False
    
    def capClear(self, user, capability):
        return True
    
    def modifyJoinMessage(self, channel, user, joinShowUser):
        if "extended_join_wait" in channel.cache:
            del channel.cache["extended_join_wait"]
            remove = []
            for u in joinShowUser:
                if "cap" in u.cache and "extended-join" in u.cache["cap"]:
                    remove.append(u)
                    u.sendMessage("JOIN", user.metadata["ext"]["accountname"] if "accountname" in user.metadata["ext"] else "*", ":{}".format(user.realname), to=channel.name, prefix=user.prefix())
            for u in remove:
                joinShowUser.remove(u)
            return joinShowUser
        else:
            channel.cache["extended_join_wait"] = True
            return "again" # force this module to have lower priority so it goes last, after any modules that may actually hide the join notice

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.extended_join = None
    
    def spawn(self):

        self.extended_join = ExtendedJoin().hook(self.ircd)