give BufferLine.id default value, overwrite in ircv3_msgid.py

This commit is contained in:
jesopo 2020-01-17 16:28:23 +00:00
parent 5c7026886d
commit 95668f2b8b
3 changed files with 18 additions and 11 deletions

View file

@ -1,12 +1,10 @@
import collections, dataclasses, datetime, re, typing import collections, dataclasses, datetime, re, typing, uuid
from src import IRCBot, IRCServer, utils from src import IRCBot, IRCServer, utils
MAX_LINES = 64 MAX_LINES = 64
@dataclasses.dataclass @dataclasses.dataclass
class BufferLine(object): class BufferLine(object):
id: str
timestamp: datetime.datetime
sender: str sender: str
message: str message: str
action: bool action: bool
@ -19,6 +17,10 @@ class BufferLine(object):
notes: typing.Dict[str, str] = dataclasses.field( notes: typing.Dict[str, str] = dataclasses.field(
default_factory=dict) default_factory=dict)
id: str = dataclasses.field(default_factory=uuid.uuid4)
timestamp: datetime.datetime = dataclasses.field(
default_factory=utils.datetime.utcnow)
class BufferLineMatch(object): class BufferLineMatch(object):
def __init__(self, line: BufferLine, match: str): def __init__(self, line: BufferLine, match: str):
self.line = line self.line = line

View file

@ -3,25 +3,32 @@ from src import ModuleManager, utils
TAG = utils.irc.MessageTag("msgid", "draft/msgid") TAG = utils.irc.MessageTag("msgid", "draft/msgid")
class Module(ModuleManager.BaseModule): class Module(ModuleManager.BaseModule):
def _on_channel(self, channel, tags): def _on_channel(self, channel, tags, buffer_line):
msgid = TAG.get_value(tags) msgid = TAG.get_value(tags)
if not msgid == None: if not msgid == None:
channel.set_setting("last-msgid", msgid) channel.set_setting("last-msgid", msgid)
if buffer_line:
buffer_line.id = msgid
@utils.hook("received.message.channel") @utils.hook("received.message.channel")
@utils.hook("send.message.channel") @utils.hook("send.message.channel")
@utils.hook("received.notice.channel") @utils.hook("received.notice.channel")
@utils.hook("send.notice.channel") @utils.hook("send.notice.channel")
def on_channel(self, event):
self._on_channel(event["channel"], event["tags"], event["buffer_line"])
@utils.hook("received.tagmsg.channel") @utils.hook("received.tagmsg.channel")
@utils.hook("send.tagmsg.channel") @utils.hook("send.tagmsg.channel")
def on_channel(self, event): def tagmsg(self, event):
self._on_channel(event["channel"], event["tags"]) self._on_channel(event["channel"], event["tags"], None)
@utils.hook("received.ctcp.request") @utils.hook("received.ctcp.request")
@utils.hook("received.ctcp.response") @utils.hook("received.ctcp.response")
def ctcp(self, event): def ctcp(self, event):
if event["is_channel"]: if event["is_channel"]:
self._on_channel(event["target"], event["tags"]) self._on_channel(event["target"], event["tags"], None)
@utils.hook("postprocess.command") @utils.hook("postprocess.command")
def postprocess_command(self, event): def postprocess_command(self, event):

View file

@ -97,13 +97,11 @@ def message(events, event):
context = "channel" if is_channel else "private" context = "channel" if is_channel else "private"
hook = events.on(direction).on(event_type).on(context) hook = events.on(direction).on(event_type).on(context)
message_id = event["line"].tags.get("id", str(uuid.uuid4()))
buffer_line = None buffer_line = None
if message: if message:
buffer_line = IRCBuffer.BufferLine(message_id, utils.datetime.utcnow(), buffer_line = IRCBuffer.BufferLine(user.nickname, message, action,
user.nickname, message, action, event["line"].tags, from_self, event["line"].tags, from_self, event["line"].command)
event["line"].command)
buffer_obj = target_obj buffer_obj = target_obj
if is_channel: if is_channel: