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"], self.command(event["server"], event["channel"],
event["target_str"], True, event["user"], command, event["target_str"], True, event["user"], command,
args_split, event["line"], hook, args_split, event["line"], hook,
command_prefix=command_prefix) command_prefix=command_prefix,
buffer_line=event["buffer_line"])
else: else:
self.events.on("unknown.command").call(server=event["server"], self.events.on("unknown.command").call(server=event["server"],
target=event["channel"], user=event["user"], target=event["channel"], user=event["user"],
@ -336,7 +337,8 @@ class Module(ModuleManager.BaseModule):
event["target_str"], True, event["user"], command, event["target_str"], True, event["user"], command,
"", event["line"], hook, match=match, "", event["line"], hook, match=match,
message=event["message"], command_prefix="", message=event["message"], command_prefix="",
action=event["action"]) action=event["action"],
buffer_line=event["buffer_line"])
if res: if res:
break break
@ -365,7 +367,8 @@ class Module(ModuleManager.BaseModule):
if hook: if hook:
self.command(event["server"], event["user"], self.command(event["server"], event["user"],
event["user"].nickname, False, event["user"], command, 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: else:
self.events.on("unknown.command").call(server=event["server"], self.events.on("unknown.command").call(server=event["server"],
target=event["user"], user=event["user"], command=command, 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) hook = events.on(direction).on(event_type).on(context)
if is_channel: if is_channel:
hook.call(channel=target_obj, **kwargs) buffer_line = None
if message: if message:
target_obj.buffer.add_message(user.nickname, message, action, buffer_line = target_obj.buffer.add_message(user.nickname, message,
event["line"].tags, from_self) action, event["line"].tags, from_self)
hook.call(channel=target_obj, buffer_line=buffer_line, **kwargs)
else: else:
hook.call(**kwargs)
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: if message:
buffer_obj.buffer.add_message(user.nickname, message, action, buffer_line = buffer_obj.buffer.add_message(user.nickname, message,
event["line"].tags, from_self) 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.server = server
self._lines = collections.deque(maxlen=MAX_LINES self._lines = collections.deque(maxlen=MAX_LINES
) # type: typing.Deque[BufferLine] ) # type: typing.Deque[BufferLine]
self._skip_next = False
def _add_message(self, sender: str, message: str, action: bool, tags: dict, def _add_message(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool, method: str): from_self: bool, method: str) -> BufferLine:
if not self._skip_next:
line = BufferLine(sender, message, action, tags, from_self, method) line = BufferLine(sender, message, action, tags, from_self, method)
self._lines.appendleft(line) self._lines.appendleft(line)
self._skip_next = False return line
def add_message(self, sender: str, message: str, action: bool, tags: dict, def add_message(self, sender: str, message: str, action: bool, tags: dict,
from_self: bool=False): from_self: bool=False) -> BufferLine:
self._add_message(sender, message, action, tags, from_self, "PRIVMSG") return self._add_message(sender, message, action, tags, from_self,
"PRIVMSG")
def add_notice(self, sender: str, message: str, tags: dict, def add_notice(self, sender: str, message: str, tags: dict,
from_self: bool=False): 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]: def get(self, index: int=0, **kwargs) -> typing.Optional[BufferLine]:
from_self = kwargs.get("from_self", True) from_self = kwargs.get("from_self", True)
@ -83,6 +83,3 @@ class Buffer(object):
if len(found_lines) == max: if len(found_lines) == max:
break break
return found_lines return found_lines
def skip_next(self):
self._skip_next = True