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
This commit is contained in:
parent
0003c0c16e
commit
a79d0cdd9f
|
@ -148,12 +148,33 @@ class DrReactor(irc.client.Reactor):
|
||||||
log.debug("EVENT: e[%s] s[%s] t[%s] a[%s]", event.type, event.source,
|
log.debug("EVENT: e[%s] s[%s] t[%s] a[%s]", event.type, event.source,
|
||||||
event.target, event.arguments)
|
event.target, event.arguments)
|
||||||
|
|
||||||
|
# set up some default stuff
|
||||||
event._recursing = False
|
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)
|
self.try_recursion(connection, event)
|
||||||
|
|
||||||
# only do aliasing for pubmsg/privmsg
|
|
||||||
if event.type in ['pubmsg', 'privmsg']:
|
if event.type in ['pubmsg', 'privmsg']:
|
||||||
what = event.arguments[0]
|
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<addressed_msg>.*)'.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)
|
log.debug("checking for alias for %s", what)
|
||||||
|
|
||||||
for alias in Alias.objects.all():
|
for alias in Alias.objects.all():
|
||||||
|
|
Loading…
Reference in New Issue