This commit is contained in:
deathbybandaid 2019-06-28 16:17:43 -04:00
parent 2614ee5b50
commit 6cfec9d645
2 changed files with 59 additions and 39 deletions

View File

@ -21,6 +21,7 @@ from .Config import config as botconfig
from .Database import db as botdb from .Database import db as botdb
from .Read import read as botread from .Read import read as botread
from .Channels import channels as botchannels from .Channels import channels as botchannels
from .Users import users as botusers
class SpiceBot_Commands_MainSection(StaticSection): class SpiceBot_Commands_MainSection(StaticSection):
@ -91,21 +92,32 @@ class BotCommands():
return realcom return realcom
def chan_or_nick(self, target):
if botchannels.check_channel_bot(target, True):
return "channel"
elif botdb.check_nick_id(target):
return "nick"
else:
raise Exception(str(target.lower()) + " appears to not be a valid user/channel")
def get_commands_disabled(self, target, disabletype="fully"): def get_commands_disabled(self, target, disabletype="fully"):
disabletype = str(disabletype) disabletype = str(disabletype)
target_type = self.chan_or_nick(target)
if disabletype not in list(self.dict['disabled'].keys()): if disabletype not in list(self.dict['disabled'].keys()):
self.dict['disabled'][disabletype] = { self.dict['disabled'][disabletype] = {
"users": {}, "nick": {},
"channels": {} "channel": {}
} }
if botdb.check_nick_id(target): if target_type == "nick":
if target not in list(self.dict['disabled'][disabletype]["users"].keys()): nick_id = botusers.ID(target)
self.dict['disabled'][disabletype]["users"][target] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {} if nick_id not in list(self.dict['disabled'][disabletype]["nick"].keys()):
return self.dict['disabled'][disabletype]["users"][target] self.dict['disabled'][disabletype]["nick"][nick_id] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {}
elif botchannels.check_channel_bot(target, True): return self.dict['disabled'][disabletype]["nick"][nick_id]
if target not in list(self.dict['disabled'][disabletype]["channels"].keys()): elif target_type == "channel":
self.dict['disabled'][disabletype]["channels"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {} target = str(target).lower()
return self.dict['disabled'][disabletype]["channels"][target] if target not in list(self.dict['disabled'][disabletype]["channel"].keys()):
self.dict['disabled'][disabletype]["channel"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {}
return self.dict['disabled'][disabletype]["channel"][target]
else: else:
raise Exception(str(target.lower()) + " appears to not be a valid user/channel") raise Exception(str(target.lower()) + " appears to not be a valid user/channel")
@ -116,42 +128,50 @@ class BotCommands():
return False return False
def set_command_disabled(self, command, target, timestamp, reason, bywhom, disabletype="fully"): def set_command_disabled(self, command, target, timestamp, reason, bywhom, disabletype="fully"):
disabletype = str(disabletype)
target_type = self.chan_or_nick(target)
if disabletype not in list(self.dict['disabled'].keys()): if disabletype not in list(self.dict['disabled'].keys()):
self.dict['disabled'][disabletype] = { self.dict['disabled'][disabletype] = {
"users": {}, "nick": {},
"channels": {} "channel": {}
} }
if botdb.check_nick_id(target): if target_type == "nick":
if target not in list(self.dict['disabled'][disabletype]["users"].keys()): nick_id = botusers.ID(target)
self.dict['disabled'][disabletype]["users"][target] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {} if nick_id not in list(self.dict['disabled'][disabletype]["nick"].keys()):
self.dict['disabled'][disabletype]["users"][target][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} self.dict['disabled'][disabletype]["nick"][nick_id] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {}
botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["users"][target]) self.dict['disabled'][disabletype]["nick"][nick_id][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom}
elif botchannels.check_channel_bot(target, True): botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["nick"][target])
if target not in list(self.dict['disabled'][disabletype]["channels"].keys()): elif target_type == "channel":
self.dict['disabled'][disabletype]["channels"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {} target = str(target).lower()
self.dict['disabled'][disabletype]["channels"][target][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom} if target not in list(self.dict['disabled'][disabletype]["channel"].keys()):
botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channels"][target]) self.dict['disabled'][disabletype]["channel"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {}
self.dict['disabled'][disabletype]["channel"][target][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom}
botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channel"][target])
else: else:
raise Exception(str(target.lower()) + " appears to not be a valid user/channel") raise Exception(str(target.lower()) + " appears to not be a valid user/channel")
def unset_command_disabled(self, command, target, disabletype="fully"): def unset_command_disabled(self, command, target, disabletype="fully"):
disabletype = str(disabletype)
target_type = self.chan_or_nick(target)
if disabletype not in list(self.dict['disabled'].keys()): if disabletype not in list(self.dict['disabled'].keys()):
self.dict['disabled'][disabletype] = { self.dict['disabled'][disabletype] = {
"users": {}, "nick": {},
"channels": {} "channel": {}
} }
if botdb.check_nick_id(target): if target_type == "nick":
if target not in list(self.dict['disabled'][disabletype]["users"].keys()): nick_id = botusers.ID(target)
self.dict['disabled'][disabletype]["users"][target] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {} if nick_id not in list(self.dict['disabled'][disabletype]["nick"].keys()):
if command in list(self.dict['disabled'][disabletype]["users"].keys()): self.dict['disabled'][disabletype]["nick"][nick_id] = botdb.get_nick_value(target, 'commands_' + disabletype + 'disabled') or {}
del self.dict['disabled'][disabletype]["users"][target][command] if command in list(self.dict['disabled'][disabletype]["nick"].keys()):
botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["users"][target]) del self.dict['disabled'][disabletype]["nick"][nick_id][command]
elif botchannels.check_channel_bot(target, True): botdb.set_nick_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["nick"][target])
if target not in list(self.dict['disabled'][disabletype]["channels"].keys()): elif target_type == "channel":
self.dict['disabled'][disabletype]["users"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {} target = str(target).lower()
if command in list(self.dict['disabled'][disabletype]["channels"][target]): if target not in list(self.dict['disabled'][disabletype]["channel"].keys()):
del self.dict['disabled'][disabletype]["channels"][target][command] self.dict['disabled'][disabletype]["nick"][target] = botdb.get_channel_value(target, 'commands_' + disabletype + 'disabled') or {}
botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channels"][target]) if command in list(self.dict['disabled'][disabletype]["channel"][target]):
del self.dict['disabled'][disabletype]["channel"][target][command]
botdb.set_channel_value(target, 'commands_' + disabletype + 'disabled', self.dict['disabled'][disabletype]["channel"][target])
else: else:
raise Exception(str(target.lower()) + " appears to not be a valid user/channel") raise Exception(str(target.lower()) + " appears to not be a valid user/channel")

View File

@ -247,7 +247,7 @@ def trigger_runstatus_query(bot, trigger):
# don't run commands that are disabled in channels # don't run commands that are disabled in channels
if not trigger.is_privmsg: if not trigger.is_privmsg:
channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender), "fully") channel_disabled_list = botcommands.get_commands_disabled(str(trigger.sender))
if trigger.sb["realcomref"] in list(channel_disabled_list.keys()): if trigger.sb["realcomref"] in list(channel_disabled_list.keys()):
reason = channel_disabled_list[trigger.sb["realcomref"]]["reason"] reason = channel_disabled_list[trigger.sb["realcomref"]]["reason"]
timestamp = channel_disabled_list[trigger.sb["realcomref"]]["timestamp"] timestamp = channel_disabled_list[trigger.sb["realcomref"]]["timestamp"]
@ -256,7 +256,7 @@ def trigger_runstatus_query(bot, trigger):
return trigger_cant_run(bot, trigger, message) return trigger_cant_run(bot, trigger, message)
# don't run commands that are disabled for specific users # don't run commands that are disabled for specific users
nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick), "fully") nick_disabled_list = botcommands.get_commands_disabled(str(trigger.nick))
if trigger.sb["realcomref"] in list(nick_disabled_list.keys()): if trigger.sb["realcomref"] in list(nick_disabled_list.keys()):
bywhom = nick_disabled_list[trigger.sb["realcomref"]]["disabledby"] bywhom = nick_disabled_list[trigger.sb["realcomref"]]["disabledby"]
if botusers.ID(bywhom) != botusers.ID(trigger.nick): if botusers.ID(bywhom) != botusers.ID(trigger.nick):
@ -265,7 +265,7 @@ def trigger_runstatus_query(bot, trigger):
message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason) message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason)
return trigger_cant_run(bot, trigger, message) return trigger_cant_run(bot, trigger, message)
else: else:
botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick, "fully") botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick)
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick)) botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick))
return True return True