<commit_before>from twisted.plugin import IPlugin
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from txircd.utils import ModeType, now, timestamp
from zope.interface import implements

class ServerBurst(ModuleData, Command):
    implements(IPlugin, IModuleData, ICommand)
    
    name = "ServerBurst"
    core = True
    forRegistered = False
    
    def hookIRCd(self, ircd):
        self.ircd = ircd
    
    def actions(self):
        return [ ("startburst", 1, self.startBurst) ]
    
    def serverCommands(self):
        return [ ("BURST", 1, self) ]
    
    def startBurst(self, server):
        server.bursted = False
        serversByHopcount = []
        for remoteServer in self.ircd.servers.itervalues():
            hopCount = 1
            servTrace = remoteServer
            while servTrace.nextClosest != self.ircd.serverID:
                servTrace = self.ircd.servers[servTrace.nextClosest]
                hopCount += 1
            while len(serversByHopcount) < hopCount:
                serversByHopcount.append([])
            serversByHopcount[hopCount - 1].append(remoteServer)
        for hopCount in range(1, len(serversByHopcount) + 1):
            strHopCount = str(hopCount)
            for remoteServer in serversByHopcount[hopCount - 1]:
                server.sendMessage("SERVER", remoteServer.name, remoteServer.serverID, strHopCount, remoteServer.nextClosest, ":{}".format(remoteServer.description), prefix=self.ircd.serverID)
        for user in self.ircd.users.itervalues():
            if user.localOnly:
                continue
            currentTimestamp = str(timestamp(now()))
            signonTimestamp = str(timestamp(user.connectedSince))
            modes = []
            params = []
            listModes = {}
            for mode, param in user.modes.iteritems():
                if self.ircd.userModeTypes[mode] == ModeType.List:
                    listModes[mode] = param
                else:
                    modes.append(mode)
                    if param is not None:
                        params.append(param)
            modeStr = "+{} {}".format("".join(modes), " ".join(params)) if params else "+{}".format("".join(modes))
            server.sendMessage("UID", user.uuid, currentTimestamp, user.nick, user.realhost, user.host, user.ident, user.ip, signonTimestamp, modeStr, ":{}".format(user.gecos), prefix=self.ircd.serverID)
            for mode, paramList in listModes.iteritems():
                for param, setter, time in paramList:
                    server.sendMessage("LISTMODE", user.uuid, signonTimestamp, mode, param, setter, str(timestamp(time)), prefix=self.ircd.serverID)
            for namespace, metadata in user.metadata.iteritems():
                for key, value in metadata.iteritems():
                    server.sendMessage("METADATA", user.uuid, signonTimestamp, namespace, key, value, prefix=self.ircd.serverID)
        for channel in self.ircd.channels.itervalues():
            channelTimestamp = str(timestamp(channel.existedSince))
            users = []
            for user, ranks in channel.users.iteritems():
                if user.localOnly:
                    continue
                users.append("{},{}".format(ranks, user.uuid))
            if not users:
                continue # Let's not sync this channel since it won't sync properly
            modes = []
            params = []
            listModes = {}
            for mode, param in channel.modes.iteritems():
                if self.ircd.channelModeTypes[mode] == ModeType.List:
                    listModes[mode] = param
                else:
                    modes.append(mode)
                    if param is not None:
                        params.append(param)
            modeStr = "+{} {}".format("".join(modes), " ".join(params)) if params else "+{}".format("".join(modes))<commit_msg>Fix how the UID command works<commit_after>from twisted.plugin import IPlugin
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from txircd.utils import ModeType, timestamp
from zope.interface import implements

class ServerBurst(ModuleData, Command):
    implements(IPlugin, IModuleData, ICommand)
    
    name = "ServerBurst"
    core = True
    forRegistered = False
    
    def hookIRCd(self, ircd):
        self.ircd = ircd
    
    def actions(self):
        return [ ("startburst", 1, self.startBurst) ]
    
    def serverCommands(self):
        return [ ("BURST", 1, self) ]
    
    def startBurst(self, server):
        server.bursted = False
        serversByHopcount = []
        for remoteServer in self.ircd.servers.itervalues():
            hopCount = 1
            servTrace = remoteServer
            while servTrace.nextClosest != self.ircd.serverID:
                servTrace = self.ircd.servers[servTrace.nextClosest]
                hopCount += 1
            while len(serversByHopcount) < hopCount:
                serversByHopcount.append([])
            serversByHopcount[hopCount - 1].append(remoteServer)
        for hopCount in range(1, len(serversByHopcount) + 1):
            strHopCount = str(hopCount)
            for remoteServer in serversByHopcount[hopCount - 1]:
                server.sendMessage("SERVER", remoteServer.name, remoteServer.serverID, strHopCount, remoteServer.nextClosest, ":{}".format(remoteServer.description), prefix=self.ircd.serverID)
        for user in self.ircd.users.itervalues():
            if user.localOnly:
                continue
            signonTimestamp = str(timestamp(user.connectedSince))
            nickTimestamp = str(timestamp(user.nickSince))
            modes = []
            params = []
            listModes = {}
            for mode, param in user.modes.iteritems():
                if self.ircd.userModeTypes[mode] == ModeType.List:
                    listModes[mode] = param
                else:
                    modes.append(mode)
                    if param is not None:
                        params.append(param)
            modeStr = "+{} {}".format("".join(modes), " ".join(params)) if params else "+{}".format("".join(modes))
            server.sendMessage("UID", user.uuid, signonTimestamp, user.nick, user.realhost, user.host, user.ident, user.ip, nickTimestamp, modeStr, ":{}".format(user.gecos), prefix=self.ircd.serverID)
            for mode, paramList in listModes.iteritems():
                for param, setter, time in paramList:
                    server.sendMessage("LISTMODE", user.uuid, signonTimestamp, mode, param, setter, str(timestamp(time)), prefix=self.ircd.serverID)
            for namespace, metadata in user.metadata.iteritems():
                for key, value in metadata.iteritems():
                    server.sendMessage("METADATA", user.uuid, signonTimestamp, namespace, key, value, prefix=self.ircd.serverID)
        for channel in self.ircd.channels.itervalues():
            channelTimestamp = str(timestamp(channel.existedSince))
            users = []
            for user, ranks in channel.users.iteritems():
                if user.localOnly:
                    continue
                users.append("{},{}".format(ranks, user.uuid))
            if not users:
                continue # Let's not sync this channel since it won't sync properly
            modes = []
            params = []
            listModes = {}
            for mode, param in channel.modes.iteritems():
                if self.ircd.channelModeTypes[mode] == ModeType.List:
                    listModes[mode] = param
                else:
                    modes.append(mode)
                    if param is not None:
                        params.append(param)
            modeStr = "+{} {}".format("".join(modes), " ".join(params)) if params else "+{}".format("".join(modes))
{'fraction_non_alphanumeric': 0.10932311621966795, 'fraction_numerical': 0.0020434227330779057, 'mean_word_length': 2.0352713178294572, 'pattern_counts': {'":': 4, '<': 5, '<?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': '3286042', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2075, 'n_words': 489}