Encyclopedia: Rework message parsing.
This commit is contained in:
parent
902534d10b
commit
db29965a33
|
@ -24,7 +24,7 @@ import supybot
|
||||||
import supybot.world as world
|
import supybot.world as world
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
|
|
||||||
__version__ = "3.6.0"
|
__version__ = "3.7.0"
|
||||||
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@gmail.com")
|
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@gmail.com")
|
||||||
__contributors__ = {
|
__contributors__ = {
|
||||||
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],
|
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],
|
||||||
|
|
|
@ -449,7 +449,6 @@ class Encyclopedia(callbacks.Plugin):
|
||||||
if text.split()[0].lower() in self.registryValue('ignores', channel):
|
if text.split()[0].lower() in self.registryValue('ignores', channel):
|
||||||
return
|
return
|
||||||
|
|
||||||
doChanMsg = True # Send message to channel
|
|
||||||
display = None # Set display type
|
display = None # Set display type
|
||||||
edit = None
|
edit = None
|
||||||
if not channel:
|
if not channel:
|
||||||
|
@ -466,44 +465,43 @@ class Encyclopedia(callbacks.Plugin):
|
||||||
return
|
return
|
||||||
|
|
||||||
irc = callbacks.ReplyIrcProxy(irc, msg)
|
irc = callbacks.ReplyIrcProxy(irc, msg)
|
||||||
|
ret, retmsg = '', ''
|
||||||
|
|
||||||
# Now switch between actions
|
# Now switch between actions
|
||||||
ret, retmsg = '', ''
|
if display:
|
||||||
term = self.get_target(irc, msg.nick, text, target)
|
|
||||||
lower_term = term[0].lower()
|
|
||||||
|
|
||||||
if re.match(r"please\s+see\s+((%s|(the\s+)?bot)(\s*'?s)?\s+\S+|\S+.*\s+\S+\s+(%s|(the\s+)?bot)\b)" % (re.escape(irc.nick), re.escape(irc.nick)), text, re.I):
|
|
||||||
doChanMsg = False
|
|
||||||
|
|
||||||
if lower_term == "search": # Usage info for the !search command
|
|
||||||
ret = "Search factoids for term: !search <term>"
|
|
||||||
target = term[1]
|
|
||||||
retmsg = term[2]
|
|
||||||
elif re.match(r"^seen\b", lower_term): # Some people expect a '!seen <nick>' command
|
|
||||||
ret = "I have no seen command"
|
|
||||||
retmsg = "%s: " % msg.nick if term[2] else '' # Redirect back at the caller, rather than the target
|
|
||||||
elif lower_term.startswith("google "): # Some people expect a '!google <term...>' command
|
|
||||||
ret = "I have no google command, use https://www.google.com/"
|
|
||||||
retmsg = "%s: " % msg.nick if term[2] else '' # Redirect back at the caller, rather than the target
|
|
||||||
elif re.match(r"^what'?s?\b", lower_term): # Try and catch people saying "ubottu: what is ...?"
|
|
||||||
ret = "I am only a bot, please don't think I'm intelligent :)"
|
|
||||||
retmsg = "%s: " % msg.nick if channel else ''
|
|
||||||
|
|
||||||
# Lookup, search or edit?
|
|
||||||
elif lower_term.startswith('search '):
|
|
||||||
ret = self.search_factoid(text[7:].strip(), channel)
|
|
||||||
elif lower_term.startswith('delete '):
|
|
||||||
edit = 'delete'
|
|
||||||
elif re.match(r'^no[\s,]+[^|\s]+[^|]*?\s+is(\s+|\b)\S+', text, re.I) \
|
|
||||||
or re.match(r'^[^|\s]+[^|]*?\s*(\s+is\s*<sed>|=~|~=)\s*\S+', text, re.I) \
|
|
||||||
or lower_term.startswith(('forget ', 'unforget ')):
|
|
||||||
edit = 'edit'
|
|
||||||
elif re.match(r'^[^|\s]+[^|]*?\s+is(\s+|\b)\S+', text, re.I):
|
|
||||||
edit = 'add'
|
|
||||||
else:
|
|
||||||
if not display:
|
|
||||||
text, target, retmsg = term
|
|
||||||
ret = self.factoid_lookup(text, channel, msg.nick, display)
|
ret = self.factoid_lookup(text, channel, msg.nick, display)
|
||||||
|
else:
|
||||||
|
term = self.get_target(irc, msg.nick, text, target)
|
||||||
|
lower_term = term[0].lower()
|
||||||
|
|
||||||
|
if lower_term == "search": # Usage info for the !search command
|
||||||
|
ret = "Search factoids for term: !search <term>"
|
||||||
|
target = term[1]
|
||||||
|
retmsg = term[2]
|
||||||
|
elif re.match(r"^seen\b", lower_term): # Some people expect a '!seen <nick>' command
|
||||||
|
ret = "I have no seen command"
|
||||||
|
retmsg = "%s: " % msg.nick if term[2] else '' # Redirect back at the caller, rather than the target
|
||||||
|
elif lower_term.startswith("google "): # Some people expect a '!google <term...>' command
|
||||||
|
ret = "I have no google command, use https://www.google.com/"
|
||||||
|
retmsg = "%s: " % msg.nick if term[2] else '' # Redirect back at the caller, rather than the target
|
||||||
|
elif re.match(r"^what'?s?\b", lower_term): # Try and catch people saying "ubottu: what is ...?"
|
||||||
|
ret = "I am only a bot, please don't think I'm intelligent :)"
|
||||||
|
retmsg = "%s: " % msg.nick if channel else ''
|
||||||
|
|
||||||
|
# Lookup, search or edit?
|
||||||
|
elif lower_term.startswith('search '):
|
||||||
|
ret = self.search_factoid(text[7:].strip(), channel)
|
||||||
|
elif lower_term.startswith('delete '):
|
||||||
|
edit = 'delete'
|
||||||
|
elif re.match(r'^no[\s,]+[^|\s]+[^|]*?\s+is(\s+|\b)\S+', text, re.I) \
|
||||||
|
or re.match(r'^[^|\s]+[^|]*?\s*(\s+is\s*<sed>|=~|~=)\s*\S+', text, re.I) \
|
||||||
|
or lower_term.startswith(('forget ', 'unforget ')):
|
||||||
|
edit = 'edit'
|
||||||
|
elif re.match(r'^[^|\s]+[^|]*?\s+is(\s+|\b)\S+', text, re.I):
|
||||||
|
edit = 'add'
|
||||||
|
else:
|
||||||
|
text, target, retmsg = term
|
||||||
|
ret = self.factoid_lookup(text, channel, msg.nick, display)
|
||||||
|
|
||||||
if edit:
|
if edit:
|
||||||
check = getattr(self, 'factoid_%s_check' % edit)(text, channel, msg.nick)
|
check = getattr(self, 'factoid_%s_check' % edit)(text, channel, msg.nick)
|
||||||
|
@ -559,7 +557,7 @@ class Encyclopedia(callbacks.Plugin):
|
||||||
if retmsg and checkUrl(retmsg):
|
if retmsg and checkUrl(retmsg):
|
||||||
# !ops factoid called with a URL, most likely spam
|
# !ops factoid called with a URL, most likely spam
|
||||||
return
|
return
|
||||||
if doChanMsg and channel and not irc.isChannel(target) \
|
if channel and not irc.isChannel(target) \
|
||||||
and target in irc.state.channels[channel].users:
|
and target in irc.state.channels[channel].users:
|
||||||
myqueue(irc, channel, "%s: Please see my private message" % target)
|
myqueue(irc, channel, "%s: Please see my private message" % target)
|
||||||
myqueue(irc, target, retmsg + ret[0])
|
myqueue(irc, target, retmsg + ret[0])
|
||||||
|
|
Loading…
Reference in New Issue