# 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 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 irc_lower
from fnmatch import fnmatch

class ListCommand(Command):
    def onUse(self, user, data):
        chancache = []
        for channame, channel in self.ircd.channels.iteritems():
            if data["chanfilter"] is not None:
                filterMatch = False
                for filterEntry in data["chanfilter"]:
                    if fnmatch(channame, filterEntry):
                        filterMatch = True
                        break
                if not filterMatch:
                    continue
            chancache.append({
                "channel": channel,
                "name": channel.name,
                "users": len(channel.users),

# 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 irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


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


class ListCommand(Command):
    def onUse(self, user, data):
        chancache = []
        for channame, channel in self.ircd.channels.iteritems():
            if data["chanfilter"] is not None:
                filterMatch = False
                for filterEntry in data["chanfilter"]:
                    if fnmatch(channame, filterEntry):
                        filterMatch = True
                        break
                if not filterMatch:
                    continue
            chancache.append({
                "channel": channel,
                "name": channel.name,
                "users": len(channel.users),

                "topic": channel.topic if channel.topic else ""