<commit_before>from twisted.enterprise import adbapi
from twisted.internet.defer import Deferred
from txircd.modbase import Command
from txircd.utils import chunk_message, crypt, irc_lower, now, CaseInsensitiveDictionary
import math, os, yaml

class Service(object):
	
	class ServiceSocket(object):
		class ServiceTransport(object):
			def loseConnection(self):
				pass
		
		def __init__(self):
			self.transport = self.ServiceTransport()
	
	def __init__(self, ircd, nick, ident, host, gecos, helpTexts):
		# We're going to try to keep Service fairly consistent with IRCUser, even if most of these variables will never be used
		# in order to prevent exceptions all over the place
		self.ircd = ircd
		self.socket = self.ServiceSocket()
		self.password = <PASSWORD>
		self.nickname = nick
		self.username = ident
		self.hostname = host
		self.realname = gecos
		self.ip = "127.0.0.1"
		self.server = self.ircd.servconfig["server_name"]
		self.signon = now()
		self.lastactivity = now()
		self.lastpong = now()
		self.mode = {}
		self.channels = CaseInsensitiveDictionary()
		self.disconnected = Deferred()
		self.disconnected.callback(None)
		self.registered = 0
		self.metadata = {
			"server": {},
			"user": {},
			"client": {},
			"ext": {},
			"private": {}
		}
		self.cache = {} # Not only do various other modules potentially play with the cache, but we can do what we want with it to store auction data, etc.
		self.help = helpTexts
	
	def register(self):
		pass
	
	def send_isupport(self):
		pass
	
	def disconnect(self, reason):
		pass
	
	def checkData(self, data):
		pass
	
	def connectionLost(self, reason):
		pass
	
	def sendMessage(self, command, *parameter_list, **kw):
		if command == "PRIVMSG" and "prefix" in kw:
			nick = kw["prefix"][0:kw["prefix"].find("!")]
			user = self.ircd.users[nick]
			params = parameter_list[0].split(" ")
			serviceCommand = params.pop(0).upper().lstrip(":") # Messages sent this way start with a colon
			if serviceCommand == "HELP":
				if not params:
					helpOut = chunk_message(self.help[0], 80)
					for line in helpOut:
						user.sendMessage("NOTICE", ":{}".format(line), prefix=self.prefix())
					user.sendMessage("NOTICE", ": ", prefix=self.prefix())
					commands = sorted(self.help[1].keys())
					for cmd in commands:
						info = self.help[1][cmd]
						if info[2] and "o" not in user.mode:
							continue
						user.sendMessage("NOTICE", ":\x02{}\x02\t{}".format(cmd.upper(), info[0]), prefix=self.prefix())
					user.sendMessage("NOTICE", ": ", prefix=self.prefix())
					user.sendMessage("NOTICE", ":End of HELP", prefix=self.prefix())
				else:
					helpCmd = params[0]
					if helpCmd not in self.help[1]:
						user.sendMessage("NOTICE", ":No help available for \x02{}\x02.".format(helpCmd), prefix=self.prefix())
					else:
						info = self.help[1][helpCmd]
						if info[2] and "o" not in user.mode:
							user.sendMessage("NOTICE", ":No help available for \x02{}\x02.".format(helpCmd), prefix=self.prefix())
						else:
							helpOut = chunk_message(info[1], 80)
							for line in helpOut:
								user.sendMessage("NOTICE", ":{}".format(line), prefix=self.prefix())
							user.sendMessage("NOTICE", ":*** End of \x02{}\x02 help".format(helpCmd), prefix=self.prefix())
			elif serviceCommand in self.help:
				self.ircd.users[nick].handleCommand(serviceCommand, None, params)
			else:
				self.ircd.users[nick].sendMessage("NOTICE", ":Unknown command \x02{}\x02.  Use \x1F/msg {} HELP\x1F for help.".format(serviceCommand, self.nickname), prefix=self.prefix())
	
	def setMetadata(self, namespace, key, value):
		oldValue = self.metadata[namespace][key] if key in self.metadata[namespace] else ""
		self.metadata[namespace][key] = value
		for modfunc in self.ircd.actions["metadataupdate"]:
			modfunc(self, namespace, key, oldValue, value)
	
	def delMetadata(self, namespace, key):
		oldValue = self.metadata[namespace][key]
		del self.metadata[namespace][key]
		for modfunc in self.ircd.actions["metadataupdate"]:
			modfunc(self, namespace, key, oldValue, "")
	
	def prefix(self):
		return "{}!{}@{}".format(self.nickname, self.username, self.hostname)
	<commit_msg>Fix services commands going through said service<commit_after>from twisted.enterprise import adbapi
from twisted.internet.defer import Deferred
from txircd.modbase import Command
from txircd.utils import chunk_message, crypt, irc_lower, now, CaseInsensitiveDictionary
import math, os, yaml

class Service(object):
	
	class ServiceSocket(object):
		class ServiceTransport(object):
			def loseConnection(self):
				pass
		
		def __init__(self):
			self.transport = self.ServiceTransport()
	
	def __init__(self, ircd, nick, ident, host, gecos, helpTexts):
		# We're going to try to keep Service fairly consistent with IRCUser, even if most of these variables will never be used
		# in order to prevent exceptions all over the place
		self.ircd = ircd
		self.socket = self.ServiceSocket()
		self.password = <PASSWORD>
		self.nickname = nick
		self.username = ident
		self.hostname = host
		self.realname = gecos
		self.ip = "127.0.0.1"
		self.server = self.ircd.servconfig["server_name"]
		self.signon = now()
		self.lastactivity = now()
		self.lastpong = now()
		self.mode = {}
		self.channels = CaseInsensitiveDictionary()
		self.disconnected = Deferred()
		self.disconnected.callback(None)
		self.registered = 0
		self.metadata = {
			"server": {},
			"user": {},
			"client": {},
			"ext": {},
			"private": {}
		}
		self.cache = {} # Not only do various other modules potentially play with the cache, but we can do what we want with it to store auction data, etc.
		self.help = helpTexts
	
	def register(self):
		pass
	
	def send_isupport(self):
		pass
	
	def disconnect(self, reason):
		pass
	
	def checkData(self, data):
		pass
	
	def connectionLost(self, reason):
		pass
	
	def sendMessage(self, command, *parameter_list, **kw):
		if command == "PRIVMSG" and "prefix" in kw:
			nick = kw["prefix"][0:kw["prefix"].find("!")]
			user = self.ircd.users[nick]
			params = parameter_list[0].split(" ")
			serviceCommand = params.pop(0).upper().lstrip(":") # Messages sent this way start with a colon
			if serviceCommand == "HELP":
				if not params:
					helpOut = chunk_message(self.help[0], 80)
					for line in helpOut:
						user.sendMessage("NOTICE", ":{}".format(line), prefix=self.prefix())
					user.sendMessage("NOTICE", ": ", prefix=self.prefix())
					commands = sorted(self.help[1].keys())
					for cmd in commands:
						info = self.help[1][cmd]
						if info[2] and "o" not in user.mode:
							continue
						user.sendMessage("NOTICE", ":\x02{}\x02\t{}".format(cmd.upper(), info[0]), prefix=self.prefix())
					user.sendMessage("NOTICE", ": ", prefix=self.prefix())
					user.sendMessage("NOTICE", ":End of HELP", prefix=self.prefix())
				else:
					helpCmd = params[0]
					if helpCmd not in self.help[1]:
						user.sendMessage("NOTICE", ":No help available for \x02{}\x02.".format(helpCmd), prefix=self.prefix())
					else:
						info = self.help[1][helpCmd]
						if info[2] and "o" not in user.mode:
							user.sendMessage("NOTICE", ":No help available for \x02{}\x02.".format(helpCmd), prefix=self.prefix())
						else:
							helpOut = chunk_message(info[1], 80)
							for line in helpOut:
								user.sendMessage("NOTICE", ":{}".format(line), prefix=self.prefix())
							user.sendMessage("NOTICE", ":*** End of \x02{}\x02 help".format(helpCmd), prefix=self.prefix())
			elif serviceCommand in self.help[1]:
				self.ircd.users[nick].handleCommand(serviceCommand, None, params)
			else:
				self.ircd.users[nick].sendMessage("NOTICE", ":Unknown command \x02{}\x02.  Use \x1F/msg {} HELP\x1F for help.".format(serviceCommand, self.nickname), prefix=self.prefix())
	
	def setMetadata(self, namespace, key, value):
		oldValue = self.metadata[namespace][key] if key in self.metadata[namespace] else ""
		self.metadata[namespace][key] = value
		for modfunc in self.ircd.actions["metadataupdate"]:
			modfunc(self, namespace, key, oldValue, value)
	
	def delMetadata(self, namespace, key):
		oldValue = self.metadata[namespace][key]
		del self.metadata[namespace][key]
		for modfunc in self.ircd.actions["metadataupdate"]:
			modfunc(self, namespace, key, oldValue, "")
	
	def prefix(self):
		return "{}!{}@{}".format(self.nickname, self.username, self.hostname)
	
{'fraction_non_alphanumeric': 0.14666346615458473, 'fraction_numerical': 0.011161785885741718, 'mean_word_length': 3.927853341218214, 'pattern_counts': {'":': 34, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '1052515', 'n_tokens_mistral': 3153, 'n_tokens_neox': 2649, 'n_words': 696}