mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-10 21:50:59 -05:00
commit
8b754adc6c
@ -12,6 +12,7 @@ from sopel.config.types import StaticSection, ValidatedAttribute
|
||||
import os
|
||||
import threading
|
||||
import copy
|
||||
import imp
|
||||
|
||||
from sopel_modules.spicemanip import spicemanip
|
||||
import sopel_modules
|
||||
@ -368,5 +369,86 @@ class BotCommands():
|
||||
|
||||
self.register(validcomdict)
|
||||
|
||||
def list_plugin_filenames(self, directory, plugin_type='file'):
|
||||
return_list = []
|
||||
base = os.path.abspath(directory)
|
||||
for filename in os.listdir(base):
|
||||
abspath = os.path.join(base, filename)
|
||||
|
||||
if os.path.isdir(abspath):
|
||||
returndict = {"type": "folder"}
|
||||
if os.path.isfile(os.path.join(abspath, '__init__.py')):
|
||||
returndict["name"] = os.path.basename(filename)
|
||||
returndict["abspath"] = abspath
|
||||
if plugin_type == 'file':
|
||||
returndict["handler"] = sopel.plugins.handlers.PyFilePlugin(abspath)
|
||||
else:
|
||||
returndict["handler"] = sopel.plugins.handlers.PyModulePlugin(os.path.basename(filename), plugin_type)
|
||||
module_files = []
|
||||
for subfilename in os.listdir(abspath):
|
||||
name, ext = os.path.splitext(subfilename)
|
||||
if ext == '.py' and name != '__init__':
|
||||
subabspath = os.path.join(abspath, subfilename)
|
||||
if os.path.isfile(os.path.join(subabspath, name + '.json')):
|
||||
dictfile = os.path.join(subabspath, name + '.json')
|
||||
else:
|
||||
dictfile = False
|
||||
module_files.append({"name": name, "abspath": subabspath, "dictfile": dictfile})
|
||||
returndict["module_files"] = module_files
|
||||
return_list.append(returndict)
|
||||
else:
|
||||
returndict = {"type": "file"}
|
||||
name, ext = os.path.splitext(filename)
|
||||
if ext == '.py' and name != '__init__':
|
||||
returndict["name"] = name
|
||||
returndict["abspath"] = abspath
|
||||
if plugin_type == 'file':
|
||||
returndict["handler"] = sopel.plugins.handlers.PyFilePlugin(abspath)
|
||||
else:
|
||||
returndict["handler"] = sopel.plugins.handlers.PyModulePlugin(name, plugin_type)
|
||||
if os.path.isfile(os.path.join(abspath, name + '.json')):
|
||||
dictfile = os.path.join(abspath, name + '.json')
|
||||
else:
|
||||
dictfile = False
|
||||
returndict["dictfile"] = dictfile
|
||||
return_list.append(returndict)
|
||||
return return_list
|
||||
|
||||
def list_plugin_dir(self):
|
||||
plugin_dir = imp.find_module('modules', [imp.find_module('sopel')[1]])[1]
|
||||
return self.list_plugin_filenames(plugin_dir, 'sopel.modules')
|
||||
|
||||
def list_sopel_modules_dir(self):
|
||||
try:
|
||||
import sopel_modules
|
||||
except ImportError:
|
||||
return []
|
||||
sopel_modules_list = []
|
||||
for plugin_dir in set(sopel_modules.__path__):
|
||||
small_list = self.list_plugin_filenames(plugin_dir, 'sopel_modules')
|
||||
sopel_modules_list.extend(small_list)
|
||||
return sopel_modules_list
|
||||
|
||||
def list_homedir_dir(self):
|
||||
plugin_dir = os.path.join(botconfig.config.homedir, 'modules')
|
||||
return self.list_plugin_filenames(plugin_dir)
|
||||
|
||||
def list_extra_dir(self):
|
||||
sopel_modules_list = []
|
||||
if botconfig.config.core.extra:
|
||||
plugin_dirs = list(botconfig.config.core.extra)
|
||||
for plugin_dir in plugin_dirs:
|
||||
if os.path.isdir(plugin_dir):
|
||||
small_list = self.list_plugin_filenames(plugin_dir)
|
||||
sopel_modules_list.extend(small_list)
|
||||
return sopel_modules_list
|
||||
|
||||
def get_plugin_list(self):
|
||||
full_list = []
|
||||
for x in ["plugin", "sopel_modules", "homedir", "extra"]:
|
||||
return_list = eval("self.list_" + str(x) + "_dir()")
|
||||
full_list.extend(return_list)
|
||||
return full_list
|
||||
|
||||
|
||||
commands = BotCommands()
|
||||
|
||||
@ -295,5 +295,10 @@ class BotDictCommands():
|
||||
def setup_dictcoms(self):
|
||||
botconfig.define_section("SpiceBot_DictComs", SpiceBot_DictComs_MainSection, validate=False)
|
||||
|
||||
def process(bot, trigger, botcom):
|
||||
|
||||
# use the default key, unless otherwise specified
|
||||
botcom.dict["responsekey"] = "?default"
|
||||
|
||||
|
||||
dictcoms = BotDictCommands()
|
||||
|
||||
@ -38,6 +38,12 @@ class BotGif():
|
||||
|
||||
valid_gif_api_dict = botread.json_to_dict(self.dir_to_scan, "Gif API", "SpiceBot_Gif")
|
||||
|
||||
"""
|
||||
15:02 <+Exirel> `channel_section = getattr(bot.config, 'channel', None)`
|
||||
15:02 <deathbybandaid> I'm listening though
|
||||
15:02 <+Exirel> `value_of_the_option_specchan = channel_section.specchan`
|
||||
"""
|
||||
|
||||
for gif_api in list(valid_gif_api_dict.keys()):
|
||||
botconfig.define_section(gif_api, GifAPISection, validate=False)
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ def prerun(t_command_type='module', t_command_subtype=None):
|
||||
check_nick = spicemanip(trigger.args[1], 1).lower()
|
||||
if check_nick != str(bot.nick).lower():
|
||||
return
|
||||
else:
|
||||
elif t_command_type == "module":
|
||||
if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)):
|
||||
return
|
||||
|
||||
@ -53,7 +53,7 @@ def prerun(t_command_type='module', t_command_subtype=None):
|
||||
# Primary command used for trigger, and a list of all words
|
||||
trigger_args, trigger_command, trigger_prefix = make_trigger_args(trigger.args[1], trigger_command_type)
|
||||
|
||||
if trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]:
|
||||
if trigger_prefix and trigger_prefix in [botconfig.SpiceBot_Commands.query_prefix]:
|
||||
return
|
||||
|
||||
trigger_command_type = botcommands.find_command_type(trigger_command)
|
||||
@ -68,6 +68,7 @@ def prerun(t_command_type='module', t_command_subtype=None):
|
||||
argsdict_default = {}
|
||||
argsdict_default["type"] = trigger_command_type
|
||||
argsdict_default["com"] = trigger_command
|
||||
argsdict_default["trigger_prefix"] = trigger_prefix
|
||||
|
||||
# messagelog ID
|
||||
argsdict_default["log_id"] = botmessagelog.messagelog_assign()
|
||||
@ -101,7 +102,12 @@ def prerun(t_command_type='module', t_command_subtype=None):
|
||||
botcom.dict["runcount"] = runcount
|
||||
|
||||
botcom.dict["args"], botcom.dict["hyphen_arg"] = trigger_hyphen_args(botcom.dict["args"])
|
||||
|
||||
# special handling
|
||||
botcom.dict["responsekey"] = "?default"
|
||||
|
||||
args_pass = trigger_hyphen_arg_handler(bot, trigger, botcom)
|
||||
|
||||
if args_pass:
|
||||
if trigger_runstatus(bot, trigger, botcom):
|
||||
function(bot, trigger, botcom, *args, **kwargs)
|
||||
@ -132,7 +138,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None):
|
||||
check_nick = spicemanip(trigger.args[1], 1).lower()
|
||||
if check_nick != str(bot.nick).lower():
|
||||
return
|
||||
else:
|
||||
elif t_command_type == "module":
|
||||
if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)):
|
||||
return
|
||||
|
||||
@ -144,7 +150,7 @@ def prerun_query(t_command_type='module', t_command_subtype=None):
|
||||
# Primary command used for trigger, and a list of all words
|
||||
trigger_args, trigger_command, trigger_prefix = make_trigger_args(trigger.args[1], trigger_command_type)
|
||||
|
||||
if trigger_prefix != botconfig.SpiceBot_Commands.query_prefix:
|
||||
if trigger_prefix and trigger_prefix not in [botconfig.SpiceBot_Commands.query_prefix]:
|
||||
return
|
||||
|
||||
# Argsdict Defaults
|
||||
@ -209,11 +215,15 @@ def verify_channel(trigger):
|
||||
def make_trigger_args(triggerargs_one, trigger_command_type='module'):
|
||||
trigger_args = spicemanip(triggerargs_one, 'create')
|
||||
if trigger_command_type in ['nickname']:
|
||||
trigger_prefix = spicemanip(trigger_args, 2).lower()[0]
|
||||
if trigger_prefix.isupper() or trigger_prefix.islower():
|
||||
trigger_prefix = None
|
||||
trigger_prefix = None
|
||||
# if trigger_prefix.isupper() or trigger_prefix.islower():
|
||||
# trigger_prefix = None
|
||||
trigger_command = spicemanip(trigger_args, 2).lower()
|
||||
trigger_args = spicemanip(trigger_args, '3+', 'list')
|
||||
elif trigger_command_type in ['action']:
|
||||
trigger_prefix = None
|
||||
trigger_command = spicemanip(trigger_args, 1).lower()
|
||||
trigger_args = spicemanip(trigger_args, '2+', 'list')
|
||||
else:
|
||||
trigger_prefix = spicemanip(trigger_args, 1).lower()[0]
|
||||
trigger_command = spicemanip(trigger_args, 1).lower()[1:]
|
||||
@ -262,7 +272,7 @@ def trigger_argsdict_single(argsdict_default, trigger_args_part):
|
||||
def trigger_runstatus_query(bot, trigger, botcom):
|
||||
|
||||
# Bots can't run commands
|
||||
if Identifier(trigger.nick) == bot.nick:
|
||||
if trigger.nick == bot.nick:
|
||||
return False
|
||||
|
||||
# Allow permissions for enabling and disabling commands via hyphenargs
|
||||
@ -329,7 +339,8 @@ def trigger_runstatus(bot, trigger, botcom):
|
||||
|
||||
if not trigger.is_privmsg:
|
||||
if str(trigger.sender).lower() in [x.lower() for x in botcom.dict["dict"]["hardcoded_channel_block"]]:
|
||||
botmessagelog.messagelog_error(botcom.dict["log_id"], "The " + str(botcom.dict["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to.")
|
||||
message = "The " + str(botcom.dict["comtext"]) + " command cannot be used in " + str(trigger.sender) + " because it is hardcoded not to."
|
||||
return trigger_cant_run(bot, trigger, botcom, message)
|
||||
|
||||
if botcom.dict["runcount"] > 1:
|
||||
# check channel multirun blocks
|
||||
@ -402,11 +413,13 @@ def trigger_hyphen_args(trigger_args_part):
|
||||
'foldername', 'folderpath',
|
||||
"author",
|
||||
'contribs', 'contrib', "contributors",
|
||||
'alias', 'aliases'
|
||||
'alias', 'aliases',
|
||||
'random'
|
||||
]
|
||||
numdict = {
|
||||
"last": -1
|
||||
}
|
||||
|
||||
hyphen_args = []
|
||||
trigger_args_unhyphend = []
|
||||
for worditem in trigger_args_part:
|
||||
|
||||
@ -106,11 +106,11 @@ def bot_command_rule_ai(bot, trigger):
|
||||
if trigger_command not in commands_list:
|
||||
if not SpiceBot.letters_in_string(trigger_command):
|
||||
return
|
||||
invalid_display = ["I don't seem to have a command for " + str(trigger_command) + "!"]
|
||||
# invalid_display = ["I don't seem to have a command for " + str(trigger_command) + "!"]
|
||||
# TODO
|
||||
# invalid_display.append("If you have a suggestion for this command, you can run .feature ." + str(trigger_command))
|
||||
# invalid_display.append("ADD DESCRIPTION HERE!")
|
||||
bot.osd(invalid_display, trigger.nick, 'notice')
|
||||
# bot.osd(invalid_display, trigger.nick, 'notice')
|
||||
return
|
||||
|
||||
elif command_type == 'nickname':
|
||||
|
||||
Loading…
Reference in New Issue
Block a user