Merge pull request #48 from SpiceBot/development

Development
This commit is contained in:
Deathbybandaid 2019-06-07 11:07:41 -04:00 committed by GitHub
commit 397f536da0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 172 additions and 142 deletions

View File

@ -14,6 +14,8 @@ import aiml
from .Database import db as botdb from .Database import db as botdb
from .Config import config as botconfig from .Config import config as botconfig
import spicemanip
class SpiceBot_AI_MainSection(StaticSection): class SpiceBot_AI_MainSection(StaticSection):
extra = ListAttribute('extra') extra = ListAttribute('extra')
@ -137,9 +139,6 @@ class SpiceBot_AI():
def bot_message_precipher(self, bot, trigger, message): def bot_message_precipher(self, bot, trigger, message):
# uppercase input
message = message.upper()
# punctuation # punctuation
puct_dict = {"!": "exclamationmark", ".": "period", "?": "questionmark", ",": "comma"} puct_dict = {"!": "exclamationmark", ".": "period", "?": "questionmark", ",": "comma"}
for puctuation in puct_dict.keys(): for puctuation in puct_dict.keys():
@ -147,10 +146,18 @@ class SpiceBot_AI():
# bot items # bot items
for botitem in ["nick"]: for botitem in ["nick"]:
message = message.replace(str(eval("bot." + botitem)).upper(), str("bot" + botitem).upper()) messagelist = spicemanip.main(message, "create")
for i in range(len(messagelist)):
if messagelist[i].upper() == str(eval("bot." + botitem)).upper():
messagelist[i] = str("bot" + botitem).upper()
message = spicemanip.main(messagelist, 0)
for triggeritem in ["nick", "sender"]: for triggeritem in ["nick", "sender"]:
message = message.replace(str(eval("trigger." + triggeritem)).upper(), str("trigger" + triggeritem).upper()) messagelist = spicemanip.main(message, "create")
for i in range(len(messagelist)):
if messagelist[i].upper() == str(eval("trigger." + botitem)).upper():
messagelist[i] = str("trigger" + botitem).upper()
message = spicemanip.main(messagelist, 0)
return message return message

View File

@ -52,10 +52,6 @@ def bot_command_nick(bot, trigger):
bot.osd(trigger.nick + ", where would you like me to beam you?") bot.osd(trigger.nick + ", where would you like me to beam you?")
return return
elif fulltrigger.lower().startswith("beam me up"):
bot.osd("locks onto " + trigger.nick + "s coordinates and transports them to the transporter room.", 'action')
return
elif fulltrigger.lower().endswith(tuple(["order 66"])): elif fulltrigger.lower().endswith(tuple(["order 66"])):
if fulltrigger.lower() == "execute order 66": if fulltrigger.lower() == "execute order 66":

View File

@ -26,6 +26,7 @@ def bot_command_rule(bot, trigger):
# ignore text coming from a valid prefix # ignore text coming from a valid prefix
if str(message).startswith(tuple(bot.config.core.prefix_list)): if str(message).startswith(tuple(bot.config.core.prefix_list)):
return
trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module')
# patch for people typing "...", maybe other stuff, but this verifies that there is still a command here # patch for people typing "...", maybe other stuff, but this verifies that there is still a command here
if trigger_command.startswith("."): if trigger_command.startswith("."):
@ -48,6 +49,7 @@ def bot_command_rule(bot, trigger):
if str(message).lower().startswith(str(bot.nick).lower()): if str(message).lower().startswith(str(bot.nick).lower()):
command_type = 'nickname' command_type = 'nickname'
trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'nickname') trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'nickname')
trigger_args.insert(0, trigger_command)
fulltrigger = spicemanip.main(trigger_args, 0) fulltrigger = spicemanip.main(trigger_args, 0)
if str(trigger_command).startswith("?"): if str(trigger_command).startswith("?"):
return return
@ -56,8 +58,9 @@ def bot_command_rule(bot, trigger):
if trigger_command in SpiceBot.commands.dict['commands']["nickname"].keys(): if trigger_command in SpiceBot.commands.dict['commands']["nickname"].keys():
return return
else: else:
command_type = 'module' command_type = 'other'
trigger_args, trigger_command = SpiceBot.prerun.trigger_args(message, 'module') trigger_args = spicemanip.main(message, 'create')
trigger_command = trigger_args[0]
fulltrigger = spicemanip.main(trigger_args, 0) fulltrigger = spicemanip.main(trigger_args, 0)
returnmessage = SpiceBot.botai.on_message(bot, trigger, message) returnmessage = SpiceBot.botai.on_message(bot, trigger, message)
@ -66,7 +69,8 @@ def bot_command_rule(bot, trigger):
else: else:
if command_type == 'nickname': if command_type == 'nickname':
if trigger_args[0].lower() in ["what", "where"] and trigger_args[0].lower() in ["is", "are"]: if trigger_args[0].lower() in ["what", "where"] and trigger_args[1].lower() in ["is", "are"]:
# TODO saved definitions
searchterm = spicemanip.main(trigger_args, "3+") or None searchterm = spicemanip.main(trigger_args, "3+") or None
if searchterm: if searchterm:
if trigger_args[0].lower() == "where": if trigger_args[0].lower() == "where":

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<aiml version="1.0">
<category>
<pattern>BOTNICK beam me up</pattern>
<template>locks onto triggernicks coordinates and transports them to the transporter room.</template>
</category>
</aiml>

View File

@ -21,6 +21,7 @@ def nickname_comand_channels(bot, trigger):
commandused = 'list' commandused = 'list'
else: else:
commandused = spicemanip.main(trigger.sb['args'], 1).lower() commandused = spicemanip.main(trigger.sb['args'], 1).lower()
bot.say(str(commandused))
commands_list = [] commands_list = []
for commandstype in SpiceBot.commands.dict['commands'].keys(): for commandstype in SpiceBot.commands.dict['commands'].keys():
@ -43,133 +44,3 @@ def nickname_comand_channels(bot, trigger):
elif commandused == 'random': elif commandused == 'random':
bot.osd(["Here's a random command for you:", + spicemanip.main(commands_list, 'random')]) bot.osd(["Here's a random command for you:", + spicemanip.main(commands_list, 'random')])
return return
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun.prerun('nickname')
@sopel.module.nickname_commands('(.*)')
def query_detection_nick(bot, trigger):
# command issued, check if valid
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if not trigger.sb['com'][0] == "?":
return
trigger.sb['com'] = trigger.sb['com'][1:]
if not SpiceBot.letters_in_string(trigger.sb['com']):
return
commands_list = dict()
for com in SpiceBot.commands.dict['commands']['nickname'].keys():
if com not in commands_list.keys():
commands_list[com] = SpiceBot.commands.dict['commands']['nickname'][com]
if trigger.sb['com'].endswith("+"):
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if trigger.sb['com'].lower() not in list(commands_list.keys()):
dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(trigger.sb['com']) + "."]
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if len(closestmatches):
dispmsg.append("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
bot.osd(dispmsg, trigger.nick, 'notice')
return
realcom = trigger.sb['com']
if "aliasfor" in commands_list[trigger.sb['com']].keys():
realcom = commands_list[trigger.sb['com']]["aliasfor"]
validcomlist = commands_list[realcom]["validcoms"]
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("?"):
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if not len(closestmatches):
bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following " + bot.nick + " commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice')
return
commandlist = []
for command in list(commands_list.keys()):
if command.lower().startswith(str(trigger.sb['com']).lower()):
commandlist.append(command)
if not len(commandlist):
bot.osd("No " + bot.nick + " commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice')
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun.prerun('query')
@sopel.module.rule('^\?(.*)')
def query_detection(bot, trigger):
# command issued, check if valid
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if not SpiceBot.letters_in_string(trigger.sb['com']):
return
commands_list = dict()
for commandstype in SpiceBot.commands.dict['commands'].keys():
if commandstype not in ['rule', 'nickname']:
for com in SpiceBot.commands.dict['commands'][commandstype].keys():
if com not in commands_list.keys():
commands_list[com] = SpiceBot.commands.dict['commands'][commandstype][com]
if trigger.sb['com'][:-1] == "+":
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if trigger.sb['com'].lower() not in list(commands_list.keys()):
dispmsg = ["Cannot find any alias commands: No valid commands match " + str(trigger.sb['com']) + "."]
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if len(closestmatches):
dispmsg.append("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
bot.osd(dispmsg, trigger.nick, 'notice')
return
realcom = trigger.sb['com']
if "aliasfor" in commands_list[trigger.sb['com']].keys():
realcom = commands_list[trigger.sb['com']]["aliasfor"]
validcomlist = commands_list[realcom]["validcoms"]
bot.osd("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice')
return
if trigger.sb['com'][:-1] == "?":
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if not len(closestmatches):
bot.osd("Cannot find any similar commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice')
return
commandlist = []
for command in list(commands_list.keys()):
if command.lower().startswith(str(trigger.sb['com']).lower()):
commandlist.append(command)
if not len(commandlist):
bot.osd("No commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice')

View File

@ -0,0 +1,142 @@
# coding=utf8
from __future__ import unicode_literals, absolute_import, division, print_function
"""
This is the SpiceBot Commands system.
This Class stores commands in an easy to access manner
"""
import sopel
import spicemanip
import sopel_modules.SpiceBot as SpiceBot
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun.prerun('nickname')
@sopel.module.nickname_commands('(.*)')
def query_detection_nick(bot, trigger):
# command issued, check if valid
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if not trigger.sb['com'][0] == "?":
return
trigger.sb['com'] = trigger.sb['com'][1:]
if not SpiceBot.letters_in_string(trigger.sb['com']):
return
commands_list = dict()
for com in SpiceBot.commands.dict['commands']['nickname'].keys():
if com not in commands_list.keys():
commands_list[com] = SpiceBot.commands.dict['commands']['nickname'][com]
if trigger.sb['com'].endswith("+"):
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if trigger.sb['com'].lower() not in list(commands_list.keys()):
dispmsg = ["Cannot find any alias " + bot.nick + " commands: No valid commands match " + str(trigger.sb['com']) + "."]
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if len(closestmatches):
dispmsg.append("The following " + bot.nick + " commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
bot.osd(dispmsg, trigger.nick, 'notice')
return
realcom = trigger.sb['com']
if "aliasfor" in commands_list[trigger.sb['com']].keys():
realcom = commands_list[trigger.sb['com']]["aliasfor"]
validcomlist = commands_list[realcom]["validcoms"]
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("?"):
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if not len(closestmatches):
bot.osd("Cannot find any similar " + bot.nick + " commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following " + bot.nick + " commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice')
return
commandlist = []
for command in list(commands_list.keys()):
if command.lower().startswith(str(trigger.sb['com']).lower()):
commandlist.append(command)
if not len(commandlist):
bot.osd("No " + bot.nick + " commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following " + bot.nick + " commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice')
@SpiceBot.events.check_ready([SpiceBot.events.BOT_COMMANDS])
@SpiceBot.prerun.prerun('query')
@sopel.module.rule('^\?(.*)')
def query_detection(bot, trigger):
# command issued, check if valid
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if not SpiceBot.letters_in_string(trigger.sb['com']):
return
commands_list = dict()
for commandstype in SpiceBot.commands.dict['commands'].keys():
if commandstype not in ['rule', 'nickname']:
for com in SpiceBot.commands.dict['commands'][commandstype].keys():
if com not in commands_list.keys():
commands_list[com] = SpiceBot.commands.dict['commands'][commandstype][com]
if trigger.sb['com'][:-1] == "+":
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
if trigger.sb['com'].lower() not in list(commands_list.keys()):
dispmsg = ["Cannot find any alias commands: No valid commands match " + str(trigger.sb['com']) + "."]
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if len(closestmatches):
dispmsg.append("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
bot.osd(dispmsg, trigger.nick, 'notice')
return
realcom = trigger.sb['com']
if "aliasfor" in commands_list[trigger.sb['com']].keys():
realcom = commands_list[trigger.sb['com']]["aliasfor"]
validcomlist = commands_list[realcom]["validcoms"]
bot.osd("The following commands match " + str(trigger.sb['com']) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick, 'notice')
return
if trigger.sb['com'][:-1] == "?":
trigger.sb['com'] = trigger.sb['com'][:-1]
if not trigger.sb['com'] or not len(trigger.sb['com']):
return
closestmatches = SpiceBot.similar_list(trigger.sb['com'], list(commands_list.keys()), 10, 'reverse')
if not len(closestmatches):
bot.osd("Cannot find any similar commands for " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following commands may match " + str(trigger.sb['com']) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick, 'notice')
return
commandlist = []
for command in list(commands_list.keys()):
if command.lower().startswith(str(trigger.sb['com']).lower()):
commandlist.append(command)
if not len(commandlist):
bot.osd("No commands start with " + str(trigger.sb['com']) + ".", trigger.nick, 'notice')
else:
bot.osd("The following commands start with " + str(trigger.sb['com']) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick, 'notice')

View File

@ -6,6 +6,7 @@ These are the core SpiceBot Classes
This module contains references only for other modules to utilize. This module contains references only for other modules to utilize.
""" """
from .CommandsQuery import *
from .Commands import * from .Commands import *
from .Channels import * from .Channels import *
from .Database import * from .Database import *