# 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()


from twisted.words.protocols import irc
from txircd.modbase import Command

class AwayCommand(Command):
    def onUse(self, user, data):
        if "reason" in data:
            user.setMetadata("ext", "away", data["reason"])
            user.sendMessage(irc.RPL_NOWAWAY, ":You have been marked as being away")
        else:
            if "away" in user.metadata["ext"]:
                user.delMetadata("ext", "away")
            user.sendMessage(irc.RPL_UNAWAY, ":You are no longer marked as being away")
    
    def processParams(self, user, params):
        if user.registered > 0:

# 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/modules/cmd_away.py
from twisted.words.protocols import irc
from txircd.modbase import Command


class AwayCommand(Command):
    def onUse(self, user, data):
        if "reason" in data:
            user.setMetadata("ext", "away", data["reason"])
            user.sendMessage(irc.RPL_NOWAWAY, ":You have been marked as being away")
        else:
            if "away" in user.metadata["ext"]:
                user.delMetadata("ext", "away")
            user.sendMessage(irc.RPL_UNAWAY, ":You are no longer marked as being away")
    
    def processParams(self, user, params):
        if user.registered > 0:

            user.sendMessage(irc.ERR_NOTREGISTERED, "AWAY", ":You have not registered")