migrate user privs check

This commit is contained in:
deathbybandaid 2019-09-19 08:45:23 -04:00
parent 597fabc6d3
commit 1164a7c478
6 changed files with 44 additions and 46 deletions

View File

@ -13,7 +13,7 @@ from word2number import w2n
from sopel_modules.spicemanip import spicemanip 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 .Commands import commands as botcommands
from .Database import db as botdb from .Database import db as botdb
from .Channels import channels as botchannels 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 # Allow permissions for enabling and disabling commands via hyphenargs
if botcom.dict["adminswitch"]: 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 return True
else: else:
botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") 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 # Allow permissions for enabling and disabling commands via hyphenargs
if botcom.dict["adminswitch"]: 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 return True
else: else:
botmessagelog.messagelog_error(botcom.dict["log_id"], "The admin switch (-a) is for use by authorized nicks ONLY.") 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): def trigger_cant_run(bot, trigger, botcom, message=None):
if message: if message:
botmessagelog.messagelog_error(botcom.dict["log_id"], 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.") botmessagelog.messagelog_error(botcom.dict["log_id"], "You however are authorized to bypass this warning with the (-a) admin switch.")
return False 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.") botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.")
return False 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 target != trigger.nick:
if botcom.dict["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]: 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.") 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.") botmessagelog.messagelog_error(botcom.dict["log_id"], "I don't know who/what " + str(target) + " is.")
return False 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 target != trigger.nick:
if onoff in ['enable', 'unblock', "activate", "on"]: 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.") 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.")

View File

@ -18,7 +18,6 @@ from sopel_modules.spicemanip import spicemanip
from .Logs import logs from .Logs import logs
from .Config import config as botconfig from .Config import config as botconfig
from .Users import users as botusers
"""Variable References""" """Variable References"""
@ -57,41 +56,6 @@ def bot_privs(privtype):
return botpriveval 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 Classes
""" """

View File

@ -6,7 +6,7 @@ import sopel
from sopel.tools import Identifier from sopel.tools import Identifier
from .Database import db as botdb 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 from sopel_modules.spicemanip import spicemanip
@ -524,5 +524,39 @@ class BotUsers():
elif outputtype == 'random': elif outputtype == 'random':
return spicemanip(validtargs, '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() users = BotUsers()

View File

@ -16,7 +16,7 @@ import sopel_modules.SpiceBot as SpiceBot
@sopel.module.nickname_commands('logs', 'debug') @sopel.module.nickname_commands('logs', 'debug')
def bot_command_logs(bot, trigger, botcom): 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.") SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.")
return return

View File

@ -29,7 +29,7 @@ def bot_command_privmsg(bot, trigger, botcom):
def bot_command_process(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.") SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.")
return return

View File

@ -13,7 +13,7 @@ import sopel_modules.SpiceBot as SpiceBot
@sopel.module.nickname_commands('update') @sopel.module.nickname_commands('update')
def nickname_comand_update(bot, trigger, botcom): 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.") SpiceBot.messagelog.messagelog_error(botcom.dict["log_id"], "I was unable to process this Bot Nick command due to privilege issues.")
return return