# 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
import re

irc.RPL_BADWORDADDED = "927"
irc.RPL_BADWORDREMOVED = "928"
irc.ERR_NOSUCHBADWORD = "929"

class BadwordCommand(Command):
    def __init__(self):
        self.badwords = {}
    
    def onUse(self, user, data):
        if "replacement" in data:
            badword = data["badword"]
            replacement = data["replacement"]
            self.badwords[badword] = replacement
            user.sendMessage(irc.RPL_BADWORDADDED, badword, ":{}".format(replacement))
        else:
            del self.badwords[badword]
            user.sendMessage(irc.RPL_BADWORDREMOVED, badword, ":Badword removed")
    
    def processParams(self, user, params):
        if user.registered > 0:
            user.sendMessage(irc.ERR_NOTREGISTERED, "BADWORD", ":You have not registered")

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


irc.RPL_BADWORDADDED = "927"
irc.RPL_BADWORDREMOVED = "928"
irc.ERR_NOSUCHBADWORD = "929"

class BadwordCommand(Command):
    def __init__(self):
        self.badwords = {}
    
    def onUse(self, user, data):
        if "replacement" in data:
            badword = data["badword"]
            replacement = data["replacement"]
            self.badwords[badword] = replacement
            user.sendMessage(irc.RPL_BADWORDADDED, badword, ":{}".format(replacement))
        else:
            del self.badwords[badword]
            user.sendMessage(irc.RPL_BADWORDREMOVED, badword, ":Badword removed")
    
    def processParams(self, user, params):
        if user.registered > 0:
            user.sendMessage(irc.ERR_NOTREGISTERED, "BADWORD", ":You have not registered")

            return {}