<commit_before>from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from zope.interface import implements

irc.RPL_ADMINLOC1 = "257"
irc.RPL_ADMINLOC2 = "258"

class AdminCommand(ModuleData):
    implements(IPlugin, IModuleData)
    
    name = "AdminCommand"
    core = True
    
    def hookIRCd(self, ircd):
        self.ircd = ircd
    
    def actions(self):
        return [ ("sendremoteusermessage-256", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINME, *params, **kw)),
                ("sendremoteusermessage-257", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINLOC1, *params, **kw)),
                ("sendremoteusermessage-258", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINLOC2, *params, **kw)),
                ("sendremoteusermessage-259", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINEMAIL, *params, **kw)) ]
    
    def userCommands(self):
        return [ ("ADMIN", 1, UserAdmin(self.ircd, self.sendAdminData)) ]
    
    def serverCommands(self):
        return [ ("ADMINREQ", 1, ServerAdmin(self.ircd, self.sendAdminData)) ]
    
    def sendAdminData(self, user, serverName):
        user.sendMessage(irc.RPL_ADMINME, serverName, ":Administrative info for {}".format(serverName))
        try:
            adminData = self.ircd.config["admin_server"]
        except KeyError:
            adminData = ""
        if not adminData: # If the line is blank, let's provide a default value
            adminData = "This server has no admins. Anarchy!"
        user.sendMessage(irc.RPL_ADMINLOC1, ":{}".format(adminData))
        try:
            adminData = self.ircd.config["admin_admin"]
        except KeyError:
            adminData = ""
        if not adminData:
            adminData = "Nobody configured the second line of this."
        user.sendMessage(irc.RPL_ADMINLOC2, ":{}".format(adminData))
        try:
            adminEmail = self.ircd.config["admin_email"]
        except KeyError:
            adminEmail = ""
        if not adminEmail:
            adminEmail = "No Admin <<EMAIL>>"
        user.sendMessage(irc.RPL_ADMINEMAIL, ":{}".format(adminEmail))
    
    def pushMessage(self, user, numeric, *params, **kw):
        server = self.ircd.servers[user.uuid[:3]]
        server.sendMessage("PUSH", user.uuid, "::{} {} {}".format(kw["prefix"], numeric, " ".join(params)), prefix=self.ircd.serverID)
        return True

class UserAdmin(Command):
    implements(ICommand)
    
    def __init__(self, ircd, sendFunc):
        self.ircd = ircd
        self.sendFunc = sendFunc
    
    def parseParams(self, user, params, prefix, tags):
        if not params:
            return {}
        if params[0] == self.ircd.name:
            return {}
        if params[0] not in self.ircd.serverNames:
            user.sendSingleError("AdminServer", irc.ERR_NOSUCHSERVER, params[0], ":No such server")
            return None
        return {
            "server": self.ircd.servers[self.ircd.serverNames[params[0]]]
        }
    
    def execute(self, user, data):
        if "server" in data:
            server = data["server"]
            server.sendMessage("ADMINREQ", server.serverID, prefix=user.uuid)
        else:
            self.sendFunc(user, self.ircd.name)
        return True

class ServerAdmin(Command):
    implements(ICommand)
    
    def __init__(self, ircd, sendFunc):
        self.ircd = ircd
        self.sendFunc = sendFunc
    
    def parseParams(self, server, params, prefix, tags):
        if len(params) != 1:
            return None
        if prefix not in self.ircd.users:
            return None
        if params[0] == self.ircd.serverID:
            return {
                "fromuser": self.ircd.users[prefix]
            }
        if params[0] not in self.ircd.servers:
            return None
        return {
            "fromuser": self.ircd.users[prefix],
            "server": self.ircd.servers[params[0]]
        }
    
    def execute(self, server, data):
        if "server" in data:
            server = data["server"]
            server.sendMessage("ADMINREQ", server.serverID, prefix=user.uuid)
        else:
            self.sendFunc(user, self.ircd.name)
        return True

adminCmd = AdminCommand()<commit_msg>Fix incorrect use of user<commit_after>from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from zope.interface import implements

irc.RPL_ADMINLOC1 = "257"
irc.RPL_ADMINLOC2 = "258"

class AdminCommand(ModuleData):
    implements(IPlugin, IModuleData)
    
    name = "AdminCommand"
    core = True
    
    def hookIRCd(self, ircd):
        self.ircd = ircd
    
    def actions(self):
        return [ ("sendremoteusermessage-256", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINME, *params, **kw)),
                ("sendremoteusermessage-257", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINLOC1, *params, **kw)),
                ("sendremoteusermessage-258", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINLOC2, *params, **kw)),
                ("sendremoteusermessage-259", 1, lambda user, *params, **kw: self.pushMessage(user, irc.RPL_ADMINEMAIL, *params, **kw)) ]
    
    def userCommands(self):
        return [ ("ADMIN", 1, UserAdmin(self.ircd, self.sendAdminData)) ]
    
    def serverCommands(self):
        return [ ("ADMINREQ", 1, ServerAdmin(self.ircd, self.sendAdminData)) ]
    
    def sendAdminData(self, user, serverName):
        user.sendMessage(irc.RPL_ADMINME, serverName, ":Administrative info for {}".format(serverName))
        try:
            adminData = self.ircd.config["admin_server"]
        except KeyError:
            adminData = ""
        if not adminData: # If the line is blank, let's provide a default value
            adminData = "This server has no admins. Anarchy!"
        user.sendMessage(irc.RPL_ADMINLOC1, ":{}".format(adminData))
        try:
            adminData = self.ircd.config["admin_admin"]
        except KeyError:
            adminData = ""
        if not adminData:
            adminData = "Nobody configured the second line of this."
        user.sendMessage(irc.RPL_ADMINLOC2, ":{}".format(adminData))
        try:
            adminEmail = self.ircd.config["admin_email"]
        except KeyError:
            adminEmail = ""
        if not adminEmail:
            adminEmail = "No Admin <<EMAIL>>"
        user.sendMessage(irc.RPL_ADMINEMAIL, ":{}".format(adminEmail))
    
    def pushMessage(self, user, numeric, *params, **kw):
        server = self.ircd.servers[user.uuid[:3]]
        server.sendMessage("PUSH", user.uuid, "::{} {} {}".format(kw["prefix"], numeric, " ".join(params)), prefix=self.ircd.serverID)
        return True

class UserAdmin(Command):
    implements(ICommand)
    
    def __init__(self, ircd, sendFunc):
        self.ircd = ircd
        self.sendFunc = sendFunc
    
    def parseParams(self, user, params, prefix, tags):
        if not params:
            return {}
        if params[0] == self.ircd.name:
            return {}
        if params[0] not in self.ircd.serverNames:
            user.sendSingleError("AdminServer", irc.ERR_NOSUCHSERVER, params[0], ":No such server")
            return None
        return {
            "server": self.ircd.servers[self.ircd.serverNames[params[0]]]
        }
    
    def execute(self, user, data):
        if "server" in data:
            server = data["server"]
            server.sendMessage("ADMINREQ", server.serverID, prefix=user.uuid)
        else:
            self.sendFunc(user, self.ircd.name)
        return True

class ServerAdmin(Command):
    implements(ICommand)
    
    def __init__(self, ircd, sendFunc):
        self.ircd = ircd
        self.sendFunc = sendFunc
    
    def parseParams(self, server, params, prefix, tags):
        if len(params) != 1:
            return None
        if prefix not in self.ircd.users:
            return None
        if params[0] == self.ircd.serverID:
            return {
                "fromuser": self.ircd.users[prefix]
            }
        if params[0] not in self.ircd.servers:
            return None
        return {
            "fromuser": self.ircd.users[prefix],
            "server": self.ircd.servers[params[0]]
        }
    
    def execute(self, server, data):
        if "server" in data:
            server = data["server"]
            server.sendMessage("ADMINREQ", server.serverID, prefix=data["fromuser"].uuid)
        else:
            self.sendFunc(user, self.ircd.name)
        return True

adminCmd = AdminCommand()
{'fraction_non_alphanumeric': 0.12289101687186503, 'fraction_numerical': 0.008891928864569083, 'mean_word_length': 2.375529049634475, 'pattern_counts': {'":': 20, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4646482', 'n_tokens_mistral': 2724, 'n_tokens_neox': 2685, 'n_words': 617}