From 4e46bbc0a2c40d5dcf4b737c0adf8170773f5111 Mon Sep 17 00:00:00 2001 From: deathbybandaid Date: Wed, 22 May 2019 14:06:41 -0400 Subject: [PATCH] too many updates for one test, but oh well --- sopel_modules/SpiceBot/Channels.py | 8 + sopel_modules/SpiceBot/Commands.py | 154 ++++++++++++++++-- sopel_modules/SpiceBot/Events.py | 8 + sopel_modules/SpiceBot/Logs.py | 18 +- sopel_modules/SpiceBot_AI/AI.py | 15 -- .../{gifapi.py => Gif_API_Commands.py} | 0 .../{gif.py => Gif_Command.py} | 0 .../SpiceBot_GifSearch/Gif_Search_Commands | 34 ++++ sopel_modules/SpiceBot_GifSearch/__init__.py | 5 +- sopel_modules/SpiceBot_GifSearch/gifsearch.py | 7 +- .../SpiceBot_InvalidCommand/InvalidCommand.py | 42 ----- .../SpiceBot_InvalidCommand/__init__.py | 12 -- sopel_modules/SpiceBot_Logs/Logs_Command.py | 7 +- .../SpiceBot_Module_Parsing/ModuleParsing.py | 147 +---------------- 14 files changed, 221 insertions(+), 236 deletions(-) rename sopel_modules/SpiceBot_GifSearch/{gifapi.py => Gif_API_Commands.py} (100%) rename sopel_modules/SpiceBot_GifSearch/{gif.py => Gif_Command.py} (100%) create mode 100644 sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands delete mode 100644 sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py delete mode 100644 sopel_modules/SpiceBot_InvalidCommand/__init__.py diff --git a/sopel_modules/SpiceBot/Channels.py b/sopel_modules/SpiceBot/Channels.py index 37f0e6d..998ee55 100644 --- a/sopel_modules/SpiceBot/Channels.py +++ b/sopel_modules/SpiceBot/Channels.py @@ -5,11 +5,13 @@ This is the SpiceBot Channels system. """ import sopel import re +import threading class BotChannels(): """This Logs all channels known to the server""" def __init__(self): + self.lock = threading.Lock() self.channel_lock = False self.dict = { "list": {}, @@ -23,16 +25,20 @@ class BotChannels(): self.channel_lock = True def channel_list_recieve_input(self, trigger): + self.lock.acquire() channel, _, topic = trigger.args[1:] if channel.lower() not in self.dict['list'].keys(): self.dict['list'][channel.lower()] = dict() self.dict['list'][channel.lower()]['name'] = channel self.dict['list'][channel.lower()]['topic'] = self.topic_compile(topic) self.channel_lock = True + self.lock.release() def channel_list_recieve_finish(self): + self.lock.acquire() if not self.dict['InitialProcess']: self.dict['InitialProcess'] = True + self.lock.release() self.channel_lock = False def topic_compile(self, topic): @@ -49,7 +55,9 @@ class BotChannels(): if len(bot.channels[channel].privileges.keys()) == 1 and channel not in ignorepartlist and channel.startswith("#"): bot.part(channel, "Leaving Empty Channel") if channel.lower() in self.dict['list']: + self.lock.acquire() del self.dict['list'][channel.lower()] + self.lock.release() def join_all_channels(self, bot): if bot.config.SpiceBot_Channels.joinall: diff --git a/sopel_modules/SpiceBot/Commands.py b/sopel_modules/SpiceBot/Commands.py index d9e3293..dbdc57d 100644 --- a/sopel_modules/SpiceBot/Commands.py +++ b/sopel_modules/SpiceBot/Commands.py @@ -5,13 +5,19 @@ This is the SpiceBot Commands system. This Class stores commands in an easy to access manner """ +import sopel +import os +import threading import spicemanip +from .Logs import logs + class BotCommands(): """This Logs all commands known to the bot""" def __init__(self): + self.lock = threading.Lock() self.dict = { "counts": 0, "commands": { @@ -19,17 +25,20 @@ class BotCommands(): 'nickname': {}, 'rule': {} }, - "nickrules": [] } - def commandsquery_register(self, bot, command_type, validcoms, aliasfor=None): + def register(self, bot, command_dict): + + self.lock.acquire() + + command_type = command_dict["comtype"] + validcoms = command_dict["validcoms"] if not isinstance(validcoms, list): validcoms = [validcoms] if command_type not in self.dict['commands'].keys(): self.dict['commands'][command_type] = dict() - self.dict['counts'] += 1 dict_from_file = dict() @@ -37,20 +46,139 @@ class BotCommands(): if "validcoms" not in dict_from_file.keys(): dict_from_file["validcoms"] = validcoms - if not aliasfor: - - maincom = dict_from_file["validcoms"][0] - if len(dict_from_file["validcoms"]) > 1: - comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') - else: - comaliases = [] - self.dict['commands'][command_type][maincom] = dict_from_file + maincom = dict_from_file["validcoms"][0] + if len(dict_from_file["validcoms"]) > 1: + comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') else: - comaliases = validcoms + comaliases = [] + self.dict['commands'][command_type][maincom] = dict_from_file for comalias in comaliases: if comalias not in self.dict['commands'][command_type].keys(): - self.dict['commands'][command_type][comalias] = {"aliasfor": aliasfor} + self.dict['commands'][command_type][comalias] = {"aliasfor": maincom} + + self.lock.release() + + def module_directory_list(self, bot): + filepathlisting = [] + + # main Modules directory + main_dir = os.path.dirname(os.path.abspath(sopel.__file__)) + modules_dir = os.path.join(main_dir, 'modules') + filepathlisting.append(modules_dir) + + # Home Directory + home_modules_dir = os.path.join(bot.config.homedir, 'modules') + if os.path.isdir(home_modules_dir): + filepathlisting.append(home_modules_dir) + + # pypi installed + try: + import sopel_modules + for plugin_dir in set(sopel_modules.__path__): + for pathname in os.listdir(plugin_dir): + pypi_modules_dir = os.path.join(plugin_dir, pathname) + filepathlisting.append(pypi_modules_dir) + except Exception as e: + logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e)) + + # Extra directories + for directory in bot.config.core.extra: + filepathlisting.append(directory) + + return filepathlisting + + def module_files_list(self, bot): + filepathlisting = self.module_directory_list(bot) + + filepathlist = [] + + for directory in filepathlisting: + for pathname in os.listdir(directory): + path = os.path.join(directory, pathname) + if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')): + if pathname not in ["SpiceBot_dummycommand.py"]: + filepathlist.append(str(path)) + + # CoreTasks + main_dir = os.path.dirname(os.path.abspath(sopel.__file__)) + ct_path = os.path.join(main_dir, 'coretasks.py') + filepathlist.append(ct_path) + + return filepathlist + + def module_files_parse(self, bot): + filepathlist = self.module_files_list(bot) + + for modulefile in filepathlist: + + module_file_lines = [] + module_file = open(modulefile, 'r') + lines = module_file.readlines() + for line in lines: + module_file_lines.append(line) + module_file.close() + + detected_lines = [] + for line in module_file_lines: + + if str(line).startswith("@"): + line = str(line)[1:] + + if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])): + line = str(line).split("commands")[-1] + line = "commands" + line + detected_lines.append(line) + elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])): + line = str(line).split("nickname_commands")[-1] + line = "nickname_commands" + line + detected_lines.append(line) + elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): + line = str(line).split("rule")[-1] + line = "rule" + line + else: + line = None + + if line: + detected_lines.append(line) + + if len(detected_lines): + + filelinelist = [] + currentsuccesslines = 0 + for detected_line in detected_lines: + + # Commands + if str(detected_line).startswith("commands"): + comtype = "module" + validcoms = eval(str(detected_line).split("commands")[-1]) + elif str(detected_line).startswith("nickname_commands"): + comtype = "nickname" + validcoms = eval(str(detected_line).split("nickname_commands")[-1]) + elif str(detected_line).startswith("rule"): + comtype = "rule" + validcoms = eval(str(detected_line).split("rule")[-1]) + + if isinstance(validcoms, tuple): + validcoms = list(validcoms) + else: + validcoms = [validcoms] + for regexcom in ["(.*)", '^\?(.*)']: + if regexcom in validcoms: + while regexcom in validcoms: + validcoms.remove(regexcom) + + if len(validcoms): + validcomdict = {"comtype": comtype, "validcoms": validcoms} + filelinelist.append(validcomdict) + currentsuccesslines += 1 + + if currentsuccesslines: + self.dict['counts'] += 1 + + if len(filelinelist): + for atlinefound in filelinelist: + self.register(bot, atlinefound) commands = BotCommands() diff --git a/sopel_modules/SpiceBot/Events.py b/sopel_modules/SpiceBot/Events.py index 96185d0..9337192 100644 --- a/sopel_modules/SpiceBot/Events.py +++ b/sopel_modules/SpiceBot/Events.py @@ -10,6 +10,7 @@ self-trigger the bot into performing actions import sopel import functools +import threading class BotEvents(object): @@ -26,6 +27,7 @@ class BotEvents(object): """ def __init__(self): + self.lock = threading.Lock() self.RPL_WELCOME = '001' # This is a defined IRC event self.BOT_WELCOME = '1001' self.BOT_READY = '1002' @@ -43,9 +45,11 @@ class BotEvents(object): def __getattr__(self, name): ''' will only get called for undefined attributes ''' + self.lock.acquire() eventnumber = max(list(self.dict["assigned_IDs"].keys())) + 1 self.dict["assigned_IDs"][eventnumber] = str(name) setattr(self, name, str(eventnumber)) + self.lock.release() return str(eventnumber) def trigger(self, bot, number, message="SpiceBot_Events"): @@ -66,6 +70,7 @@ class BotEvents(object): self.recieved({"number": number, "message": message}) def recieved(self, trigger): + self.lock.acquire() if isinstance(trigger, dict): eventnumber = str(trigger["number"]) message = str(trigger["message"]) @@ -75,6 +80,7 @@ class BotEvents(object): if eventnumber not in self.dict["triggers_recieved"]: self.dict["triggers_recieved"][eventnumber] = [] self.dict["triggers_recieved"][eventnumber].append(message) + self.lock.release() def check(self, checklist): if not isinstance(checklist, list): @@ -85,9 +91,11 @@ class BotEvents(object): return True def startup_add(self, startlist): + self.lock.acquire() if not isinstance(startlist, list): startlist = [str(startlist)] self.dict["startup_required"].extend(startlist) + self.lock.release() def startup_check(self): for number in self.dict["startup_required"]: diff --git a/sopel_modules/SpiceBot/Logs.py b/sopel_modules/SpiceBot/Logs.py index 9927d09..0b13058 100644 --- a/sopel_modules/SpiceBot/Logs.py +++ b/sopel_modules/SpiceBot/Logs.py @@ -6,8 +6,8 @@ This is the SpiceBot Logs system. This Class stores logs in an easy to access manner """ - import sopel +import threading import os import spicemanip @@ -15,6 +15,7 @@ import spicemanip class BotLogs(): """This Is a contained source of log information""" def __init__(self): + self.lock = threading.Lock() self.dict = { "list": {"Sopel_systemd": [], "Sopel_stdio": []}, "queue": [] @@ -24,6 +25,9 @@ class BotLogs(): } def log(self, logtype, logentry, stdio=False): + + self.lock.acquire() + logtitle = "[" + logtype + "]" logmessage = logtitle + " " + logentry @@ -37,8 +41,16 @@ class BotLogs(): self.dict["list"][logtype] = [] self.dict["list"][logtype].append(logentry) - def get_logs(self): - return [] + self.lock.release() + + def get_logs(self, bot, logtype): + if logtype == "Sopel_systemd": + logindex = self.systemd_logs_fetch(bot) + elif logtype == "Sopel_stdio": + logindex = self.stdio_logs_fetch(bot) + else: + logindex = self.dict["list"][logtype] + return logindex def stdio_logs_fetch(self, bot): diff --git a/sopel_modules/SpiceBot_AI/AI.py b/sopel_modules/SpiceBot_AI/AI.py index 593b8c9..3d2a6ae 100644 --- a/sopel_modules/SpiceBot_AI/AI.py +++ b/sopel_modules/SpiceBot_AI/AI.py @@ -27,9 +27,6 @@ def bot_command_nick(bot, trigger): fulltrigger = spicemanip.main(triggerargs, 0).lower() - if fulltrigger in SpiceBot.commands.dict['nickrules']: - return - if fulltrigger.lower().startswith("what is"): searchterm = spicemanip.main(triggerargs, "3+") or None if searchterm: @@ -151,15 +148,3 @@ def bot_command_nick(bot, trigger): # bot.osd("I have never seen " + str(target) + ".") # TODO return - - else: - - closestmatches = SpiceBot.similar_list(bot, triggercommand, SpiceBot.commands.dict['commands']["nickname"].keys(), 3, 'reverse') - - if len(closestmatches): - closestmatches = spicemanip.main(closestmatches, "andlist") - bot.osd("I don't know what you are asking me to do! Did you mean: " + str(closestmatches) + "?") - return - else: - bot.osd("I don't know what you are asking me to do!") - return diff --git a/sopel_modules/SpiceBot_GifSearch/gifapi.py b/sopel_modules/SpiceBot_GifSearch/Gif_API_Commands.py similarity index 100% rename from sopel_modules/SpiceBot_GifSearch/gifapi.py rename to sopel_modules/SpiceBot_GifSearch/Gif_API_Commands.py diff --git a/sopel_modules/SpiceBot_GifSearch/gif.py b/sopel_modules/SpiceBot_GifSearch/Gif_Command.py similarity index 100% rename from sopel_modules/SpiceBot_GifSearch/gif.py rename to sopel_modules/SpiceBot_GifSearch/Gif_Command.py diff --git a/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands b/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands new file mode 100644 index 0000000..dc119cd --- /dev/null +++ b/sopel_modules/SpiceBot_GifSearch/Gif_Search_Commands @@ -0,0 +1,34 @@ +# coding=utf-8 + +from __future__ import unicode_literals, absolute_import, division, print_function + +from .gifsearch import getGif + +import sopel.module + +import spicemanip + +import sopel_modules.SpiceBot as SpiceBot + + +@SpiceBot.events.check_ready([SpiceBot.events.BOT_GIFSEARCH]) +@sopel.module.commands('(.*)') +def gifapi_triggers(bot, trigger): + + triggerargs, triggercommand = SpiceBot.sopel_triggerargs(bot, trigger, 'prefix_command') + + if triggercommand not in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): + return + + if not len(triggerargs): + return bot.osd("Please present a query to search.") + + query = spicemanip.main(triggerargs, 0) + searchdict = {"query": query, "gifsearch": triggercommand} + + gifdict = getGif(bot, searchdict) + + if gifdict["error"]: + bot.osd(gifdict["error"]) + else: + bot.osd(str(gifdict['gifapi'].title() + " Result (" + str(query) + " #" + str(gifdict["returnnum"]) + "): " + str(gifdict["returnurl"]))) diff --git a/sopel_modules/SpiceBot_GifSearch/__init__.py b/sopel_modules/SpiceBot_GifSearch/__init__.py index 841b583..c91a38a 100644 --- a/sopel_modules/SpiceBot_GifSearch/__init__.py +++ b/sopel_modules/SpiceBot_GifSearch/__init__.py @@ -5,8 +5,9 @@ Sopel Gif Search builds a convenient framework for searching for Gifs """ from __future__ import unicode_literals, absolute_import, division, print_function -from .gif import * -from .gifapi import * +from .Gif_Command import * +from .Gif_API_Commands import * +# from .Gif_Search_Commands import * from .gifsearch import * __author__ = 'Sam Zick' diff --git a/sopel_modules/SpiceBot_GifSearch/gifsearch.py b/sopel_modules/SpiceBot_GifSearch/gifsearch.py index 75e84d9..a63bf93 100644 --- a/sopel_modules/SpiceBot_GifSearch/gifsearch.py +++ b/sopel_modules/SpiceBot_GifSearch/gifsearch.py @@ -70,7 +70,12 @@ def setup(bot): bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'][gif_api] = valid_gif_api_dict[gif_api] for validgifapi in bot.memory["SpiceBot_GifSearch"]['valid_gif_api_dict'].keys(): - SpiceBot.commands.commandsquery_register(bot, "prefix", validgifapi) + command_dict = { + "comtype": "prefix", + "validcoms": validgifapi + } + SpiceBot.commands.dict['counts'] += 1 + SpiceBot.commands.register(bot, command_dict) if validgifapi not in bot.memory["SpiceBot_GifSearch"]['cache'].keys(): bot.memory["SpiceBot_GifSearch"]['cache'][validgifapi] = dict() diff --git a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py b/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py deleted file mode 100644 index 63c18f5..0000000 --- a/sopel_modules/SpiceBot_InvalidCommand/InvalidCommand.py +++ /dev/null @@ -1,42 +0,0 @@ -# coding=utf-8 - -from __future__ import unicode_literals, absolute_import, division, print_function - -import sopel.module - -import sopel_modules.SpiceBot as SpiceBot - - -def setup(bot): - if 'SpiceBot_InvalidCommand' not in bot.memory: - bot.memory["SpiceBot_InvalidCommand"] = {"valid": []} - - -def shutdown(bot): - if "SpiceBot_InvalidCommand" in bot.memory: - del bot.memory["SpiceBot_InvalidCommand"] - - -@sopel.module.event(SpiceBot.events.BOT_LOADED) -@sopel.module.rule('.*') -def bot_events_complete(bot, trigger): - for comtype in SpiceBot.commands.dict['commands'].keys(): - bot.memory["SpiceBot_InvalidCommand"]["valid"].extend(SpiceBot.commands.dict['commands'][comtype].keys()) - - -@SpiceBot.events.check_ready([SpiceBot.events.BOT_LOADED, SpiceBot.events.BOT_COMMANDSQUERY]) -@sopel.module.commands('(.*)') -def InvalidCommand_triggers(bot, trigger): - return - - triggerargs, triggercommand = SpiceBot.sopel_triggerargs(bot, trigger, 'prefix_command') - - # patch for people typing "...", maybe other stuff, but this verifies that there is still a command here - if triggercommand.startswith("."): - return - - if triggercommand not in bot.memory["SpiceBot_InvalidCommand"]["valid"]: - invalid_display = ["I don't seem to have a command for " + str(triggercommand) + "!"] - invalid_display.append("If you have a suggestion for this command, you can run .feature ." + str(triggercommand)) - invalid_display.append("ADD DESCRIPTION HERE!") - bot.osd(invalid_display, trigger.nick, 'notice') diff --git a/sopel_modules/SpiceBot_InvalidCommand/__init__.py b/sopel_modules/SpiceBot_InvalidCommand/__init__.py deleted file mode 100644 index 6f704e6..0000000 --- a/sopel_modules/SpiceBot_InvalidCommand/__init__.py +++ /dev/null @@ -1,12 +0,0 @@ -# coding=utf8 -"""Sopel Gif Search - -Sopel Gif Search builds a convenient framework for searching for Gifs -""" -from __future__ import unicode_literals, absolute_import, division, print_function - -from .InvalidCommand import * - -__author__ = 'Sam Zick' -__email__ = 'sam@deathbybandaid.net' -__version__ = '0.1.1' diff --git a/sopel_modules/SpiceBot_Logs/Logs_Command.py b/sopel_modules/SpiceBot_Logs/Logs_Command.py index 6c42b3f..46f3322 100644 --- a/sopel_modules/SpiceBot_Logs/Logs_Command.py +++ b/sopel_modules/SpiceBot_Logs/Logs_Command.py @@ -34,12 +34,7 @@ def bot_command_logs(bot, trigger): logtype = SpiceBot.inlist_match(logtype, SpiceBot.logs.dict["list"].keys()) - if logtype == "Sopel_systemd": - logindex = SpiceBot.logs.systemd_logs_fetch(bot) - elif logtype == "Sopel_stdio": - logindex = SpiceBot.logs.stdio_logs_fetch(bot) - else: - logindex = SpiceBot.logs.dict["list"][logtype] + logindex = SpiceBot.logs.get_logs(bot, logtype) if not len(logindex): bot.osd("No logs found for " + str(logtype) + ".") diff --git a/sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py b/sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py index 01a90b9..0802d4f 100644 --- a/sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py +++ b/sopel_modules/SpiceBot_Module_Parsing/ModuleParsing.py @@ -5,156 +5,19 @@ from __future__ import unicode_literals, absolute_import, division, print_functi import sopel import sopel.module -import os - import sopel_modules.SpiceBot as SpiceBot -import spicemanip - def setup(bot): - SpiceBot.logs.log('SpiceBot_CommandsQuery', "Starting setup procedure") + SpiceBot.logs.log('SpiceBot_Commands', "Starting setup procedure") SpiceBot.events.startup_add([SpiceBot.events.BOT_COMMANDSQUERY]) - filepathlisting = [] - - # main Modules directory - main_dir = os.path.dirname(os.path.abspath(sopel.__file__)) - modules_dir = os.path.join(main_dir, 'modules') - filepathlisting.append(modules_dir) - - # Home Directory - home_modules_dir = os.path.join(bot.config.homedir, 'modules') - if os.path.isdir(home_modules_dir): - filepathlisting.append(home_modules_dir) - - # pypi installed - try: - import sopel_modules - for plugin_dir in set(sopel_modules.__path__): - for pathname in os.listdir(plugin_dir): - pypi_modules_dir = os.path.join(plugin_dir, pathname) - filepathlisting.append(pypi_modules_dir) - except Exception as e: - SpiceBot.logs.log('SpiceBot_CommandsQuery', "sopel_modules not loaded :" + str(e)) - - # Extra directories - filepathlist = [] - for directory in bot.config.core.extra: - filepathlisting.append(directory) - - for directory in filepathlisting: - for pathname in os.listdir(directory): - path = os.path.join(directory, pathname) - if (os.path.isfile(path) and path.endswith('.py') and not path.startswith('_')): - if pathname not in ["SpiceBot_dummycommand.py"]: - filepathlist.append(str(path)) - - # CoreTasks - ct_path = os.path.join(main_dir, 'coretasks.py') - filepathlist.append(ct_path) - - for modulefile in filepathlist: - - module_file_lines = [] - module_file = open(modulefile, 'r') - lines = module_file.readlines() - for line in lines: - module_file_lines.append(line) - module_file.close() - - dict_from_file = dict() - - detected_lines = [] - for line in module_file_lines: - - if str(line).startswith("@"): - line = str(line)[1:] - - if str(line).startswith(tuple(["commands", "module.commands", "sopel.module.commands"])): - line = str(line).split("commands")[-1] - line = "commands" + line - detected_lines.append(line) - elif str(line).startswith(tuple(["nickname_commands", "module.nickname_commands", "sopel.module.nickname_commands"])): - line = str(line).split("nickname_commands")[-1] - line = "nickname_commands" + line - detected_lines.append(line) - elif str(line).startswith(tuple(["rule", "module.rule", "sopel.module.rule"])): - line = str(line).split("rule")[-1] - line = "rule" + line - else: - line = None - - if line: - detected_lines.append(line) - - if len(detected_lines): - - filelinelist = [] - currentsuccesslines = 0 - for detected_line in detected_lines: - - # Commands - if str(detected_line).startswith("commands"): - comtype = "module" - validcoms = eval(str(detected_line).split("commands")[-1]) - elif str(detected_line).startswith("nickname_commands"): - comtype = "nickname" - validcoms = eval(str(detected_line).split("nickname_commands")[-1]) - elif str(detected_line).startswith("rule"): - comtype = "rule" - validcoms = eval(str(detected_line).split("rule")[-1]) - - if isinstance(validcoms, tuple): - validcoms = list(validcoms) - else: - validcoms = [validcoms] - for regexcom in ["(.*)", '^\?(.*)']: - if regexcom in validcoms: - while regexcom in validcoms: - validcoms.remove(regexcom) - - if len(validcoms): - validcomdict = {"comtype": comtype, "validcoms": validcoms} - filelinelist.append(validcomdict) - currentsuccesslines += 1 - - if currentsuccesslines: - SpiceBot.commands.dict['counts'] += 1 - - if len(filelinelist): - for atlinefound in filelinelist: - - dict_from_file = dict() - - comtype = atlinefound["comtype"] - validcoms = atlinefound["validcoms"] - - # default command to filename - if "validcoms" not in dict_from_file.keys(): - dict_from_file["validcoms"] = validcoms - - maincom = dict_from_file["validcoms"][0] - if len(dict_from_file["validcoms"]) > 1: - comaliases = spicemanip.main(dict_from_file["validcoms"], '2+', 'list') - else: - comaliases = [] - - SpiceBot.commands.dict['commands'][comtype][maincom] = dict_from_file - for comalias in comaliases: - if comalias not in SpiceBot.commands.dict['commands'][comtype].keys(): - SpiceBot.commands.dict['commands'][comtype][comalias] = {"aliasfor": maincom} + SpiceBot.commands.module_files_parse(bot) for comtype in ['module', 'nickname', 'rule']: - SpiceBot.logs.log('SpiceBot_CommandsQuery', "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) - for command in SpiceBot.commands.dict['commands']['rule'].keys(): - if command.startswith("$nickname"): - command = command.split("$nickname")[-1] - if command not in SpiceBot.commands.dict['nickrules']: - SpiceBot.commands.dict['nickrules'].append(command) - - SpiceBot.events.trigger(bot, SpiceBot.events.BOT_COMMANDSQUERY, "SpiceBot_CommandsQuery") + SpiceBot.events.trigger(bot, SpiceBot.events.BOT_COMMANDSQUERY, "SpiceBot_Commands") @sopel.module.event(SpiceBot.events.BOT_LOADED) @@ -163,4 +26,4 @@ def bot_events_complete(bot, trigger): for comtype in SpiceBot.commands.dict['commands'].keys(): if comtype not in ['module', 'nickname', 'rule']: - SpiceBot.logs.log('SpiceBot_CommandsQuery', "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)