mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 15:09:54 -05:00
test
This commit is contained in:
parent
871fd454e2
commit
c16557d4a9
@ -12,10 +12,11 @@ from .Config import config as botconfig
|
|||||||
from .Read import read as botread
|
from .Read import read as botread
|
||||||
from .Commands import commands as botcommands
|
from .Commands import commands as botcommands
|
||||||
|
|
||||||
import requests
|
# import requests
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
import urllib
|
# import urllib
|
||||||
import os
|
import os
|
||||||
|
import copy
|
||||||
|
|
||||||
|
|
||||||
class SpiceBot_DictComs_MainSection(StaticSection):
|
class SpiceBot_DictComs_MainSection(StaticSection):
|
||||||
@ -33,10 +34,28 @@ class BotDictCommands():
|
|||||||
"ascii_art", "gif", "translate", "responses",
|
"ascii_art", "gif", "translate", "responses",
|
||||||
"feeds", "search"
|
"feeds", "search"
|
||||||
]
|
]
|
||||||
|
self.dict_required = ["?default"]
|
||||||
|
self.builtin_keys = [
|
||||||
|
"filepath", "filename", "folderpath", "foldername",
|
||||||
|
"comtype", "type", "validcoms",
|
||||||
|
"author", "contributors",
|
||||||
|
"description", "exampleresponse", "example",
|
||||||
|
"privs"
|
||||||
|
]
|
||||||
|
|
||||||
self.prefix_com_load()
|
self.dictcom_load()
|
||||||
|
|
||||||
def prefix_com_load(self):
|
def get_dict(self, triggersb):
|
||||||
|
|
||||||
|
# simplify usage of the bot command going forward
|
||||||
|
# copy dict to not overwrite
|
||||||
|
triggersb['comdict'] = copy.deepcopy(botcommands.dict['commands']["prefix"][triggersb['realcom']])
|
||||||
|
|
||||||
|
# execute function based on command type
|
||||||
|
triggersb['comtype'] = triggersb['comdict']["type"].lower()
|
||||||
|
return triggersb
|
||||||
|
|
||||||
|
def dictcom_load(self):
|
||||||
self.dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs")
|
self.dir_to_scan = botread.get_config_dirs("SpiceBot_DictComs")
|
||||||
for directory in self.dir_to_scan:
|
for directory in self.dir_to_scan:
|
||||||
for valid_com_type in self.valid_com_types:
|
for valid_com_type in self.valid_com_types:
|
||||||
@ -77,32 +96,20 @@ class BotDictCommands():
|
|||||||
if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types:
|
if "type" not in list(dict_from_file.keys()) or dict_from_file["type"] not in self.valid_com_types:
|
||||||
dict_from_file["type"] = 'simple'
|
dict_from_file["type"] = 'simple'
|
||||||
|
|
||||||
# Don't process these.
|
|
||||||
keysprocessed = []
|
|
||||||
keysprocessed.extend(["validcoms", "filepath", "filename", "comtype"])
|
|
||||||
keysprocessed.extend(["author", "contributors"])
|
|
||||||
keysprocessed.extend(["validcoms", "filepath", "filename", "description", "exampleresponse", "example", "privs"])
|
|
||||||
|
|
||||||
# handle basic required dict handling
|
# handle basic required dict handling
|
||||||
dict_required = ["?default"]
|
dict_from_file = self.dictcom_load_usecases(maincom, dict_from_file, self.dict_required)
|
||||||
dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, dict_required)
|
|
||||||
keysprocessed.extend(dict_required)
|
|
||||||
|
|
||||||
# remove later
|
|
||||||
keysprocessed.append("type")
|
|
||||||
|
|
||||||
# all other keys not processed above are considered potential use cases
|
# all other keys not processed above are considered potential use cases
|
||||||
otherkeys = []
|
otherkeys = []
|
||||||
for otherkey in list(dict_from_file.keys()):
|
for otherkey in list(dict_from_file.keys()):
|
||||||
if otherkey not in keysprocessed:
|
if otherkey not in self.builtin_keys:
|
||||||
otherkeys.append(otherkey)
|
otherkeys.append(otherkey)
|
||||||
if otherkeys != []:
|
if otherkeys != []:
|
||||||
dict_from_file = self.prefix_com_load_subtypes(maincom, dict_from_file, otherkeys)
|
dict_from_file = self.dictcom_load_usecases(maincom, dict_from_file, otherkeys)
|
||||||
keysprocessed.extend(otherkeys)
|
|
||||||
|
|
||||||
botcommands.register(dict_from_file)
|
botcommands.register(dict_from_file)
|
||||||
|
|
||||||
def prefix_com_load_subtypes(self, maincom, dict_from_file, process_list):
|
def dictcom_load_usecases(self, maincom, dict_from_file, process_list):
|
||||||
|
|
||||||
for mustbe in process_list:
|
for mustbe in process_list:
|
||||||
|
|
||||||
@ -121,6 +128,9 @@ class BotDictCommands():
|
|||||||
else:
|
else:
|
||||||
dict_from_file[mustbe]["type"] = "simple"
|
dict_from_file[mustbe]["type"] = "simple"
|
||||||
|
|
||||||
|
return dict_from_file
|
||||||
|
|
||||||
|
"""
|
||||||
# each usecase needs to know if it can be updated. Default is false
|
# each usecase needs to know if it can be updated. Default is false
|
||||||
if "updates_enabled" not in list(dict_from_file[mustbe].keys()):
|
if "updates_enabled" not in list(dict_from_file[mustbe].keys()):
|
||||||
dict_from_file[mustbe]["updates_enabled"] = False
|
dict_from_file[mustbe]["updates_enabled"] = False
|
||||||
@ -262,6 +272,7 @@ class BotDictCommands():
|
|||||||
dict_from_file[mustbe]["privs"] = []
|
dict_from_file[mustbe]["privs"] = []
|
||||||
|
|
||||||
return dict_from_file
|
return dict_from_file
|
||||||
|
"""
|
||||||
|
|
||||||
def setup_dictcoms(self):
|
def setup_dictcoms(self):
|
||||||
botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False)
|
botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False)
|
||||||
|
|||||||
@ -4,8 +4,6 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
This is the SpiceBot DictCom system
|
This is the SpiceBot DictCom system
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import copy
|
|
||||||
|
|
||||||
# sopel imports
|
# sopel imports
|
||||||
import sopel.module
|
import sopel.module
|
||||||
|
|
||||||
@ -19,13 +17,5 @@ def command_dictcom(bot, trigger):
|
|||||||
if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()):
|
if trigger.sb['com'] not in list(SpiceBot.commands.dict['commands']["prefix"].keys()):
|
||||||
return
|
return
|
||||||
|
|
||||||
# command aliases
|
trigger.sb = SpiceBot.dictcoms.get_dict(trigger.sb)
|
||||||
if "aliasfor" in list(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']].keys()):
|
bot.osd(str(trigger.sb))
|
||||||
trigger.sb['com'] = SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']]["aliasfor"]
|
|
||||||
|
|
||||||
# simplify usage of the bot command going forward
|
|
||||||
# copy dict to not overwrite
|
|
||||||
trigger.sb['comdict'] = copy.deepcopy(SpiceBot.commands.dict['commands']["prefix"][trigger.sb['com']])
|
|
||||||
|
|
||||||
# execute function based on command type
|
|
||||||
trigger.sb['comtype'] = trigger.sb['comdict']["type"].lower()
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user