add replyto field to privmsg ircevent messages

This commit is contained in:
dave 2020-07-02 11:20:00 -07:00
parent f2c6668e18
commit 235921fbab
3 changed files with 21 additions and 16 deletions

View File

@ -9,7 +9,7 @@ from msgbus.client import MsgbusSubClient
import pyircbot
import traceback
from pyircbot.pyircbot import PrimitiveBot
from pyircbot.irccore import IRCEvent, UserPrefix
from pyircbot.irccore import IRCEvent, UserPrefix, IRCCore
from pyircbot.common import TouchReload
from json import dumps
@ -57,12 +57,10 @@ class PyIRCBotSub(PrimitiveBot):
args, sender, trailing, extras = loads(rest)
nick, username, hostname = extras["prefix"]
msg = IRCEvent(command.upper(),
args,
UserPrefix(nick,
username,
hostname),
trailing)
msg = IRCCore.packetAsObject(command.upper(),
args,
f"{nick}!{username}@{hostname}", # hack
trailing)
for module_name, module in self.moduleInstances.items():
for hook in module.irchooks:

View File

@ -18,7 +18,7 @@ from io import StringIO
from time import time
IRCEvent = namedtuple("IRCEvent", "command args prefix trailing")
IRCEvent = namedtuple("IRCEvent", "command args prefix trailing replyto")
UserPrefix = namedtuple("UserPrefix", "nick username hostname")
ServerPrefix = namedtuple("ServerPrefix", "hostname")
@ -258,6 +258,7 @@ class IRCCore(object):
self.log.warning("Invalid hook - %s" % command)
return False
@staticmethod
def packetAsObject(command, args, prefix, trailing):
"""Given an irc message's args, prefix, and trailing data return an object with these properties
@ -269,9 +270,15 @@ class IRCCore(object):
:type trailing: str
:returns: object -- a IRCEvent object with the ``args``, ``prefix``, ``trailing``"""
return IRCEvent(command, args,
IRCCore.decodePrefix(prefix) if prefix else None,
trailing)
prefix = IRCCore.decodePrefix(prefix) if prefix else None
replyto = None
if command == "PRIVMSG":
# prefix will always be set for PRIVMSG
# TODO server side fuzzing
replyto = args[0] if args[0].startswith("#") else prefix.nick
return IRCEvent(command, args, prefix, trailing, replyto)
" Utility methods "
@staticmethod

View File

@ -5,7 +5,7 @@ from threading import Thread
from random import randint
from pyircbot import PyIRCBot
from pyircbot.pyircbot import PrimitiveBot
from pyircbot.irccore import IRCEvent, UserPrefix
from pyircbot.irccore import IRCEvent, UserPrefix, IRCCore
from unittest.mock import MagicMock
from tests.miniircd import Server as MiniIrcServer
@ -27,10 +27,10 @@ class FakeBaseBot(PrimitiveBot):
"""
Feed a message into the bot.
"""
msg = IRCEvent(cmd,
args,
UserPrefix(*sender),
trailing)
msg = IRCCore.packetAsObject(cmd,
args,
f"{sender[0]}!{sender[1]}@{sender[2]}", # hack
trailing)
for module_name, module in self.moduleInstances.items():# TODO dedupe this block across the various base classes
for hook in module.irchooks: