Merge pull request #75 from SpiceBot/development

Development
This commit is contained in:
Deathbybandaid 2019-06-27 16:09:32 -04:00 committed by GitHub
commit abdf2c2c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 138 additions and 26 deletions

View File

@ -87,7 +87,7 @@ class BotCommands():
return realcom
if "aliasfor" in self.dict['commands'][trigger_command_type][command].keys():
realcom = self.dict['commands'][trigger_command_type][command]
realcom = self.dict['commands'][trigger_command_type][command]["aliasfor"]
return realcom

View File

@ -17,6 +17,7 @@ from .Commands import commands as botcommands
from .Database import db as botdb
from .Channels import channels as botchannels
from .MessageLog import messagelog as botmessagelog
from .Config import config as botconfig
def prerun(t_command_type='module', t_command_subtype=None):
@ -26,10 +27,21 @@ def prerun(t_command_type='module', t_command_subtype=None):
@functools.wraps(function)
def internal_prerun(bot, trigger, *args, **kwargs):
if t_command_type == "nickname":
check_nick = spicemanip.main(trigger.args[1], 1).lower()
if check_nick != str(bot.nick).lower():
return
else:
if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)):
return
trigger_command_type = str(t_command_type)
# Primary command used for trigger, and a list of all words
trigger_args, trigger_command = make_trigger_args(trigger.args[1], trigger_command_type)
trigger_args, trigger_command, trigger_prefix = make_trigger_args(trigger.args[1], trigger_command_type)
if trigger_prefix == botconfig.SpiceBot_Commands.query_prefix:
return
trigger_command_type = botcommands.find_command_type(trigger_command)
if not trigger_command_type:
@ -50,11 +62,13 @@ def prerun(t_command_type='module', t_command_subtype=None):
argsdict_default["realcom"] = botcommands.get_realcom(argsdict_default["com"], trigger_command_type)
if argsdict_default["type"] == 'nickname':
argsdict_default["comtext"] = bot.nick + " " + argsdict_default["com"]
argsdict_default["realcomtext"] = bot.nick + " " + argsdict_default["realcom"]
argsdict_default["comtext"] = "'" + bot.nick + " " + argsdict_default["com"] + "'"
argsdict_default["realcomtext"] = "'" + bot.nick + " " + argsdict_default["realcom"] + "'"
else:
argsdict_default["comtext"] = argsdict_default["com"]
argsdict_default["realcomtext"] = argsdict_default["realcom"]
argsdict_default["comtext"] = "'" + argsdict_default["com"] + "'"
argsdict_default["realcomtext"] = "'" + argsdict_default["realcom"] + "'"
argsdict_default["realcomref"] = argsdict_default["type"] + "_" + argsdict_default["realcom"]
argsdict_default["dict"] = botcommands.get_command_dict(argsdict_default["realcom"], trigger_command_type)
@ -86,15 +100,90 @@ def prerun(t_command_type='module', t_command_subtype=None):
return actual_decorator
def prerun_query(t_command_type='module', t_command_subtype=None):
def actual_decorator(function):
@functools.wraps(function)
def internal_prerun(bot, trigger, *args, **kwargs):
if t_command_type == "nickname":
check_nick = spicemanip.main(trigger.args[1], 1).lower()
if check_nick != str(bot.nick).lower():
return
else:
if not str(trigger.args[1]).startswith(tuple(botconfig.core.prefix_list)):
return
if t_command_subtype != t_command_type:
return
trigger_command_type = str(t_command_type)
# 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:
return
# Argsdict Defaults
argsdict_default = {}
argsdict_default["type"] = trigger_command_type
argsdict_default["com"] = trigger_command
# messagelog ID
argsdict_default["log_id"] = botmessagelog.messagelog_assign()
argsdict_default["realcom"] = "query_command"
argsdict_default["comtext"] = "'" + bot.nick + " query'"
argsdict_default["realcomtext"] = "'" + bot.nick + " query'"
argsdict_default["realcomref"] = "nickname_query"
argsdict_default["dict"] = botcommands.get_command_dict("query", 'nickname')
# split into && groupings
and_split = trigger_and_split(trigger_args)
# Create dict listings for trigger.sb
argsdict_list = trigger_argsdict_list(argsdict_default, and_split)
# Run the function for all splits
botmessagelog.messagelog_start(bot, trigger, argsdict_default["log_id"])
runcount = 0
for argsdict in argsdict_list:
runcount += 1
trigger.sb = copy.deepcopy(argsdict)
trigger.sb["runcount"] = runcount
trigger.sb["args"], trigger.sb["hyphen_arg"] = trigger_hyphen_args(trigger.sb["args"])
if not trigger.sb["hyphen_arg"]:
# check if anything prohibits the nick from running the command
if trigger_runstatus(bot, trigger):
function(bot, trigger, *args, **kwargs)
else:
trigger_hyphen_arg_handler(bot, trigger)
botmessagelog.messagelog_exit(bot, argsdict_default["log_id"])
return internal_prerun
return actual_decorator
def make_trigger_args(triggerargs_one, trigger_command_type='module'):
trigger_args = spicemanip.main(triggerargs_one, 'create')
if trigger_command_type in ['nickname']:
trigger_prefix = spicemanip.main(trigger_args, 2).lower()[0]
if trigger_prefix.isupper() or trigger_prefix.islower():
trigger_prefix = None
trigger_command = spicemanip.main(trigger_args, 2).lower()
trigger_args = spicemanip.main(trigger_args, '3+', 'list')
else:
trigger_prefix = spicemanip.main(trigger_args, 1).lower()[0]
trigger_command = spicemanip.main(trigger_args, 1).lower()[1:]
trigger_args = spicemanip.main(trigger_args, '2+', 'list')
return trigger_args, trigger_command
return trigger_args, trigger_command, trigger_prefix
def trigger_and_split(trigger_args):
@ -167,7 +256,7 @@ def trigger_runstatus(bot, trigger):
message = "The " + str(trigger.sb["comtext"]) + " command was multirun unsage disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason)
return trigger_cant_run(bot, trigger, message)
else:
botcommands.unset_command_disabled(trigger.sb["realcom"], trigger.nick, "multirun")
botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick, "multirun")
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(trigger.nick))
# don't run commands that are disabled in channels
@ -190,8 +279,8 @@ def trigger_runstatus(bot, trigger):
message = "The " + str(trigger.sb["comtext"]) + " command was disabled by " + bywhom + " for " + str(trigger.sender) + " at " + str(timestamp) + " for the following reason: " + str(reason)
return trigger_cant_run(bot, trigger, message)
else:
botcommands.unset_command_disabled(trigger.sb["realcom"], trigger.nick, "fully")
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(trigger.nick))
botcommands.unset_command_disabled(trigger.sb["realcomref"], trigger.nick, "fully")
botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(trigger.nick))
return True
@ -272,24 +361,24 @@ def trigger_hyphen_arg_handler(bot, trigger):
if trigger.sb["hyphen_arg"] in ['enable', 'unblock', "activate", "on"]:
if not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "fully"):
if not botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "fully"):
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is already enabled for " + str(target))
return
botcommands.unset_command_disabled(trigger.sb["realcom"], target, "fully")
botcommands.unset_command_disabled(trigger.sb["realcomref"], target, "fully")
botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now enabled for " + str(target))
return
else:
if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "fully"):
if botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "fully"):
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " is already disabled for " + str(target))
return
trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given."
timestamp = str(datetime.datetime.utcnow())
botcommands.set_command_disabled(trigger.sb["realcom"], target, timestamp, trailingmessage, trigger.nick, "fully")
botcommands.set_command_disabled(trigger.sb["realcomref"], target, timestamp, trailingmessage, trigger.nick, "fully")
botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " is now disabled for " + str(target))
return
@ -322,24 +411,24 @@ def trigger_hyphen_arg_handler(bot, trigger):
if onoff in ['enable', 'unblock', "activate", "on"]:
if not botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"):
if not botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "multirun"):
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is already enabled for " + str(target))
return
botcommands.unset_command_disabled(trigger.sb["realcom"], target, "multirun")
botcommands.unset_command_disabled(trigger.sb["realcomref"], target, "multirun")
botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now enabled for " + str(target))
return
else:
if botcommands.check_commands_disabled(trigger.sb["realcom"], target, "multirun"):
if botcommands.check_commands_disabled(trigger.sb["realcomref"], target, "multirun"):
botmessagelog.messagelog_error(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is already disabled for " + str(target))
return
trailingmessage = spicemanip.main(trigger.sb["args"], 0) or "No reason given."
timestamp = str(datetime.datetime.utcnow())
botcommands.set_command_disabled(trigger.sb["realcom"], target, timestamp, trailingmessage, trigger.nick, "multirun")
botcommands.set_command_disabled(trigger.sb["realcomref"], target, timestamp, trailingmessage, trigger.nick, "multirun")
botmessagelog.messagelog(trigger.sb["log_id"], trigger.sb["comtext"] + " multirun is now disabled for " + str(target))
return

View File

@ -9,9 +9,26 @@ import sopel_modules.SpiceBot as SpiceBot
import spicemanip
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('ai')
def ai_trigger(bot, trigger):
bot.osd("I have the capability of responding to many requests, but I am not YET sentient.")
@sopel.module.rule('(.*)')
def bot_command_rule_ai(bot, trigger):
# don't run commands that are disabled in channels
if not trigger.is_privmsg:
channel_disabled_list = SpiceBot.commands.get_commands_disabled(str(trigger.sender), "fully")
if "nickname_ai" in list(channel_disabled_list.keys()):
return
# don't run commands that are disabled for specific users
nick_disabled_list = SpiceBot.commands.get_commands_disabled(str(trigger.nick), "fully")
if "nickname_ai" in list(nick_disabled_list.keys()):
return
# TODO add config limits
# but still allow in privmsg
@ -36,21 +53,21 @@ def bot_command_rule_ai(bot, trigger):
if str(message).lower().startswith(str(bot.nick).lower()):
command_type = 'nickname'
trigger_args, trigger_command = SpiceBot.make_trigger_args(message, 'nickname')
trigger_args, trigger_command, trigger_prefix = SpiceBot.make_trigger_args(message, 'nickname')
trigger_args.insert(0, trigger_command)
fulltrigger = bot.nick + " " + spicemanip.main(trigger_args, 0)
if str(trigger_command).startswith("?"):
if str(trigger_command).startswith(bot.config.SpiceBot_Commands.query_prefix):
return
if fulltrigger in SpiceBot.commands.dict['nickrules']:
return
if trigger_command in list(SpiceBot.commands.dict['commands']["nickname"].keys()):
return
elif str(message).lower().startswith("?"):
elif str(message).lower().startswith(bot.config.SpiceBot_Commands.query_prefix):
# no query commands detection here
return
elif str(message).startswith(tuple(bot.config.core.prefix_list)):
command_type = 'module'
trigger_args, trigger_command = SpiceBot.make_trigger_args(message, 'module')
trigger_args, trigger_command, trigger_prefix = SpiceBot.make_trigger_args(message, 'module')
trigger_args.insert(0, trigger_command)
fulltrigger = spicemanip.main(trigger_args, 0)
# patch for people typing "...", maybe other stuff, but this verifies that there is still a command here

View File

@ -12,8 +12,14 @@ import spicemanip
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.prerun('nickname')
@sopel.module.nickname_commands('query')
def query_trigger(bot, trigger):
bot.osd("I have been programmed to help find new commands by using `?`.")
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun('nickname_match')
@SpiceBot.prerun_query('nickname', 'nickname')
@sopel.module.nickname_commands('(.*)')
def query_detection_nick(bot, trigger):
@ -21,7 +27,7 @@ def query_detection_nick(bot, trigger):
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if not trigger.sb['com'][0] == "?":
if not trigger.sb['com'][0] == bot.config.SpiceBot_Commands.query_prefix:
return
trigger.sb['com'] = trigger.sb['com'][1:]
@ -54,7 +60,7 @@ def query_detection_nick(bot, trigger):
bot.osd("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice')
return
if trigger.sb['com'].endswith("?"):
if trigger.sb['com'].endswith(bot.config.SpiceBot_Commands.query_prefix):
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
@ -79,7 +85,7 @@ def query_detection_nick(bot, trigger):
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun('query')
@SpiceBot.prerun_query('module', 'module')
@sopel.module.rule('^\?(.*)')
def query_detection(bot, trigger):