support multiple strings as counting as nick highlights

also, treat @nicks as being addressed, since we are doing discord
through bitlbee now
keep-around/058993913747f62edfc1dea24a72d446a9770b2c
Brian S. Stephan 2019-01-10 08:48:15 -06:00
parent 2bae93778e
commit 0589939137
3 changed files with 15 additions and 10 deletions

View File

@ -177,6 +177,10 @@ IRCBOT_XMLRPC_HOST = 'localhost'
IRCBOT_XMLRPC_PORT = 13132
# nick hack for discord through bitlbee
ADDITIONAL_NICK_MATCHES = []
# IRC module stuff
# karma

View File

@ -163,8 +163,8 @@ class DrReactor(irc.client.Reactor):
event.original_msg = what
# check if we were addressed or not
my_nick = connection.get_nickname()
addressed_pattern = r'^{0:s}[:,]\s+(?P<addressed_msg>.*)'.format(my_nick)
all_nicks = '|'.join(settings.ADDITIONAL_NICK_MATCHES + [connection.get_nickname()])
addressed_pattern = r'^(({nicks})[:,]|@({nicks}))\s+(?P<addressed_msg>.*)'.format(nicks=all_nicks)
match = re.match(addressed_pattern, what, re.IGNORECASE)
if match:
event.addressed = True

View File

@ -2,6 +2,7 @@ import logging
import re
import irc.client
from django.conf import settings
from ircbot.lib import Plugin, reply_destination_for_event
from ircbot.models import IrcChannel
@ -64,8 +65,8 @@ class Markov(Plugin):
"""Learn from IRC chatter."""
what = event.arguments[0]
my_nick = connection.get_nickname()
trimmed_what = re.sub(r'^{0:s}[:,]\s+'.format(my_nick), '', what)
all_nicks = '|'.join(settings.ADDITIONAL_NICK_MATCHES + [connection.get_nickname()])
trimmed_what = re.sub(r'^(({nicks})[:,]|@({nicks}))\s+'.format(nicks=all_nicks), '', what)
nick = irc.client.NickMask(event.source).nick
target = reply_destination_for_event(event)
@ -84,16 +85,16 @@ class Markov(Plugin):
context = markovlib.get_or_create_target_context(target)
markovlib.learn_line(trimmed_what, context)
log.debug("searching '%s' for '%s'", what, my_nick)
if re.search(my_nick, what, re.IGNORECASE) is not None:
log.debug("searching '%s' for '%s'", what, all_nicks)
if re.search(all_nicks, what, re.IGNORECASE) is not None:
context = markovlib.get_or_create_target_context(target)
addressed_pattern = r'^{0:s}[:,]\s+(.*)'.format(my_nick)
addressed_re = re.compile(addressed_pattern)
if addressed_re.match(what):
addressed_pattern = r'^(({nicks})[:,]|@({nicks}))\s+(?P<addressed_msg>.*)'.format(nicks=all_nicks)
match = re.match(addressed_pattern, what, re.IGNORECASE)
if match:
# i was addressed directly, so respond, addressing
# the speaker
topics = [x for x in addressed_re.match(what).group(1).split(' ') if len(x) >= 3]
topics = [x for x in match.group('addressed_msg').split(' ') if len(x) >= 3]
return self.bot.reply(event, "{0:s}: {1:s}"
"".format(nick, " ".join(markovlib.generate_line(context, topics=topics))))