# 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/utils.py
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)


from twisted.words.protocols import irc
from txircd.modbase import Mode
from txircd.utils import epoch, irc_lower, now
    
    def checkUnset(self, user, target, param):
        mask = irc_lower(param)
        if mask in self.tellLists and target in self.tellLists[mask]:
            self.tellLists[mask].remove(target)
        if "servernoticedata" in target.cache and mask in target.cache["servernoticedata"]:
            del target.cache["servernoticedata"][mask]
        return [True, mask]
    
    def showParam(self, user, target):
        if "s" in target.mode:
            for mask in target.mode["s"]:
                time = target.cache["servernoticedata"][mask] if "servernoticedata" in target.cache and mask in target.cache["servernoticedata"] else epoch(now())
                user.sendMessage(irc.RPL_LISTMODE, target.nickname, "s", mask, target.nickname, str(time))
        user.sendMessage(irc.RPL_ENDOFLISTMODE, target.nickname, "s", ":End of server notice type list")
    
    def sendServerNotice(self, type, message):
        type = irc_lower(type)
        if type in self.tellLists:
            for u in self.tellLists[type]:
                u.sendMessage("NOTICE", ":*** {}: {}".format(type.upper(), message))

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.servernotice = None
    
    def spawn(self):
        self.servernotice = ServerNoticeMode()
        self.ircd.module_data_cache["sendservernotice"] = self.servernotice.sendServerNotice

# 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/utils.py
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)


# Path: txircd/modules/umode_s.py
from twisted.words.protocols import irc
from txircd.modbase import Mode
from txircd.utils import epoch, irc_lower, now

    
    def checkUnset(self, user, target, param):
        mask = irc_lower(param)
        if mask in self.tellLists and target in self.tellLists[mask]:
            self.tellLists[mask].remove(target)
        if "servernoticedata" in target.cache and mask in target.cache["servernoticedata"]:
            del target.cache["servernoticedata"][mask]
        return [True, mask]
    
    def showParam(self, user, target):
        if "s" in target.mode:
            for mask in target.mode["s"]:
                time = target.cache["servernoticedata"][mask] if "servernoticedata" in target.cache and mask in target.cache["servernoticedata"] else epoch(now())
                user.sendMessage(irc.RPL_LISTMODE, target.nickname, "s", mask, target.nickname, str(time))
        user.sendMessage(irc.RPL_ENDOFLISTMODE, target.nickname, "s", ":End of server notice type list")
    
    def sendServerNotice(self, type, message):
        type = irc_lower(type)
        if type in self.tellLists:
            for u in self.tellLists[type]:
                u.sendMessage("NOTICE", ":*** {}: {}".format(type.upper(), message))

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.servernotice = None
    
    def spawn(self):
        self.servernotice = ServerNoticeMode()
        self.ircd.module_data_cache["sendservernotice"] = self.servernotice.sendServerNotice

        return {