give ever BufferLine an ID (IRCv3 msgid or uuid4())
This commit is contained in:
parent
1e50c5f2d6
commit
f8b509ef94
2 changed files with 12 additions and 2 deletions
|
@ -5,6 +5,7 @@ MAX_LINES = 64
|
|||
|
||||
@dataclasses.dataclass
|
||||
class BufferLine(object):
|
||||
id: str
|
||||
sender: str
|
||||
message: str
|
||||
action: bool
|
||||
|
@ -44,6 +45,7 @@ class Buffer(object):
|
|||
else:
|
||||
for line in self._lines:
|
||||
yield line
|
||||
|
||||
def find(self, pattern: typing.Union[str, typing.Pattern[str]], **kwargs
|
||||
) -> typing.Optional[BufferLineMatch]:
|
||||
from_self = kwargs.get("from_self", True)
|
||||
|
@ -64,6 +66,12 @@ class Buffer(object):
|
|||
return BufferLineMatch(line, match.group(0))
|
||||
return None
|
||||
|
||||
def find_id(self, id: str) -> typing.Optional[BufferLine]:
|
||||
for line in self._lines:
|
||||
if line.id == id:
|
||||
return line
|
||||
return None
|
||||
|
||||
def find_from(self, nickname: str) -> typing.Optional[BufferLine]:
|
||||
lines = self.find_many_from(nickname, 1)
|
||||
if lines:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import uuid
|
||||
from src import IRCBuffer, utils
|
||||
|
||||
def _from_self(server, source):
|
||||
|
@ -96,11 +97,12 @@ 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(user.nickname, message, action,
|
||||
event["line"].tags, from_self, event["line"].command)
|
||||
buffer_line = IRCBuffer.BufferLine(message_id, 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