mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
commands no longer needs bot
This commit is contained in:
parent
f1b9b4df03
commit
72edc5f33c
@ -12,6 +12,7 @@ import threading
|
|||||||
import spicemanip
|
import spicemanip
|
||||||
|
|
||||||
from .Logs import logs
|
from .Logs import logs
|
||||||
|
from .Config import config as botconfig
|
||||||
from .Database import db as botdb
|
from .Database import db as botdb
|
||||||
|
|
||||||
|
|
||||||
@ -37,13 +38,13 @@ class BotCommands():
|
|||||||
return commandstype
|
return commandstype
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_commands_disabled(self, bot, channel):
|
def get_commands_disabled(self, channel):
|
||||||
if not len(list(self.dict['disabled'])):
|
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']
|
return self.dict['disabled']
|
||||||
|
|
||||||
def check_commands_disabled(self, bot, command, channel):
|
def check_commands_disabled(self, command, channel):
|
||||||
if command in self.get_commands_disabled(bot, channel).keys():
|
if command in self.get_commands_disabled(channel).keys():
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
@ -62,20 +63,20 @@ class BotCommands():
|
|||||||
|
|
||||||
return realcom
|
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'])):
|
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}
|
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'])):
|
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():
|
if command in self.dict['disabled'].keys():
|
||||||
del self.dict['disabled'][command]
|
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()
|
self.lock.acquire()
|
||||||
|
|
||||||
@ -107,7 +108,7 @@ class BotCommands():
|
|||||||
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
|
|
||||||
def module_directory_list(self, bot):
|
def module_directory_list(self):
|
||||||
filepathlisting = []
|
filepathlisting = []
|
||||||
|
|
||||||
# main Modules directory
|
# main Modules directory
|
||||||
@ -116,7 +117,7 @@ class BotCommands():
|
|||||||
filepathlisting.append(modules_dir)
|
filepathlisting.append(modules_dir)
|
||||||
|
|
||||||
# Home Directory
|
# 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):
|
if os.path.isdir(home_modules_dir):
|
||||||
filepathlisting.append(home_modules_dir)
|
filepathlisting.append(home_modules_dir)
|
||||||
|
|
||||||
@ -131,13 +132,13 @@ class BotCommands():
|
|||||||
logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
|
logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e))
|
||||||
|
|
||||||
# Extra directories
|
# Extra directories
|
||||||
for directory in bot.config.core.extra:
|
for directory in botconfig.dict["core"]["extra"]:
|
||||||
filepathlisting.append(directory)
|
filepathlisting.append(directory)
|
||||||
|
|
||||||
return filepathlisting
|
return filepathlisting
|
||||||
|
|
||||||
def module_files_list(self, bot):
|
def module_files_list(self):
|
||||||
filepathlisting = self.module_directory_list(bot)
|
filepathlisting = self.module_directory_list()
|
||||||
|
|
||||||
filepathlist = []
|
filepathlist = []
|
||||||
|
|
||||||
@ -155,8 +156,8 @@ class BotCommands():
|
|||||||
|
|
||||||
return filepathlist
|
return filepathlist
|
||||||
|
|
||||||
def module_files_parse(self, bot):
|
def module_files_parse(self):
|
||||||
filepathlist = self.module_files_list(bot)
|
filepathlist = self.module_files_list()
|
||||||
|
|
||||||
for modulefile in filepathlist:
|
for modulefile in filepathlist:
|
||||||
|
|
||||||
@ -226,7 +227,7 @@ class BotCommands():
|
|||||||
|
|
||||||
if len(filelinelist):
|
if len(filelinelist):
|
||||||
for atlinefound in filelinelist:
|
for atlinefound in filelinelist:
|
||||||
self.register(bot, atlinefound)
|
self.register(atlinefound)
|
||||||
|
|
||||||
|
|
||||||
commands = BotCommands()
|
commands = BotCommands()
|
||||||
|
|||||||
@ -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')
|
bot.osd("This command must be run in a channel you which to enable it in.", trigger.nick, 'notice')
|
||||||
return
|
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')
|
bot.osd(trigger.sb["com"] + " is already enabled in " + str(trigger.sender), trigger.nick, 'notice')
|
||||||
return
|
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))
|
bot.osd(trigger.sb["com"] + " is now enabled in " + str(trigger.sender))
|
||||||
return
|
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')
|
bot.osd("This command must be run in a channel you which to disable it in.", trigger.nick, 'notice')
|
||||||
return
|
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')
|
bot.osd(trigger.sb["com"] + " is already disabled in " + str(trigger.sender), trigger.nick, 'notice')
|
||||||
return
|
return
|
||||||
|
|
||||||
trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given."
|
trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given."
|
||||||
timestamp = str(datetime.datetime.utcnow())
|
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))
|
bot.osd(trigger.sb["com"] + " is now disabled in " + str(trigger.sender))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,7 @@ def setup(bot):
|
|||||||
"validcoms": validgifapi
|
"validcoms": validgifapi
|
||||||
}
|
}
|
||||||
SpiceBot.commands.dict['counts'] += 1
|
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():
|
if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys():
|
||||||
bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict()
|
bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict()
|
||||||
|
|||||||
@ -12,7 +12,7 @@ def setup(bot):
|
|||||||
SpiceBot.logs.log('SpiceBot_Commands', "Starting setup procedure")
|
SpiceBot.logs.log('SpiceBot_Commands', "Starting setup procedure")
|
||||||
SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDSQUERY])
|
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']:
|
for comtype in ['module', 'nickname', 'rule']:
|
||||||
SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
SpiceBot.logs.log('SpiceBot_Commands', "Found " + str(len(SpiceBot.commands.dict['commands'][comtype].keys())) + " " + comtype + " commands.", True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user