From 91c3688018344796bd2d26f2cf56ad374d45a5c6 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 30 Nov 2019 20:25:52 +0000 Subject: [PATCH] only add BufferLine to buffer *after* received.message.* callback --- modules/line_handler/message.py | 21 ++++++++++----------- src/IRCBuffer.py | 13 +------------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/modules/line_handler/message.py b/modules/line_handler/message.py index ae16a1f6..fa36dbc2 100644 --- a/modules/line_handler/message.py +++ b/modules/line_handler/message.py @@ -1,4 +1,4 @@ -from src import utils +from src import IRCBuffer, utils def _from_self(server, source): if source: @@ -90,21 +90,20 @@ def message(events, event): context = "channel" if is_channel else "private" hook = events.on(direction).on(event_type).on(context) + buffer_line = None + if message: + buffer_line = IRCBuffer.BufferLine(user.nickname, message, action, + event["line"].tags, from_self, event["line"].command) + + buffer_obj = target_obj if is_channel: - buffer_line = None - if message: - buffer_line = target_obj.buffer.add_message(user.nickname, message, - action, event["line"].tags, from_self) hook.call(channel=target_obj, buffer_line=buffer_line, **kwargs) else: - buffer_obj = target_obj if not from_self: buffer_obj = user - buffer_line = None - if message: - buffer_line = buffer_obj.buffer.add_message(user.nickname, message, - action, event["line"].tags, from_self) - hook.call(buffer_line=buffer_line, **kwargs) + + if buffer_line: + buffer_obj.buffer.add(buffer_line) diff --git a/src/IRCBuffer.py b/src/IRCBuffer.py index 782a6dc1..3e8f5aa9 100644 --- a/src/IRCBuffer.py +++ b/src/IRCBuffer.py @@ -26,19 +26,8 @@ class Buffer(object): self._lines = collections.deque(maxlen=MAX_LINES ) # type: typing.Deque[BufferLine] - def _add_message(self, sender: str, message: str, action: bool, tags: dict, - from_self: bool, method: str) -> BufferLine: - line = BufferLine(sender, message, action, tags, from_self, method) + def add(self, line: BufferLine): self._lines.appendleft(line) - return line - def add_message(self, sender: str, message: str, action: bool, tags: dict, - from_self: bool=False) -> BufferLine: - return self._add_message(sender, message, action, tags, from_self, - "PRIVMSG") - def add_notice(self, sender: str, message: str, tags: dict, - from_self: bool=False): - return self._add_message(sender, message, False, tags, from_self, - "NOTICE") def get(self, index: int=0, **kwargs) -> typing.Optional[BufferLine]: from_self = kwargs.get("from_self", True)