# 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 epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)


from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import epoch, now

irc.RPL_WHOISACCOUNT = "330"
irc.RPL_WHOISSECURE  = "671"
irc.RPL_WHOISCERTFP = "276"
irc.RPL_WHOISHOST = "378"

class WhoisCommand(Command):
    def onUse(self, user, data):
        if "targetuser" not in data:
            return
        targets = data["targetuser"]
        for u in targets:
            user.sendMessage(irc.RPL_WHOISUSER, u.nickname, u.username, u.hostname, "*", ":{}".format(u.realname))
            if "o" in user.mode or user == u:

# 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 epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)


# Path: txircd/modules/cmd_whois.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import epoch, now


irc.RPL_WHOISACCOUNT = "330"
irc.RPL_WHOISSECURE  = "671"
irc.RPL_WHOISCERTFP = "276"
irc.RPL_WHOISHOST = "378"

class WhoisCommand(Command):
    def onUse(self, user, data):
        if "targetuser" not in data:
            return
        targets = data["targetuser"]
        for u in targets:
            user.sendMessage(irc.RPL_WHOISUSER, u.nickname, u.username, u.hostname, "*", ":{}".format(u.realname))
            if "o" in user.mode or user == u:

                user.sendMessage(irc.RPL_WHOISHOST, u.nickname, ":is connecting from {}@{} {}".format(u.username, u.realhost, u.ip))