test
This commit is contained in:
parent
9b3ae72030
commit
8792ff352d
@ -8,18 +8,34 @@ class Users():
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = None
|
self.bot = None
|
||||||
|
|
||||||
self.priv_dict = {
|
self.bot_priv_dict = {
|
||||||
"OWNER": 10,
|
"OWNER": 10,
|
||||||
"ADMIN": 5
|
"ADMIN": 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.channel_privilege_dict = {
|
||||||
|
"OPER": plugin.OPER,
|
||||||
|
"OWNER": plugin.OWNER,
|
||||||
|
"ADMIN": plugin.ADMIN,
|
||||||
|
"OP": plugin.OP,
|
||||||
|
"HALFOP": plugin.HALFOP,
|
||||||
|
"VOICE": plugin.VOICE,
|
||||||
|
}
|
||||||
|
|
||||||
"""Bot Priviledges"""
|
"""Bot Priviledges"""
|
||||||
|
|
||||||
|
def get_bot_privilege_name(self, privilege):
|
||||||
|
priv_list = []
|
||||||
|
for priv_name in list(self.bot_priv_dict.keys()):
|
||||||
|
if self.bot_priv_dict[priv_name] >= privilege:
|
||||||
|
priv_list.append(priv_name)
|
||||||
|
return priv_list[-1]
|
||||||
|
|
||||||
def has_bot_privilege(self, nick, privilege):
|
def has_bot_privilege(self, nick, privilege):
|
||||||
|
|
||||||
if not isinstance(privilege, int):
|
if not isinstance(privilege, int):
|
||||||
if privilege.upper() in list(self.priv_dict.keys()):
|
if privilege.upper() in list(self.bot_priv_dict.keys()):
|
||||||
privilege = self.priv_dict[privilege.upper()]
|
privilege = self.bot_priv_dict[privilege.upper()]
|
||||||
else:
|
else:
|
||||||
privilege = 0
|
privilege = 0
|
||||||
|
|
||||||
@ -27,9 +43,9 @@ class Users():
|
|||||||
|
|
||||||
def get_nick_bot_privilege_level(self, nick):
|
def get_nick_bot_privilege_level(self, nick):
|
||||||
if self.is_bot_owner(nick):
|
if self.is_bot_owner(nick):
|
||||||
return self.priv_dict["OWNER"]
|
return self.bot_priv_dict["OWNER"]
|
||||||
elif self.is_bot_admin(nick):
|
elif self.is_bot_admin(nick):
|
||||||
return self.priv_dict["ADMIN"]
|
return self.bot_priv_dict["ADMIN"]
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
"""Bot Owner"""
|
"""Bot Owner"""
|
||||||
@ -69,10 +85,18 @@ class Users():
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
"""Channel Priviledges"""
|
"""Channel Privileges"""
|
||||||
|
|
||||||
|
def get_channel_privilege_name(self, privilege):
|
||||||
|
priv_list = []
|
||||||
|
for priv_name in list(self.channel_privilege_dict.keys()):
|
||||||
|
if self.channel_privilege_dict[priv_name] >= privilege:
|
||||||
|
priv_list.append(priv_name)
|
||||||
|
return priv_list[-1]
|
||||||
|
|
||||||
def has_channel_privilege(self, nick, channelstr, privilege):
|
def has_channel_privilege(self, nick, channelstr, privilege):
|
||||||
|
|
||||||
|
if not isinstance(privilege, int):
|
||||||
if privilege.upper() == "OPER":
|
if privilege.upper() == "OPER":
|
||||||
privilege = plugin.OPER
|
privilege = plugin.OPER
|
||||||
elif privilege.upper() == "OWNER":
|
elif privilege.upper() == "OWNER":
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from sopel.trigger import Trigger
|
|||||||
from sopel_SpiceBot_Core_1 import sb
|
from sopel_SpiceBot_Core_1 import sb
|
||||||
|
|
||||||
|
|
||||||
def prerun():
|
def prerun(metadata={}):
|
||||||
"""This decorator is the hub of handling for all SpiceBot Commands"""
|
"""This decorator is the hub of handling for all SpiceBot Commands"""
|
||||||
|
|
||||||
def actual_decorator(function):
|
def actual_decorator(function):
|
||||||
@ -14,7 +14,13 @@ def prerun():
|
|||||||
@functools.wraps(function)
|
@functools.wraps(function)
|
||||||
def internal_prerun(bot, trigger, *args, **kwargs):
|
def internal_prerun(bot, trigger, *args, **kwargs):
|
||||||
|
|
||||||
comrun = ComRun(bot, trigger, function)
|
comrun = ComRun(bot, trigger, function, metadata)
|
||||||
|
|
||||||
|
# Check that nick has the correct bot or channel privileges
|
||||||
|
# to run the command.
|
||||||
|
if not comrun.is_nick_privileged():
|
||||||
|
comrun.osd(comrun.required_privileges_text())
|
||||||
|
return
|
||||||
|
|
||||||
# Since there was more than one command,
|
# Since there was more than one command,
|
||||||
# we are going to redispatch commands
|
# we are going to redispatch commands
|
||||||
@ -140,13 +146,26 @@ def rebuild_pipes(commands, trigger_str_add=None):
|
|||||||
|
|
||||||
class ComRun():
|
class ComRun():
|
||||||
|
|
||||||
def __init__(self, bot, trigger, function):
|
def __init__(self, bot, trigger, function, metadata):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
self.orig_trigger = trigger
|
self.orig_trigger = trigger
|
||||||
self.trigger = trigger
|
self.trigger = trigger
|
||||||
self.function = function
|
self.function = function
|
||||||
|
self.metadata = metadata
|
||||||
self._say = []
|
self._say = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def instigator(self):
|
||||||
|
return self.trigger.nick
|
||||||
|
|
||||||
|
@property
|
||||||
|
def channel(self):
|
||||||
|
return self.trigger.sender
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_in_channel(self):
|
||||||
|
return self.channel.startswith("#")
|
||||||
|
|
||||||
def say(self, message):
|
def say(self, message):
|
||||||
self._say.append(message)
|
self._say.append(message)
|
||||||
|
|
||||||
@ -155,6 +174,49 @@ class ComRun():
|
|||||||
recipients = self.trigger.sender
|
recipients = self.trigger.sender
|
||||||
sb.osd(messages, recipients, text_method, max_messages=-1)
|
sb.osd(messages, recipients, text_method, max_messages=-1)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def required_privileges(self):
|
||||||
|
bot_level = 0
|
||||||
|
channel_level = 0
|
||||||
|
|
||||||
|
if "required_privileges" in list(self.metadata.keys()):
|
||||||
|
if "bot_level" in list(self.metadata["required_privileges"].keys()):
|
||||||
|
bot_level = self.metadata["required_privileges"]["bot_level"]
|
||||||
|
if "channel_level" in list(self.metadata["required_privileges"].keys()):
|
||||||
|
channel_level = self.metadata["required_privileges"]["channel_level"]
|
||||||
|
|
||||||
|
return {
|
||||||
|
"bot": bot_level,
|
||||||
|
"channel": channel_level
|
||||||
|
}
|
||||||
|
|
||||||
|
@property()
|
||||||
|
def required_privileges_text(self):
|
||||||
|
ret_text = "This command requries privileges of/above the following"
|
||||||
|
if self.required_privileges["bot"]:
|
||||||
|
ret_text += " Bot: %s" % sb.users.get_bot_privilege_name(self.required_privileges["bot"])
|
||||||
|
if self.required_privileges["channel"] and self.is_in_channel:
|
||||||
|
ret_text += " or "
|
||||||
|
ret_text += "Channel: %s" % sb.users.get_channel_privilege_name(self.required_privileges["channel"])
|
||||||
|
ret_text += "."
|
||||||
|
return ret_text
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_nick_privileged(self):
|
||||||
|
has_bot_priv = True
|
||||||
|
has_channel_priv = True
|
||||||
|
|
||||||
|
priv_dict = self.required_privileges()
|
||||||
|
|
||||||
|
has_bot_priv = sb.users.has_bot_privilege(self.trigger.nick, priv_dict["bot"])
|
||||||
|
|
||||||
|
if self.is_in_channel:
|
||||||
|
has_channel_priv = sb.users.has_channel_privilege(self.trigger.nick, self.trigger.sender, priv_dict["channel"])
|
||||||
|
|
||||||
|
if has_bot_priv or has_channel_priv:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_real_command(self):
|
def is_real_command(self):
|
||||||
return sb.commands.is_real_command(self.command)
|
return sb.commands.is_real_command(self.command)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user