# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/utils.py
# def chunk_message(msg, chunk_size):
#     chunks = []
#     msg += "\n"
#     while msg:
#         index = msg.find("\n",0,chunk_size+1)
#         if index < 0:
#             index = msg.rfind(" ",0,chunk_size+1)
#         if index < 0:
#             index = chunk_size
#         chunks.append(msg[:index])
#         msg = msg[index+1:] if msg[index] in " \n" else msg[index:]
#     return chunks
# 
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import chunk_message, irc_lower
            for target in targetlist:
                lowerTarget = irc_lower(target)
                if lowerTarget not in user.cache["monitorwatching"]:
                    user.cache["monitormasks"].append(target)
                    user.cache["monitorwatching"].append(lowerTarget)
                    if lowerTarget not in self.ircd.module_data_cache["monitorwatchedby"]:
                        self.ircd.module_data_cache["monitorwatchedby"][lowerTarget] = []
                    self.ircd.module_data_cache["monitorwatchedby"][lowerTarget].append(user)
                if target in self.ircd.users:
                    online.append(target)
                else:
                    offline.append(target)
            if online:
                onLines = chunk_message(" ".join(online), 400)
                for line in onLines:
                    user.sendMessage(irc.RPL_MONONLINE, ":{}".format(line.replace(" ", ",")))
            if offline:
                offLines = chunk_message(" ".join(offline), 400)
                for line in offLines:
                    user.sendMessage(irc.RPL_MONOFFLINE, ":{}".format(line.replace(" ", ",")))
        elif modifier == "-":
            targetlist = data["targetlist"]
            if "monitormasks" not in user.cache or "monitorwatching" not in user.cache:
                return
            for target in targetlist:
                lowerTarget = irc_lower(target)
                if lowerTarget in user.cache["monitorwatching"]:
                    user.cache["monitorwatching"].remove(lowerTarget)
                    watchList = user.cache["monitormasks"]
                    for mask in watchList:

# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/utils.py
# def chunk_message(msg, chunk_size):
#     chunks = []
#     msg += "\n"
#     while msg:
#         index = msg.find("\n",0,chunk_size+1)
#         if index < 0:
#             index = msg.rfind(" ",0,chunk_size+1)
#         if index < 0:
#             index = chunk_size
#         chunks.append(msg[:index])
#         msg = msg[index+1:] if msg[index] in " \n" else msg[index:]
#     return chunks
# 
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


# Path: txircd/modules/ircv3_monitor.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import chunk_message, irc_lower

            for target in targetlist:
                lowerTarget = irc_lower(target)
                if lowerTarget not in user.cache["monitorwatching"]:
                    user.cache["monitormasks"].append(target)
                    user.cache["monitorwatching"].append(lowerTarget)
                    if lowerTarget not in self.ircd.module_data_cache["monitorwatchedby"]:
                        self.ircd.module_data_cache["monitorwatchedby"][lowerTarget] = []
                    self.ircd.module_data_cache["monitorwatchedby"][lowerTarget].append(user)
                if target in self.ircd.users:
                    online.append(target)
                else:
                    offline.append(target)
            if online:
                onLines = chunk_message(" ".join(online), 400)
                for line in onLines:
                    user.sendMessage(irc.RPL_MONONLINE, ":{}".format(line.replace(" ", ",")))
            if offline:
                offLines = chunk_message(" ".join(offline), 400)
                for line in offLines:
                    user.sendMessage(irc.RPL_MONOFFLINE, ":{}".format(line.replace(" ", ",")))
        elif modifier == "-":
            targetlist = data["targetlist"]
            if "monitormasks" not in user.cache or "monitorwatching" not in user.cache:
                return
            for target in targetlist:
                lowerTarget = irc_lower(target)
                if lowerTarget in user.cache["monitorwatching"]:
                    user.cache["monitorwatching"].remove(lowerTarget)
                    watchList = user.cache["monitormasks"]
                    for mask in watchList:

                        if irc_lower(mask) == lowerTarget: