diff options
| author | 2020-01-17 14:19:30 +0000 | |
|---|---|---|
| committer | 2020-01-17 14:19:30 +0000 | |
| commit | f8b509ef94a9dff01f4d7e860b20ebecbc3aff24 (patch) | |
| tree | efd4d2c13ed4673891f6f0ee90e2a92f0caffce6 /src | |
| parent | make `++asd++` count only as `++` on `++help` (diff) | |
| signature | ||
give ever BufferLine an ID (IRCv3 msgid or uuid4())
Diffstat (limited to 'src')
| -rw-r--r-- | src/IRCBuffer.py | 8 | ||||
| -rw-r--r-- | src/core_modules/line_handler/message.py | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/IRCBuffer.py b/src/IRCBuffer.py index 3e8f5aa9..dbd59b3b 100644 --- a/src/IRCBuffer.py +++ b/src/IRCBuffer.py @@ -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: diff --git a/src/core_modules/line_handler/message.py b/src/core_modules/line_handler/message.py index 035116b6..8b231ede 100644 --- a/src/core_modules/line_handler/message.py +++ b/src/core_modules/line_handler/message.py @@ -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: |
