only add BufferLine to buffer *after* received.message.* callback

This commit is contained in:
jesopo 2019-11-30 20:25:52 +00:00
parent d688636909
commit 91c3688018
2 changed files with 11 additions and 23 deletions

View file

@ -1,4 +1,4 @@
from src import utils from src import IRCBuffer, utils
def _from_self(server, source): def _from_self(server, source):
if source: if source:
@ -90,21 +90,20 @@ 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)
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: 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) hook.call(channel=target_obj, buffer_line=buffer_line, **kwargs)
else: else:
buffer_obj = target_obj buffer_obj = target_obj
if not from_self: if not from_self:
buffer_obj = user 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) hook.call(buffer_line=buffer_line, **kwargs)
if buffer_line:
buffer_obj.buffer.add(buffer_line)

View file

@ -26,19 +26,8 @@ class Buffer(object):
self._lines = collections.deque(maxlen=MAX_LINES self._lines = collections.deque(maxlen=MAX_LINES
) # type: typing.Deque[BufferLine] ) # type: typing.Deque[BufferLine]
def _add_message(self, sender: str, message: str, action: bool, tags: dict, def add(self, line: BufferLine):
from_self: bool, method: str) -> BufferLine:
line = BufferLine(sender, message, action, tags, from_self, method)
self._lines.appendleft(line) 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]: def get(self, index: int=0, **kwargs) -> typing.Optional[BufferLine]:
from_self = kwargs.get("from_self", True) from_self = kwargs.get("from_self", True)