mirror of
https://github.com/SpiceBot/SpiceBot.git
synced 2026-11-13 06:59:53 -05:00
nickname commands handled externally
This commit is contained in:
parent
ff03cc903a
commit
c8a576baf2
@ -13,6 +13,10 @@ from sopel_modules.SpiceBot_Events.System import bot_events_check
|
|||||||
@sopel.module.nickname_commands('(.*)')
|
@sopel.module.nickname_commands('(.*)')
|
||||||
def bot_command_nick(bot, trigger):
|
def bot_command_nick(bot, trigger):
|
||||||
|
|
||||||
|
# command must not start with
|
||||||
|
if str(trigger).startswith(tuple(['?'])):
|
||||||
|
return
|
||||||
|
|
||||||
while not bot_events_check(bot, ['1004', '2002']):
|
while not bot_events_check(bot, ['1004', '2002']):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
77
sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py
Normal file
77
sopel_modules/SpiceBot_CommandsQuery/NickQueryCommand.py
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
from __future__ import unicode_literals, absolute_import, division, print_function
|
||||||
|
|
||||||
|
import sopel
|
||||||
|
import sopel.module
|
||||||
|
|
||||||
|
from sopel_modules.SpiceBot_Events.System import bot_events_check
|
||||||
|
from sopel_modules.SpiceBot_SBTools import sopel_triggerargs, similar_list, letters_in_string
|
||||||
|
|
||||||
|
|
||||||
|
import spicemanip
|
||||||
|
|
||||||
|
|
||||||
|
@sopel.module.nickname_commands('^\?(.*)')
|
||||||
|
def query_detection_nick(bot, trigger):
|
||||||
|
|
||||||
|
while not bot_events_check(bot, '2002'):
|
||||||
|
pass
|
||||||
|
|
||||||
|
triggerargs, triggercommand = sopel_triggerargs(bot, trigger, 'nickname_command')
|
||||||
|
|
||||||
|
# command issued, check if valid
|
||||||
|
if not triggercommand or not len(triggercommand):
|
||||||
|
return
|
||||||
|
|
||||||
|
if not letters_in_string(triggercommand):
|
||||||
|
return
|
||||||
|
|
||||||
|
commands_list = dict()
|
||||||
|
for com in bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'].keys():
|
||||||
|
if com not in commands_list.keys():
|
||||||
|
commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'][com]
|
||||||
|
|
||||||
|
if triggercommand.endswith("+"):
|
||||||
|
|
||||||
|
triggercommand = triggercommand[:-1]
|
||||||
|
if not triggercommand or not len(triggercommand):
|
||||||
|
return
|
||||||
|
|
||||||
|
if triggercommand.lower() not in list(commands_list.keys()):
|
||||||
|
dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."]
|
||||||
|
closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse')
|
||||||
|
if len(closestmatches):
|
||||||
|
dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
|
||||||
|
bot.notice(dispmsg, trigger.nick)
|
||||||
|
return
|
||||||
|
|
||||||
|
realcom = triggercommand
|
||||||
|
if "aliasfor" in commands_list[triggercommand].keys():
|
||||||
|
realcom = commands_list[triggercommand]["aliasfor"]
|
||||||
|
validcomlist = commands_list[realcom]["validcoms"]
|
||||||
|
bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick)
|
||||||
|
return
|
||||||
|
|
||||||
|
if triggercommand.endswith("?"):
|
||||||
|
|
||||||
|
triggercommand = triggercommand[:-1]
|
||||||
|
if not triggercommand or not len(triggercommand):
|
||||||
|
return
|
||||||
|
|
||||||
|
closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse')
|
||||||
|
if not len(closestmatches):
|
||||||
|
bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick)
|
||||||
|
else:
|
||||||
|
bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick)
|
||||||
|
return
|
||||||
|
|
||||||
|
commandlist = []
|
||||||
|
for command in list(commands_list.keys()):
|
||||||
|
if command.lower().startswith(str(triggercommand).lower()):
|
||||||
|
commandlist.append(command)
|
||||||
|
|
||||||
|
if not len(commandlist):
|
||||||
|
bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick)
|
||||||
|
else:
|
||||||
|
bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
||||||
@ -28,68 +28,52 @@ def query_detection(bot, trigger):
|
|||||||
return
|
return
|
||||||
|
|
||||||
commands_list = dict()
|
commands_list = dict()
|
||||||
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands'].keys():
|
for commandstype in bot.memory['SpiceBot_CommandsQuery']['commands']["commandstype"].keys():
|
||||||
if commandstype != 'rule':
|
if commandstype not in ['rule', 'nickname']:
|
||||||
for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys():
|
for com in bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype].keys():
|
||||||
if com not in commands_list.keys():
|
if com not in commands_list.keys():
|
||||||
if commandstype == 'nickname':
|
|
||||||
commands_list[str(bot.nick) + " " + com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com]
|
|
||||||
if "aliasfor" in commands_list[str(bot.nick) + " " + com].keys():
|
|
||||||
aliasforcom = commands_list[str(bot.nick) + " " + com]["aliasfor"]
|
|
||||||
commands_list[str(bot.nick) + " " + com]["aliasfor"] = str(bot.nick) + " " + aliasforcom
|
|
||||||
else:
|
|
||||||
commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com]
|
commands_list[com] = bot.memory['SpiceBot_CommandsQuery']['commands'][commandstype][com]
|
||||||
|
|
||||||
botnick_coms = list(bot.memory['SpiceBot_CommandsQuery']['commands']['nickname'].keys())
|
if triggercommand.endswith("+"):
|
||||||
# botnick_coms.extend(bot.memory['SpiceBot_CommandsQuery']['nickrules'])
|
|
||||||
|
|
||||||
if triggercommand.lower().startswith(str(bot.nick).lower()):
|
triggercommand = triggercommand[:-1]
|
||||||
searchlist = botnick_coms
|
if not triggercommand or not len(triggercommand):
|
||||||
searchitem = spicemanip.main([triggercommand].extend(triggerargs), 0)
|
|
||||||
else:
|
|
||||||
searchlist = list(commands_list.keys())
|
|
||||||
searchitem = triggercommand
|
|
||||||
|
|
||||||
if searchitem.endswith("+"):
|
|
||||||
|
|
||||||
searchitem = searchitem[:-1]
|
|
||||||
if not searchitem or not len(searchitem):
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if searchitem.lower() not in searchlist:
|
if triggercommand.lower() not in list(commands_list.keys()):
|
||||||
dispmsg = ["Cannot find any alias commands: No valid commands match " + str(searchitem) + "."]
|
dispmsg = ["Cannot find any alias commands: No valid commands match " + str(triggercommand) + "."]
|
||||||
closestmatches = similar_list(bot, searchitem, searchlist, 10, 'reverse')
|
closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse')
|
||||||
if len(closestmatches):
|
if len(closestmatches):
|
||||||
dispmsg.append("The following commands match " + str(searchitem) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
|
dispmsg.append("The following commands match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".")
|
||||||
bot.notice(dispmsg, trigger.nick)
|
bot.notice(dispmsg, trigger.nick)
|
||||||
return
|
return
|
||||||
|
|
||||||
realcom = searchitem
|
realcom = triggercommand
|
||||||
if "aliasfor" in commands_list[searchitem].keys():
|
if "aliasfor" in commands_list[triggercommand].keys():
|
||||||
realcom = commands_list[searchitem]["aliasfor"]
|
realcom = commands_list[triggercommand]["aliasfor"]
|
||||||
validcomlist = commands_list[realcom]["validcoms"]
|
validcomlist = commands_list[realcom]["validcoms"]
|
||||||
bot.notice("The following commands match " + str(searchitem) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick)
|
bot.notice("The following commands match " + str(triggercommand) + ": " + spicemanip.main(validcomlist, 'andlist') + ".", trigger.nick)
|
||||||
return
|
return
|
||||||
|
|
||||||
if searchitem.endswith("?"):
|
if triggercommand.endswith("?"):
|
||||||
|
|
||||||
searchitem = searchitem[:-1]
|
triggercommand = triggercommand[:-1]
|
||||||
if not searchitem or not len(searchitem):
|
if not triggercommand or not len(triggercommand):
|
||||||
return
|
return
|
||||||
|
|
||||||
closestmatches = similar_list(bot, searchitem, searchlist, 10, 'reverse')
|
closestmatches = similar_list(bot, triggercommand, list(commands_list.keys()), 10, 'reverse')
|
||||||
if not len(closestmatches):
|
if not len(closestmatches):
|
||||||
bot.notice("Cannot find any similar commands for " + str(searchitem) + ".", trigger.nick)
|
bot.notice("Cannot find any similar commands for " + str(triggercommand) + ".", trigger.nick)
|
||||||
else:
|
else:
|
||||||
bot.notice("The following commands may match " + str(searchitem) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick)
|
bot.notice("The following commands may match " + str(triggercommand) + ": " + spicemanip.main(closestmatches, 'andlist') + ".", trigger.nick)
|
||||||
return
|
return
|
||||||
|
|
||||||
commandlist = []
|
commandlist = []
|
||||||
for command in searchlist:
|
for command in list(commands_list.keys()):
|
||||||
if command.lower().startswith(str(searchitem).lower()):
|
if command.lower().startswith(str(triggercommand).lower()):
|
||||||
commandlist.append(command)
|
commandlist.append(command)
|
||||||
|
|
||||||
if not len(commandlist):
|
if not len(commandlist):
|
||||||
bot.notice("No commands start with " + str(searchitem) + ".", trigger.nick)
|
bot.notice("No commands start with " + str(triggercommand) + ".", trigger.nick)
|
||||||
else:
|
else:
|
||||||
bot.notice("The following commands start with " + str(searchitem) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
bot.notice("The following commands start with " + str(triggercommand) + ": " + spicemanip.main(commandlist, 'andlist') + ".", trigger.nick)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from __future__ import unicode_literals, absolute_import, division, print_functi
|
|||||||
|
|
||||||
from .CommandsQuery import *
|
from .CommandsQuery import *
|
||||||
from .QueryCommand import *
|
from .QueryCommand import *
|
||||||
|
from .NickQueryCommand import *
|
||||||
|
|
||||||
__author__ = 'Sam Zick'
|
__author__ = 'Sam Zick'
|
||||||
__email__ = 'sam@deathbybandaid.net'
|
__email__ = 'sam@deathbybandaid.net'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user