new attempt

This commit is contained in:
deathbybandaid 2019-05-23 17:55:48 -04:00
parent 1a5ef76dc1
commit d56d8d9261
2 changed files with 32 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import threading
import spicemanip import spicemanip
from .Logs import logs from .Logs import logs
from .Database import db as spicedb
class BotCommands(): class BotCommands():
@ -25,6 +26,7 @@ class BotCommands():
'nickname': {}, 'nickname': {},
'rule': {} 'rule': {}
}, },
'disabled': {}
} }
def find_command_type(self, command): def find_command_type(self, command):
@ -35,6 +37,30 @@ class BotCommands():
return commandstype return commandstype
return None return None
def get_disabled_commands(self, bot, channel):
if not len(list(self.dict['disabled'])):
self.dict['disabled'] = spicedb.get_channel_value(bot, channel, 'disabled_commands', 'commands') or {}
return self.dict['disabled']
def check_disabled_commands(self, bot, command, channel):
if command in self.get_disabled_commands(self, bot, channel).keys():
return True
else:
return False
def set_command_disabled(self, bot, command, channel, timestamp, reason, bywhom):
if not len(list(self.dict['disabled'])):
self.dict['disabled'] = spicedb.get_channel_value(bot, channel, 'disabled_commands', 'commands') or {}
self.dict['disabled'][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom}
spicedb.set_channel_value(bot, channel, 'disabled_commands', self.dict['disabled'], 'commands')
def unset_command_disabled(self, bot, command, channel):
if not len(list(self.dict['disabled'])):
self.dict['disabled'] = spicedb.get_channel_value(bot, channel, 'disabled_commands', 'commands') or {}
if command in self.dict['disabled'].keys():
del self.dict['disabled'][command]
spicedb.set_channel_value(bot, channel, 'disabled_commands', self.dict['disabled'], 'commands')
def register(self, bot, command_dict): def register(self, bot, command_dict):
self.lock.acquire() self.lock.acquire()

View File

@ -53,13 +53,14 @@ class BotPrerun():
# Run the function for all splits # Run the function for all splits
for argsdict in argsdict_list: for argsdict in argsdict_list:
trigger.sb = argsdict
if len(argsdict["hyphen_args"]): if len(argsdict["hyphen_args"]):
self.hyphen_arg_handler(bot, trigger, argsdict) self.hyphen_arg_handler(bot, trigger, argsdict)
argsdict["hyphen_args"] = []
# check if anything prohibits the nick from running the command # check if anything prohibits the nick from running the command
if self.runstatus(bot, trigger, argsdict): if self.runstatus(bot, trigger, argsdict):
trigger.sb = argsdict
function(bot, trigger, *args, **kwargs) function(bot, trigger, *args, **kwargs)
return return
return internal_prerun return internal_prerun
@ -124,14 +125,11 @@ class BotPrerun():
bot.notice("This command must be run in a channel you which to enable it in.", trigger.nick) bot.notice("This command must be run in a channel you which to enable it in.", trigger.nick)
return return
disabled_list = spicedb.get_channel_value(bot, trigger.sender, 'disabled_commands', 'commands') or {} if not commands.check_disabled_commands(self, bot, argsdict["realcom"], trigger.sender):
if argsdict["realcom"] not in disabled_list.keys():
bot.notice(argsdict["com"] + " is already enabled in " + str(trigger.sender), trigger.nick) bot.notice(argsdict["com"] + " is already enabled in " + str(trigger.sender), trigger.nick)
return return
del disabled_list[argsdict["realcom"]] commands.unset_command_disabled(bot, argsdict["realcom"], trigger.sender)
spicedb.set_channel_value(bot, trigger.sender, 'disabled_commands', disabled_list, 'commands')
bot.say(argsdict["com"] + " is now enabled in " + str(trigger.sender)) bot.say(argsdict["com"] + " is now enabled in " + str(trigger.sender))
return return
@ -145,19 +143,14 @@ class BotPrerun():
bot.notice("This command must be run in a channel you which to disable it in.", trigger.nick) bot.notice("This command must be run in a channel you which to disable it in.", trigger.nick)
return return
disabled_list = spicedb.get_channel_value(bot, trigger.sender, 'disabled_commands', 'commands') or {} if commands.check_disabled_commands(self, bot, argsdict["realcom"], trigger.sender):
if argsdict["realcom"] in disabled_list.keys():
bot.notice(argsdict["com"] + " is already disabled in " + str(trigger.sender), trigger.nick) bot.notice(argsdict["com"] + " is already disabled in " + str(trigger.sender), trigger.nick)
return return
trailingmessage = spicemanip.main(argsdict["args"], 0) or "No reason given." trailingmessage = spicemanip.main(argsdict["args"], 0) or "No reason given."
timestamp = str(datetime.datetime.utcnow()) timestamp = str(datetime.datetime.utcnow())
disabled_list[argsdict["realcom"]] = {"reason": trailingmessage, "timestamp": timestamp, "disabledby": trigger.nick} commands.set_command_disabled(self, bot, argsdict["realcom"], trigger.sender, timestamp, trailingmessage, trigger.nick)
spicedb.set_channel_value(bot, trigger.sender, 'disabled_commands', disabled_list, 'commands')
spicedb.adjust_channel_list(bot, trigger.sender, 'disabled_commands', argsdict["realcom"], 'add', 'commands')
bot.say(argsdict["com"] + " is now disabled in " + str(trigger.sender)) bot.say(argsdict["com"] + " is now disabled in " + str(trigger.sender))
return return