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

View File

@ -18,7 +18,7 @@ from io import StringIO
from time import time 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") UserPrefix = namedtuple("UserPrefix", "nick username hostname")
ServerPrefix = namedtuple("ServerPrefix", "hostname") ServerPrefix = namedtuple("ServerPrefix", "hostname")
@ -258,6 +258,7 @@ class IRCCore(object):
self.log.warning("Invalid hook - %s" % command) self.log.warning("Invalid hook - %s" % command)
return False return False
@staticmethod
def packetAsObject(command, args, prefix, trailing): def packetAsObject(command, args, prefix, trailing):
"""Given an irc message's args, prefix, and trailing data return an object with these properties """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 :type trailing: str
:returns: object -- a IRCEvent object with the ``args``, ``prefix``, ``trailing``""" :returns: object -- a IRCEvent object with the ``args``, ``prefix``, ``trailing``"""
return IRCEvent(command, args, prefix = IRCCore.decodePrefix(prefix) if prefix else None
IRCCore.decodePrefix(prefix) if prefix else None,
trailing) 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 " " Utility methods "
@staticmethod @staticmethod

View File

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