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

class NickCommand(ModuleData):
    implements(IPlugin, IModuleData)
    
    name = "NickCommand"
    core = True
    
    def hookIRCd(self, ircd):
        self.ircd = ircd
    
    def actions(self):
        return [ ("changenickmessage", 1, self.sendNickMessage),
                ("remotenickrequest", 1, self.forwardNickRequest),
                ("changenick", 1, self.broadcastNickChange),
                ("remotechangenick", 1, self.propagateNickChange) ]
    
    def userCommands(self):
        return [ ("NICK", 1, NickUserCommand(self.ircd)) ]
    
    def serverCommands(self):
        return [ ("NICK", 1, NickServerCommand(self.ircd)),
                ("CHGNICK", 1, ChgNickServerCommand(self.ircd)) ]
    
    def sendNickMessage(self, userShowList, user, oldNick):
        def transformUser(sayingUser):
            return "{}!{}@{}".format(oldNick, sayingUser.ident, sayingUser.host)
        for targetUser in userShowList:
            targetUser.sendMessage("NICK", to=user.nick, sourceuser=user, usertransform=transformUser)
        del userShowList[:]
    
    def forwardNickRequest(self, user, newNick):
        self.ircd.servers[user.uuid[:3]].sendMessage("CHGNICK", user.uuid, newNick, prefix=self.ircd.serverID)
        return True
    
    def broadcastNickChange(self, user, oldNick):
        nickTS = timestamp(user.nickSince)
        for server in self.ircd.servers.itervalues():
            if server.nextClosest == self.ircd.serverID:
                server.sendMessage("NICK", nickTS, user.nick, prefix=user.uuid)
    
    def propagateNickChange(self, user, oldNick):
        nickTS = timestamp(user.nickSince)
        fromServer = self.ircd.servers[user.uuid[:3]]
        while fromServer.nextClosest != self.ircd.serverID:
            fromServer = self.ircd.servers[fromServer.nextClosest]
        for server in self.ircd.servers.itervalues():
            if server != fromServer and server.nextClosest == self.ircd.serverID:
                server.sendMessage("NICK", nickTS, user.nick, prefix=user.uuid)

class NickUserCommand(Command):
    implements(ICommand)
    
    forRegistered = None<commit_msg>String timestamps since Python still cares<commit_after>from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from txircd.utils import isValidNick, timestamp
from zope.interface import implements
from datetime import datetime

class NickCommand(ModuleData):
    implements(IPlugin, IModuleData)
    
    name = "NickCommand"
    core = True
    
    def hookIRCd(self, ircd):
        self.ircd = ircd
    
    def actions(self):
        return [ ("changenickmessage", 1, self.sendNickMessage),
                ("remotenickrequest", 1, self.forwardNickRequest),
                ("changenick", 1, self.broadcastNickChange),
                ("remotechangenick", 1, self.propagateNickChange) ]
    
    def userCommands(self):
        return [ ("NICK", 1, NickUserCommand(self.ircd)) ]
    
    def serverCommands(self):
        return [ ("NICK", 1, NickServerCommand(self.ircd)),
                ("CHGNICK", 1, ChgNickServerCommand(self.ircd)) ]
    
    def sendNickMessage(self, userShowList, user, oldNick):
        def transformUser(sayingUser):
            return "{}!{}@{}".format(oldNick, sayingUser.ident, sayingUser.host)
        for targetUser in userShowList:
            targetUser.sendMessage("NICK", to=user.nick, sourceuser=user, usertransform=transformUser)
        del userShowList[:]
    
    def forwardNickRequest(self, user, newNick):
        self.ircd.servers[user.uuid[:3]].sendMessage("CHGNICK", user.uuid, newNick, prefix=self.ircd.serverID)
        return True
    
    def broadcastNickChange(self, user, oldNick):
        nickTS = timestamp(user.nickSince)
        for server in self.ircd.servers.itervalues():
            if server.nextClosest == self.ircd.serverID:
                server.sendMessage("NICK", nickTS, user.nick, prefix=user.uuid)
    
    def propagateNickChange(self, user, oldNick):
        nickTS = str(timestamp(user.nickSince))
        fromServer = self.ircd.servers[user.uuid[:3]]
        while fromServer.nextClosest != self.ircd.serverID:
            fromServer = self.ircd.servers[fromServer.nextClosest]
        for server in self.ircd.servers.itervalues():
            if server != fromServer and server.nextClosest == self.ircd.serverID:
                server.sendMessage("NICK", nickTS, user.nick, prefix=user.uuid)

class NickUserCommand(Command):
    implements(ICommand)
    
    forRegistered = None
{'fraction_non_alphanumeric': 0.10806385591485879, 'fraction_numerical': 0.0036839950880065493, 'mean_word_length': 3.032178217821782, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4645103', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1463, 'n_words': 306}