commands no longer needs bot

This commit is contained in:
deathbybandaid 2019-05-30 13:48:06 -04:00
parent f1b9b4df03
commit 72edc5f33c
4 changed files with 26 additions and 25 deletions

View File

@ -12,6 +12,7 @@ import threading
import spicemanip
from .Logs import logs
from .Config import config as botconfig
from .Database import db as botdb
@ -37,13 +38,13 @@ class BotCommands():
return commandstype
return None
def get_commands_disabled(self, bot, channel):
def get_commands_disabled(self, channel):
if not len(list(self.dict['disabled'])):
self.dict['disabled'] = botdb.get_channel_value(bot, channel, 'commands_disabled') or {}
self.dict['disabled'] = botdb.get_channel_value(channel, 'commands_disabled') or {}
return self.dict['disabled']
def check_commands_disabled(self, bot, command, channel):
if command in self.get_commands_disabled(bot, channel).keys():
def check_commands_disabled(self, command, channel):
if command in self.get_commands_disabled(channel).keys():
return True
else:
return False
@ -62,20 +63,20 @@ class BotCommands():
return realcom
def set_command_disabled(self, bot, command, channel, timestamp, reason, bywhom):
def set_command_disabled(self, command, channel, timestamp, reason, bywhom):
if not len(list(self.dict['disabled'])):
self.dict['disabled'] = botdb.get_channel_value(bot, channel, 'commands_disabled') or {}
self.dict['disabled'] = botdb.get_channel_value(channel, 'commands_disabled') or {}
self.dict['disabled'][command] = {"reason": reason, "timestamp": timestamp, "disabledby": bywhom}
botdb.set_channel_value(bot, channel, 'commands_disabled', self.dict['disabled'])
botdb.set_channel_value(channel, 'commands_disabled', self.dict['disabled'])
def unset_command_disabled(self, bot, command, channel):
def unset_command_disabled(self, command, channel):
if not len(list(self.dict['disabled'])):
self.dict['disabled'] = botdb.get_channel_value(bot, channel, 'commands_disabled') or {}
self.dict['disabled'] = botdb.get_channel_value(channel, 'commands_disabled') or {}
if command in self.dict['disabled'].keys():
del self.dict['disabled'][command]
botdb.set_channel_value(bot, channel, 'commands_disabled', self.dict['disabled'])
botdb.set_channel_value(channel, 'commands_disabled', self.dict['disabled'])
def register(self, bot, command_dict):
def register(self, command_dict):
self.lock.acquire()
@ -107,7 +108,7 @@ class BotCommands():
self.lock.release()
def module_directory_list(self, bot):
def module_directory_list(self):
filepathlisting = []
# main Modules directory
@ -116,7 +117,7 @@ class BotCommands():
filepathlisting.append(modules_dir)
# Home Directory
home_modules_dir = os.path.join(bot.config.homedir, 'modules')
home_modules_dir = os.path.join(botconfig.config.homedir, 'modules')
if os.path.isdir(home_modules_dir):
filepathlisting.append(home_modules_dir)
@ -131,13 +132,13 @@ class BotCommands():
logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
# Extra directories
for directory in bot.config.core.extra:
for directory in botconfig.dict["core"]["extra"]:
filepathlisting.append(directory)
return filepathlisting
def module_files_list(self, bot):
filepathlisting = self.module_directory_list(bot)
def module_files_list(self):
filepathlisting = self.module_directory_list()
filepathlist = []
@ -155,8 +156,8 @@ class BotCommands():
return filepathlist
def module_files_parse(self, bot):
filepathlist = self.module_files_list(bot)
def module_files_parse(self):
filepathlist = self.module_files_list()
for modulefile in filepathlist:
@ -226,7 +227,7 @@ class BotCommands():
if len(filelinelist):
for atlinefound in filelinelist:
self.register(bot, atlinefound)
self.register(atlinefound)
commands = BotCommands()

View File

@ -161,11 +161,11 @@ class BotPrerun():
bot.osd("This command must be run in a channel you which to enable it in.", trigger.nick, 'notice')
return
if not commands.check_commands_disabled(bot, trigger.sb["realcom"], trigger.sender):
if not commands.check_commands_disabled(trigger.sb["realcom"], trigger.sender):
bot.osd(trigger.sb["com"] + " is already enabled in " + str(trigger.sender), trigger.nick, 'notice')
return
commands.unset_command_disabled(bot, trigger.sb["realcom"], trigger.sender)
commands.unset_command_disabled(trigger.sb["realcom"], trigger.sender)
bot.osd(trigger.sb["com"] + " is now enabled in " + str(trigger.sender))
return
@ -179,14 +179,14 @@ class BotPrerun():
bot.osd("This command must be run in a channel you which to disable it in.", trigger.nick, 'notice')
return
if commands.check_commands_disabled(bot, trigger.sb["realcom"], trigger.sender):
if commands.check_commands_disabled(trigger.sb["realcom"], trigger.sender):
bot.osd(trigger.sb["com"] + " is already disabled in " + str(trigger.sender), trigger.nick, 'notice')
return
trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given."
timestamp = str(datetime.datetime.utcnow())
commands.set_command_disabled(bot, trigger.sb["realcom"], trigger.sender, timestamp, trailingmessage, trigger.nick)
commands.set_command_disabled(trigger.sb["realcom"], trigger.sender, timestamp, trailingmessage, trigger.nick)
bot.osd(trigger.sb["com"] + " is now disabled in " + str(trigger.sender))
return

View File

@ -75,7 +75,7 @@ def setup(bot):
"validcoms": validgifapi
}
SpiceBot.commands.dict['counts'] += 1
SpiceBot.commands.register(bot, command_dict)
SpiceBot.commands.register(command_dict)
if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys():
bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict()

View File

@ -12,7 +12,7 @@ def setup(bot):
SpiceBot.logs.log('SpiceBot_Commands', "Starting setup procedure")
SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDSQUERY])
SpiceBot.commands.module_files_parse(bot)
SpiceBot.commands.module_files_parse()
for comtype in ['module', 'nickname', 'rule']:
SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)