<commit_before>from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.config import ConfigValidationError
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from txircd.modules.xlinebase import XLineBase
from txircd.utils import durationToSeconds, ircLower, now
from zope.interface import implements
from fnmatch import fnmatchcase

class KLine(ModuleData, Command, XLineBase):
	implements(IPlugin, IModuleData, ICommand)
	
	name = "KLine"
	core = True
	lineType = "K"
	propagateToServers = False
	
	def actions(self):
		return [ ("register", 10, self.checkLines),
		         ("commandpermission-KLINE", 10, self.restrictToOper),
		         ("statsruntype-klines", 10, self.generateInfo),
		         ("burst", 10, self.burstLines) ]
	
	def userCommands(self):
		return [ ("KLINE", 1, self) ]
	
	def load(self):
		self.initializeLineStorage()

	def verifyConfig(self, config):
		if "client_ban_msg" in config and not isinstance(config["client_ban_msg"], basestring):
			raise ConfigValidationError("client_ban_msg", "value must be a string")
	
	def checkUserMatch(self, user, mask, data):
		banMask = self.normalizeMask(mask)
		userMask = ircLower("{}@{}".format(user.ident, user.host))
		if fnmatchcase(userMask, banMask):
			return True
		userMask = ircLower("{}@{}".format(user.ident, user.realHost))
		if fnmatchcase(userMask, banMask):
			return True
		userMask = ircLower("{}@{}".format(user.ident, user,ip))
		if fnmatchcase(userMask, banMask):
			return True
		return False
	
	def killUser(self, user, reason):
		self.ircd.log.info("Matched user {user.uuid} ({user.ident}@{user.host}) against a k:line: {reason}", user=user, reason=reason)
		user.sendMessage(irc.ERR_YOUREBANNEDCREEP, self.ircd.config.get("client_ban_msg", "You're banned! Email <EMAIL> for assistance."))
		user.disconnect("K:Lined: {}".format(reason))
	
	def checkLines(self, user):
		banReason = self.matchUser(user)
		if banReason:
			self.killUser(user, banReason)
			return False
		return True<commit_msg>Derp.<commit_after>from twisted.plugin import IPlugin
from twisted.words.protocols import irc
from txircd.config import ConfigValidationError
from txircd.module_interface import Command, ICommand, IModuleData, ModuleData
from txircd.modules.xlinebase import XLineBase
from txircd.utils import durationToSeconds, ircLower, now
from zope.interface import implements
from fnmatch import fnmatchcase

class KLine(ModuleData, Command, XLineBase):
	implements(IPlugin, IModuleData, ICommand)
	
	name = "KLine"
	core = True
	lineType = "K"
	propagateToServers = False
	
	def actions(self):
		return [ ("register", 10, self.checkLines),
		         ("commandpermission-KLINE", 10, self.restrictToOper),
		         ("statsruntype-klines", 10, self.generateInfo),
		         ("burst", 10, self.burstLines) ]
	
	def userCommands(self):
		return [ ("KLINE", 1, self) ]
	
	def load(self):
		self.initializeLineStorage()

	def verifyConfig(self, config):
		if "client_ban_msg" in config and not isinstance(config["client_ban_msg"], basestring):
			raise ConfigValidationError("client_ban_msg", "value must be a string")
	
	def checkUserMatch(self, user, mask, data):
		banMask = self.normalizeMask(mask)
		userMask = ircLower("{}@{}".format(user.ident, user.host))
		if fnmatchcase(userMask, banMask):
			return True
		userMask = ircLower("{}@{}".format(user.ident, user.realHost))
		if fnmatchcase(userMask, banMask):
			return True
		userMask = ircLower("{}@{}".format(user.ident, user.ip))
		if fnmatchcase(userMask, banMask):
			return True
		return False
	
	def killUser(self, user, reason):
		self.ircd.log.info("Matched user {user.uuid} ({user.ident}@{user.host}) against a k:line: {reason}", user=user, reason=reason)
		user.sendMessage(irc.ERR_YOUREBANNEDCREEP, self.ircd.config.get("client_ban_msg", "You're banned! Email <EMAIL> for assistance."))
		user.disconnect("K:Lined: {}".format(reason))
	
	def checkLines(self, user):
		banReason = self.matchUser(user)
		if banReason:
			self.killUser(user, banReason)
			return False
		return True
{'fraction_non_alphanumeric': 0.12616364527192553, 'fraction_numerical': 0.004409603135717786, 'mean_word_length': 5.12143928035982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1191446', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1313, 'n_words': 327}