mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
migrate user privs check
This commit is contained in:
parent
597fabc6d3
commit
1164a7c478
@ -13,7 +13,7 @@ from word2number import w2n
|
||||
|
||||
from sopel_modules.spicemanip import spicemanip
|
||||
|
||||
from .Tools import command_permissions_check, class_create
|
||||
from .Tools import class_create
|
||||
from .Commands import commands as botcommands
|
||||
from .Database import db as botdb
|
||||
from .Channels import channels as botchannels
|
||||
@ -282,7 +282,7 @@ def trigger_runstatus_query(bot, trigger, botcom):
|
||||
|
||||
# Allow permissions for enabling and disabling commands via hyphenargs
|
||||
if botcom.dict["adminswitch"]:
|
||||
if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if botusers.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
return True
|
||||
else:
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.")
|
||||
@ -348,7 +348,7 @@ def trigger_runstatus(bot, trigger, botcom):
|
||||
|
||||
# Allow permissions for enabling and disabling commands via hyphenargs
|
||||
if botcom.dict["adminswitch"]:
|
||||
if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if botusers.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
return True
|
||||
else:
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.")
|
||||
@ -430,7 +430,7 @@ def trigger_runstatus(bot, trigger, botcom):
|
||||
def trigger_cant_run(bot, trigger, botcom, message=None):
|
||||
if message:
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], message)
|
||||
if command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if botusers.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "You however are authorized to bypass this warning with the (-a) admin switch.")
|
||||
return False
|
||||
|
||||
@ -532,7 +532,7 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom):
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.")
|
||||
return False
|
||||
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if not botusers.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if target != trigger.nick:
|
||||
if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]:
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable this command for " + str(target) + " due to privilege issues.")
|
||||
@ -583,7 +583,7 @@ def trigger_hyphen_arg_handler(bot, trigger, botcom):
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.")
|
||||
return False
|
||||
|
||||
if not command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if not botusers.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if target != trigger.nick:
|
||||
if onoff in ['enable', 'unblock', "activate", "on"]:
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "I was unable to enable multirun usage on " + str(botcom.dict["comtext"]) + " for " + str(target) + " due to privilege issues.")
|
||||
|
||||
@ -18,7 +18,6 @@ from sopel_modules.spicemanip import spicemanip
|
||||
|
||||
from .Logs import logs
|
||||
from .Config import config as botconfig
|
||||
from .Users import users as botusers
|
||||
|
||||
|
||||
"""Variable References"""
|
||||
@ -57,41 +56,6 @@ def bot_privs(privtype):
|
||||
return botpriveval
|
||||
|
||||
|
||||
def command_permissions_check(bot, trigger, privslist):
|
||||
|
||||
nick_id = botusers.whois_ident(trigger.nick)
|
||||
if bot.config.SpiceBot_regnick.regnick:
|
||||
if int(nick_id) not in botusers.dict["identified"]:
|
||||
return False
|
||||
|
||||
commandrunconsensus = []
|
||||
|
||||
for botpriv in ["admins", "owner"]:
|
||||
if botpriv in privslist:
|
||||
botpriveval = bot_privs(botpriv)
|
||||
if not inlist(trigger.nick, botpriveval):
|
||||
commandrunconsensus.append('False')
|
||||
else:
|
||||
commandrunconsensus.append('True')
|
||||
|
||||
if not trigger.is_privmsg:
|
||||
for chanpriv in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']:
|
||||
if chanpriv in privslist:
|
||||
chanpriveval = channel_privs(bot, trigger.sender, chanpriv)
|
||||
if not inlist(trigger.nick, chanpriveval):
|
||||
commandrunconsensus.append('False')
|
||||
else:
|
||||
commandrunconsensus.append('True')
|
||||
|
||||
if not len(privslist):
|
||||
commandrunconsensus.append('True')
|
||||
|
||||
if 'True' not in commandrunconsensus:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
"""
|
||||
Classes
|
||||
"""
|
||||
|
||||
@ -6,7 +6,7 @@ import sopel
|
||||
from sopel.tools import Identifier
|
||||
|
||||
from .Database import db as botdb
|
||||
from .Tools import is_number, inlist, similar, array_arrangesort
|
||||
from .Tools import is_number, inlist, similar, array_arrangesort, bot_privs, channel_privs
|
||||
|
||||
from sopel_modules.spicemanip import spicemanip
|
||||
|
||||
@ -524,5 +524,39 @@ class BotUsers():
|
||||
elif outputtype == 'random':
|
||||
return spicemanip(validtargs, 'random')
|
||||
|
||||
def command_permissions_check(self, bot, trigger, privslist):
|
||||
|
||||
nick_id = self.whois_ident(trigger.nick)
|
||||
if bot.config.SpiceBot_regnick.regnick:
|
||||
if int(nick_id) not in self.dict["identified"]:
|
||||
return False
|
||||
|
||||
commandrunconsensus = []
|
||||
|
||||
for botpriv in ["admins", "owner"]:
|
||||
if botpriv in privslist:
|
||||
botpriveval = bot_privs(botpriv)
|
||||
if not inlist(trigger.nick, botpriveval):
|
||||
commandrunconsensus.append('False')
|
||||
else:
|
||||
commandrunconsensus.append('True')
|
||||
|
||||
if not trigger.is_privmsg:
|
||||
for chanpriv in ['OP', 'HOP', 'VOICE', 'OWNER', 'ADMIN']:
|
||||
if chanpriv in privslist:
|
||||
chanpriveval = channel_privs(bot, trigger.sender, chanpriv)
|
||||
if not inlist(trigger.nick, chanpriveval):
|
||||
commandrunconsensus.append('False')
|
||||
else:
|
||||
commandrunconsensus.append('True')
|
||||
|
||||
if not len(privslist):
|
||||
commandrunconsensus.append('True')
|
||||
|
||||
if 'True' not in commandrunconsensus:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
users = BotUsers()
|
||||
|
||||
@ -16,7 +16,7 @@ import sopel_modules.SpiceBot as SpiceBot
|
||||
@sopel.module.nickname_commands('logs', 'debug')
|
||||
def bot_command_logs(bot, trigger, botcom):
|
||||
|
||||
if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if not SpiceBot.users.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ def bot_command_privmsg(bot, trigger, botcom):
|
||||
|
||||
def bot_command_process(bot, trigger, botcom):
|
||||
|
||||
if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner']):
|
||||
if not SpiceBot.users.command_permissions_check(bot, trigger, ['admins', 'owner']):
|
||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot
|
||||
@sopel.module.nickname_commands('update')
|
||||
def nickname_comand_update(bot, trigger, botcom):
|
||||
|
||||
if not SpiceBot.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
if not SpiceBot.users.command_permissions_check(bot, trigger, ['admins', 'owner', 'OP', 'ADMIN', 'OWNER']):
|
||||
SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.")
|
||||
return
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user