remove IRCBuffer.skip_next (not used), pass buffer lines on message events

This commit is contained in:
jesopo 2019-11-27 12:06:57 +00:00
parent 6a02accb63
commit 9972125b24
3 changed files with 24 additions and 21 deletions

View file

@ -315,7 +315,8 @@ class Module(ModuleManager.BaseModule):
self.command(event["server"], event["channel"],
event["target_str"], True, event["user"], command,
args_split, event["line"], hook,
command_prefix=command_prefix)
command_prefix=command_prefix,
buffer_line=event["buffer_line"])
else:
self.events.on("unknown.command").call(server=event["server"],
target=event["channel"], user=event["user"],
@ -336,7 +337,8 @@ class Module(ModuleManager.BaseModule):
event["target_str"], True, event["user"], command,
"", event["line"], hook, match=match,
message=event["message"], command_prefix="",
action=event["action"])
action=event["action"],
buffer_line=event["buffer_line"])
if res:
break
@ -365,7 +367,8 @@ class Module(ModuleManager.BaseModule):
if hook:
self.command(event["server"], event["user"],
event["user"].nickname, False, event["user"], command,
args_split, event["line"], hook, command_prefix="")
args_split, event["line"], hook, command_prefix="",
buffer_line=event["buffer_line"])
else:
self.events.on("unknown.command").call(server=event["server"],
target=event["user"], user=event["user"], command=command,

View file

@ -91,17 +91,20 @@ def message(events, event):
hook = events.on(direction).on(event_type).on(context)
if is_channel:
hook.call(channel=target_obj, **kwargs)
buffer_line = None
if message:
target_obj.buffer.add_message(user.nickname, message, action,
event["line"].tags, from_self)
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:
hook.call(**kwargs)
buffer_obj = target_obj
if not from_self:
buffer_obj = user
buffer_line = None
if message:
buffer_obj.buffer.add_message(user.nickname, message, action,
event["line"].tags, from_self)
buffer_line = buffer_obj.buffer.add_message(user.nickname, message,
action, event["line"].tags, from_self)
hook.call(buffer_line=buffer_line, **kwargs)

View file

@ -24,20 +24,20 @@ class Buffer(object):
self.server = server
self._lines = collections.deque(maxlen=MAX_LINES
) # type: typing.Deque[BufferLine]
self._skip_next = False
def _add_message(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool, method: str):
if not self._skip_next:
from_self: bool, method: str) -> BufferLine:
line = BufferLine(sender, message, action, tags, from_self, method)
self._lines.appendleft(line)
self._skip_next = False
return line
def add_message(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool=False):
self._add_message(sender, message, action, tags, from_self, "PRIVMSG")
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):
self._add_message(sender, message, False, tags, from_self, "NOTICE")
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)
@ -83,6 +83,3 @@ class Buffer(object):
if len(found_lines) == max:
break
return found_lines
def skip_next(self):
self._skip_next = True