From a79d0cdd9f8bf0cea9a405d8865613db8a40aeb0 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 10 Mar 2017 18:13:47 -0600 Subject: [PATCH] bot: add a bunch of event attrs related to msgs - event.addressed - msg started with 'bot: ' - event.original_msg - the pub/privmsg - event.addressed_msg - pub/privmsg minus 'bot: ' - event.sender_nick - nick of event.source - event.sent_location - channel or nick of event.source - event.in_privmsg - if the event was in a privmsg or not closes bss/dr.botzo#32 --- ircbot/bot.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ircbot/bot.py b/ircbot/bot.py index 2afd1d5..4c3f225 100644 --- a/ircbot/bot.py +++ b/ircbot/bot.py @@ -148,12 +148,33 @@ class DrReactor(irc.client.Reactor): log.debug("EVENT: e[%s] s[%s] t[%s] a[%s]", event.type, event.source, event.target, event.arguments) + # set up some default stuff event._recursing = False + event.addressed = False + event.original_msg = None + event.addressed_msg = None + + sender_nick = irc.client.NickMask(event.source).nick + sent_location = ircbotlib.reply_destination_for_event(event) + event.sender_nick = sender_nick + event.sent_location = sent_location + event.in_privmsg = sender_nick == sent_location + self.try_recursion(connection, event) - # only do aliasing for pubmsg/privmsg if event.type in ['pubmsg', 'privmsg']: what = event.arguments[0] + event.original_msg = what + + # check if we were addressed or not + my_nick = connection.get_nickname() + addressed_pattern = r'^{0:s}[:,]\s+(?P.*)'.format(my_nick) + match = re.match(addressed_pattern, what, re.IGNORECASE) + if match: + event.addressed = True + event.addressed_msg = match.group('addressed_msg') + + # only do aliasing for pubmsg/privmsg log.debug("checking for alias for %s", what) for alias in Alias.objects.all():