<commit_before>from twisted.plugin import IPlugin
from twisted.python import log
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IMode, IModuleData, Mode, ModuleData
from txircd.utils import ircLower, ModeType
from zope.interface import implements
from fnmatch import fnmatch
import logging

class Oper(ModuleData, Mode):
	implements(IPlugin, IModuleData, IMode)
	
	name = "Oper"
	core = True
	
	def userCommands(self):
		return [ ("OPER", 1, UserOper(self.ircd)) ]
	
	def serverCommands(self):
		return [ ("OPER", 1, ServerOper(self.ircd)) ]
	
	def actions(self):
		return [ ("userhasoperpermission", 1, self.operPermission),
		("modepermission-user-o", 1, self.nope),
		("burst", 90, self.propagatePermissions) ]
	
	def userModes(self):
		return [ ("o", ModeType.NoParam, self) ]
	
	def operPermission(self, user, permissionType):
		if "o" not in user.modes:
			# Maybe the user de-opered or something, but if they did they're clearly not an oper now
			return False
		# Check for oper permissions in the user's permission storage
		if "oper-permissions" not in user.cache:
			return False
		return permissionType in user.cache["oper-permissions"]
	
	def nope(self, user, settingUser, adding, param):
		if adding:
			user.sendMessage(irc.ERR_NOPRIVILEGES, "Permission denied - User mode o may not be set")<commit_msg>Allow modules to query whether the user is a general oper or not<commit_after>from twisted.plugin import IPlugin
from twisted.python import log
from twisted.words.protocols import irc
from txircd.module_interface import Command, ICommand, IMode, IModuleData, Mode, ModuleData
from txircd.utils import ircLower, ModeType
from zope.interface import implements
from fnmatch import fnmatch
import logging

class Oper(ModuleData, Mode):
	implements(IPlugin, IModuleData, IMode)
	
	name = "Oper"
	core = True
	
	def userCommands(self):
		return [ ("OPER", 1, UserOper(self.ircd)) ]
	
	def serverCommands(self):
		return [ ("OPER", 1, ServerOper(self.ircd)) ]
	
	def actions(self):
		return [ ("userhasoperpermission", 1, self.operPermission),
		("modepermission-user-o", 1, self.nope),
		("burst", 90, self.propagatePermissions) ]
	
	def userModes(self):
		return [ ("o", ModeType.NoParam, self) ]
	
	def operPermission(self, user, permissionType):
		if "o" not in user.modes:
			# Maybe the user de-opered or something, but if they did they're clearly not an oper now
			return False
		# If the client code is just generally querying whether the user has any oper permissions, just tell it yes if the user has +o
		if not permissionType:
			return True
		# Check for oper permissions in the user's permission storage
		if "oper-permissions" not in user.cache:
			return False
		return permissionType in user.cache["oper-permissions"]
	
	def nope(self, user, settingUser, adding, param):
		if adding:
			user.sendMessage(irc.ERR_NOPRIVILEGES, "Permission denied - User mode o may not be set")
{'fraction_non_alphanumeric': 0.09620596205962059, 'fraction_numerical': 0.0040650406504065045, 'mean_word_length': 4.678846153846154, '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': '5694282', 'n_tokens_mistral': 972, 'n_tokens_neox': 887, 'n_words': 322}