mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-12 22:49:53 -05:00
ready for live testing maybe
This commit is contained in:
parent
23faf6e4d2
commit
f1cbe5edba
@ -13,10 +13,12 @@ import os
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
import spicemanip
|
import spicemanip
|
||||||
|
import sopel_modules
|
||||||
|
|
||||||
from .Logs import logs
|
from .Logs import logs
|
||||||
from .Config import config as botconfig
|
from .Config import config as botconfig
|
||||||
from .Database import db as botdb
|
from .Database import db as botdb
|
||||||
|
from .Read import read as botread
|
||||||
|
|
||||||
|
|
||||||
class SpiceBot_Commands_MainSection(StaticSection):
|
class SpiceBot_Commands_MainSection(StaticSection):
|
||||||
@ -29,7 +31,6 @@ class BotCommands():
|
|||||||
self.setup_commands()
|
self.setup_commands()
|
||||||
self.lock = threading.Lock()
|
self.lock = threading.Lock()
|
||||||
self.dict = {
|
self.dict = {
|
||||||
"counts": 0,
|
|
||||||
'nickrules': [],
|
'nickrules': [],
|
||||||
'nickaiml': [],
|
'nickaiml': [],
|
||||||
"commands": {
|
"commands": {
|
||||||
@ -145,14 +146,10 @@ class BotCommands():
|
|||||||
filepathlisting.append(home_modules_dir)
|
filepathlisting.append(home_modules_dir)
|
||||||
|
|
||||||
# pypi installed
|
# pypi installed
|
||||||
try:
|
for plugin_dir in set(sopel_modules.__path__):
|
||||||
import sopel_modules
|
for pathname in os.listdir(plugin_dir):
|
||||||
for plugin_dir in set(sopel_modules.__path__):
|
pypi_modules_dir = os.path.join(plugin_dir, pathname)
|
||||||
for pathname in os.listdir(plugin_dir):
|
filepathlisting.append(pypi_modules_dir)
|
||||||
pypi_modules_dir = os.path.join(plugin_dir, pathname)
|
|
||||||
filepathlisting.append(pypi_modules_dir)
|
|
||||||
except Exception as e:
|
|
||||||
logs.log('SpiceBOT_COMMANDS', "sopel_modules not loaded :" + str(e))
|
|
||||||
|
|
||||||
# Extra directories
|
# Extra directories
|
||||||
for directory in botconfig.extra:
|
for directory in botconfig.extra:
|
||||||
@ -198,6 +195,15 @@ class BotCommands():
|
|||||||
folderpath = str(modulefile).split("/" + filename)[0]
|
folderpath = str(modulefile).split("/" + filename)[0]
|
||||||
foldername = str(folderpath).split("/")[-1]
|
foldername = str(folderpath).split("/")[-1]
|
||||||
|
|
||||||
|
# check for json reference file
|
||||||
|
validcomdict = botread.module_json_to_dict(str(modulefile))
|
||||||
|
|
||||||
|
# replace json defaults
|
||||||
|
validcomdict["filepath"] = str(modulefile)
|
||||||
|
validcomdict["filename"] = str(filename_base)
|
||||||
|
validcomdict["folderpath"] = str(folderpath)
|
||||||
|
validcomdict["foldername"] = str(foldername)
|
||||||
|
|
||||||
detected_lines = []
|
detected_lines = []
|
||||||
for line in module_file_lines:
|
for line in module_file_lines:
|
||||||
|
|
||||||
@ -249,14 +255,8 @@ class BotCommands():
|
|||||||
validcoms.remove(regexcom)
|
validcoms.remove(regexcom)
|
||||||
|
|
||||||
if len(validcoms):
|
if len(validcoms):
|
||||||
validcomdict = {
|
validcomdict["comtype"] = comtype
|
||||||
"comtype": comtype,
|
validcomdict["validcoms"] = validcoms
|
||||||
"validcoms": validcoms,
|
|
||||||
"filepath": str(modulefile),
|
|
||||||
"filename": str(filename_base),
|
|
||||||
"folderpath": str(folderpath),
|
|
||||||
"foldername": str(foldername),
|
|
||||||
}
|
|
||||||
filelinelist.append(validcomdict)
|
filelinelist.append(validcomdict)
|
||||||
currentsuccesslines += 1
|
currentsuccesslines += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@ -63,47 +63,13 @@ class BotJSONCommands():
|
|||||||
dict_from_file[var] = tuple_contents_bak
|
dict_from_file[var] = tuple_contents_bak
|
||||||
|
|
||||||
# check that type is set, use cases will inherit this if not set
|
# check that type is set, use cases will inherit this if not set
|
||||||
if "type" not in list(dict_from_file.keys()):
|
if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types:
|
||||||
dict_from_file["type"] = dict_from_file["foldername"]
|
|
||||||
if dict_from_file["type"] not in self.valid_com_types:
|
|
||||||
dict_from_file["type"] = 'simple'
|
dict_from_file["type"] = 'simple'
|
||||||
|
|
||||||
# Don't process these.
|
# Don't process these.
|
||||||
keysprocessed = []
|
keysprocessed = []
|
||||||
keysprocessed.extend(["validcoms", "filepath", "filename"])
|
keysprocessed.extend(["validcoms", "filepath", "filename"])
|
||||||
|
keysprocessed.append("author", "contributors")
|
||||||
# the command must have an author
|
|
||||||
if "author" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["author"] = "deathbybandaid"
|
|
||||||
keysprocessed.append("author")
|
|
||||||
|
|
||||||
# the command must have a contributors list
|
|
||||||
if "contributors" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["contributors"] = []
|
|
||||||
if not isinstance(dict_from_file["contributors"], list):
|
|
||||||
dict_from_file["contributors"] = [dict_from_file["contributors"]]
|
|
||||||
if "deathbybandaid" not in dict_from_file["contributors"]:
|
|
||||||
dict_from_file["contributors"].append("deathbybandaid")
|
|
||||||
if dict_from_file["author"] not in dict_from_file["contributors"]:
|
|
||||||
dict_from_file["contributors"].append(dict_from_file["author"])
|
|
||||||
keysprocessed.append("contributors")
|
|
||||||
|
|
||||||
if "hardcoded_channel_block" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["hardcoded_channel_block"] = []
|
|
||||||
keysprocessed.append("hardcoded_channel_block")
|
|
||||||
|
|
||||||
if "example" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["example"] = str(botconfig.core.prefix_list[0] + maincom)
|
|
||||||
|
|
||||||
if "exampleresponse" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["exampleresponse"] = None
|
|
||||||
|
|
||||||
if "description" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["description"] = None
|
|
||||||
|
|
||||||
if "privs" not in list(dict_from_file.keys()):
|
|
||||||
dict_from_file["privs"] = []
|
|
||||||
|
|
||||||
keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"])
|
keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"])
|
||||||
|
|
||||||
# handle basic required dict handling
|
# handle basic required dict handling
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import os
|
|||||||
import codecs
|
import codecs
|
||||||
|
|
||||||
from .Logs import logs
|
from .Logs import logs
|
||||||
|
from .Config import config as botconfig
|
||||||
|
|
||||||
|
|
||||||
class BotRead():
|
class BotRead():
|
||||||
@ -84,6 +85,7 @@ class BotRead():
|
|||||||
dict_from_file["filename"] = str(filename_base)
|
dict_from_file["filename"] = str(filename_base)
|
||||||
dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0]
|
dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0]
|
||||||
dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1]
|
dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1]
|
||||||
|
dict_from_file = self.command_defaults(dict_from_file)
|
||||||
configs_dict[filename_base] = dict_from_file
|
configs_dict[filename_base] = dict_from_file
|
||||||
|
|
||||||
if filecount:
|
if filecount:
|
||||||
@ -96,5 +98,86 @@ class BotRead():
|
|||||||
|
|
||||||
return configs_dict
|
return configs_dict
|
||||||
|
|
||||||
|
def module_json_to_dict(self, filepath, logging=True):
|
||||||
|
|
||||||
|
# gather file stats
|
||||||
|
slashsplit = str(filepath).split("/")
|
||||||
|
filename = slashsplit[-1]
|
||||||
|
filename_base = os.path.basename(filename).rsplit('.', 1)[0]
|
||||||
|
folderpath = str(filepath).split("/" + filename)[0]
|
||||||
|
|
||||||
|
jsonpath = os.path.join(folderpath, filename_base + ".json")
|
||||||
|
if os.path.exists(jsonpath) and os.path.isfile(jsonpath):
|
||||||
|
|
||||||
|
# Read dictionary from file, if not, enable an empty dict
|
||||||
|
filereadgood = True
|
||||||
|
inf = codecs.open(filepath, "r", encoding='utf-8')
|
||||||
|
infread = inf.read()
|
||||||
|
try:
|
||||||
|
dict_from_file = eval(infread)
|
||||||
|
except Exception as e:
|
||||||
|
filereadgood = False
|
||||||
|
if logging:
|
||||||
|
logs.log("SpiceBot_Modules", "Error loading %s: %s (%s)" % ("Module Commands", e, filepath))
|
||||||
|
dict_from_file = dict()
|
||||||
|
# Close File
|
||||||
|
inf.close()
|
||||||
|
|
||||||
|
# gather file stats
|
||||||
|
slashsplit = str(filepath).split("/")
|
||||||
|
filename = slashsplit[-1]
|
||||||
|
filename_base = os.path.basename(filename).rsplit('.', 1)[0]
|
||||||
|
|
||||||
|
if not filereadgood or not isinstance(dict_from_file, dict):
|
||||||
|
dict_from_file = {}
|
||||||
|
else:
|
||||||
|
dict_from_file["filepath"] = str(filepath)
|
||||||
|
dict_from_file["filename"] = str(filename_base)
|
||||||
|
dict_from_file["folderpath"] = dict_from_file["filepath"].split("/" + dict_from_file["filename"])[0]
|
||||||
|
dict_from_file["foldername"] = str(dict_from_file["folderpath"]).split("/")[-1]
|
||||||
|
dict_from_file = self.command_defaults(dict_from_file)
|
||||||
|
else:
|
||||||
|
dict_from_file = {}
|
||||||
|
|
||||||
|
dict_from_file = self.command_defaults(dict_from_file)
|
||||||
|
return dict_from_file
|
||||||
|
|
||||||
|
def command_defaults(self, dict_from_file):
|
||||||
|
|
||||||
|
# the command must have an author
|
||||||
|
if "author" not in list(dict_from_file.keys()):
|
||||||
|
dict_from_file["author"] = "deathbybandaid"
|
||||||
|
|
||||||
|
# the command must have a contributors list
|
||||||
|
if "contributors" not in list(dict_from_file.keys()):
|
||||||
|
dict_from_file["contributors"] = []
|
||||||
|
if not isinstance(dict_from_file["contributors"], list):
|
||||||
|
dict_from_file["contributors"] = [dict_from_file["contributors"]]
|
||||||
|
if "deathbybandaid" not in dict_from_file["contributors"]:
|
||||||
|
dict_from_file["contributors"].append("deathbybandaid")
|
||||||
|
if dict_from_file["author"] not in dict_from_file["contributors"]:
|
||||||
|
dict_from_file["contributors"].append(dict_from_file["author"])
|
||||||
|
|
||||||
|
if "example" not in list(dict_from_file.keys()):
|
||||||
|
dict_from_file["example"] = "$maincom"
|
||||||
|
# TODO
|
||||||
|
#if dict_from_file["comtype"] == "nickname":
|
||||||
|
# dict_from_file["example"] = str(botconfig.nick + " $maincom")
|
||||||
|
# else:
|
||||||
|
# dict_from_file["example"] = str(botconfig.core.prefix_list[0] + "$maincom")
|
||||||
|
if not dict_from_file["example"].startswith("$maincom"):
|
||||||
|
dict_from_file["example"] = "$maincom " + dict_from_file["example"]
|
||||||
|
|
||||||
|
if "exampleresponse" not in list(dict_from_file.keys()):
|
||||||
|
dict_from_file["exampleresponse"] = None
|
||||||
|
|
||||||
|
if "description" not in list(dict_from_file.keys()):
|
||||||
|
dict_from_file["description"] = None
|
||||||
|
|
||||||
|
if "privs" not in list(dict_from_file.keys()):
|
||||||
|
dict_from_file["privs"] = []
|
||||||
|
|
||||||
|
return dict_from_file
|
||||||
|
|
||||||
|
|
||||||
read = BotRead()
|
read = BotRead()
|
||||||
|
|||||||
@ -26,7 +26,7 @@ from .Google import *
|
|||||||
from .Gif import *
|
from .Gif import *
|
||||||
from .Sherlock import *
|
from .Sherlock import *
|
||||||
from .Reddit import *
|
from .Reddit import *
|
||||||
# from .DictComs import *
|
from .DictComs import *
|
||||||
from .Read import *
|
from .Read import *
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user