give BufferLine.id default value, overwrite in ircv3_msgid.py
This commit is contained in:
parent
5c7026886d
commit
95668f2b8b
3 changed files with 18 additions and 11 deletions
|
@ -1,12 +1,10 @@
|
|||
import collections, dataclasses, datetime, re, typing
|
||||
import collections, dataclasses, datetime, re, typing, uuid
|
||||
from src import IRCBot, IRCServer, utils
|
||||
|
||||
MAX_LINES = 64
|
||||
|
||||
@dataclasses.dataclass
|
||||
class BufferLine(object):
|
||||
id: str
|
||||
timestamp: datetime.datetime
|
||||
sender: str
|
||||
message: str
|
||||
action: bool
|
||||
|
@ -19,6 +17,10 @@ class BufferLine(object):
|
|||
notes: typing.Dict[str, str] = dataclasses.field(
|
||||
default_factory=dict)
|
||||
|
||||
id: str = dataclasses.field(default_factory=uuid.uuid4)
|
||||
timestamp: datetime.datetime = dataclasses.field(
|
||||
default_factory=utils.datetime.utcnow)
|
||||
|
||||
class BufferLineMatch(object):
|
||||
def __init__(self, line: BufferLine, match: str):
|
||||
self.line = line
|
||||
|
|
|
@ -3,25 +3,32 @@ from src import ModuleManager, utils
|
|||
TAG = utils.irc.MessageTag("msgid", "draft/msgid")
|
||||
|
||||
class Module(ModuleManager.BaseModule):
|
||||
def _on_channel(self, channel, tags):
|
||||
def _on_channel(self, channel, tags, buffer_line):
|
||||
msgid = TAG.get_value(tags)
|
||||
if not msgid == None:
|
||||
channel.set_setting("last-msgid", msgid)
|
||||
|
||||
if buffer_line:
|
||||
buffer_line.id = msgid
|
||||
|
||||
@utils.hook("received.message.channel")
|
||||
@utils.hook("send.message.channel")
|
||||
@utils.hook("received.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("send.tagmsg.channel")
|
||||
def on_channel(self, event):
|
||||
self._on_channel(event["channel"], event["tags"])
|
||||
def tagmsg(self, event):
|
||||
self._on_channel(event["channel"], event["tags"], None)
|
||||
|
||||
|
||||
@utils.hook("received.ctcp.request")
|
||||
@utils.hook("received.ctcp.response")
|
||||
def ctcp(self, event):
|
||||
if event["is_channel"]:
|
||||
self._on_channel(event["target"], event["tags"])
|
||||
self._on_channel(event["target"], event["tags"], None)
|
||||
|
||||
@utils.hook("postprocess.command")
|
||||
def postprocess_command(self, event):
|
||||
|
|
|
@ -97,13 +97,11 @@ def message(events, event):
|
|||
|
||||
context = "channel" if is_channel else "private"
|
||||
hook = events.on(direction).on(event_type).on(context)
|
||||
message_id = event["line"].tags.get("id", str(uuid.uuid4()))
|
||||
|
||||
buffer_line = None
|
||||
if message:
|
||||
buffer_line = IRCBuffer.BufferLine(message_id, utils.datetime.utcnow(),
|
||||
user.nickname, message, action, event["line"].tags, from_self,
|
||||
event["line"].command)
|
||||
buffer_line = IRCBuffer.BufferLine(user.nickname, message, action,
|
||||
event["line"].tags, from_self, event["line"].command)
|
||||
|
||||
buffer_obj = target_obj
|
||||
if is_channel:
|
||||
|
|
Loading…
Reference in a new issue