<commit_before>from twisted.internet.abstract import isIPAddress, isIPv6Address
from twisted.plugin import IPlugin
from twisted.python import log
from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
from txircd.utils import ModeType
from zope.interface import implements
from hashlib import sha256
import logging

class HostCloaking(ModuleData, Mode):
    implements(IPlugin, IModuleData, IMode)

    name = "HostCloaking"
    affectedActions = [ "modechange-user-x" ]
    cloakingSalt = None
    cloakingPrefix = None

    def hookIRCd(self, ircd):
        self.ircd = ircd

    def userModes(self):
        return [ ("x", ModeType.NoParam, self) ]

    def actions(self):
        return [ ("modeactioncheck-user-x-modechange-user-x", 1, self.modeChanged) ]

    def modeChanged(self, *params):
        return True

    def apply(self, actionType, user, param, settingUser, uid, adding, *params, **kw):
        if adding:
            userHost = user.host
            if isIPv6Address(userHost):
                user.changeHost(self.applyIPv6Cloak(userHost))
            elif isIPAddress(userHost):
                user.changeHost(self.applyIPv4Cloak(userHost))
            else:
                user.changeHost(self.applyHostCloak(userHost, user.ip))
        else:<commit_msg>Only apply the host cloak once<commit_after>from twisted.internet.abstract import isIPAddress, isIPv6Address
from twisted.plugin import IPlugin
from twisted.python import log
from txircd.module_interface import IMode, IModuleData, Mode, ModuleData
from txircd.utils import ModeType
from zope.interface import implements
from hashlib import sha256
import logging

class HostCloaking(ModuleData, Mode):
    implements(IPlugin, IModuleData, IMode)

    name = "HostCloaking"
    affectedActions = [ "modechange-user-x" ]
    cloakingSalt = None
    cloakingPrefix = None

    def hookIRCd(self, ircd):
        self.ircd = ircd

    def userModes(self):
        return [ ("x", ModeType.NoParam, self) ]

    def actions(self):
        return [ ("modeactioncheck-user-x-modechange-user-x", 1, self.modeChanged) ]

    def modeChanged(self, *params):
        if user.uuid[:3] == self.ircd.serverID:
            return True
        return None

    def apply(self, actionType, user, param, settingUser, uid, adding, *params, **kw):
        if adding:
            userHost = user.host
            if isIPv6Address(userHost):
                user.changeHost(self.applyIPv6Cloak(userHost))
            elif isIPAddress(userHost):
                user.changeHost(self.applyIPv4Cloak(userHost))
            else:
                user.changeHost(self.applyHostCloak(userHost, user.ip))
        else:
{'fraction_non_alphanumeric': 0.0920611256056653, 'fraction_numerical': 0.00633619083115915, 'mean_word_length': 2.964549483013294, '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': '798002', 'n_tokens_mistral': 823, 'n_tokens_neox': 801, 'n_words': 197}