diff --git a/modules/format_activity.py b/modules/format_activity.py index 978eabef..c9cf71b2 100644 --- a/modules/format_activity.py +++ b/modules/format_activity.py @@ -127,12 +127,12 @@ class Module(ModuleManager.BaseModule): @utils.hook("received.mode.channel") def mode(self, event): - args = " ".join(event["mode_args"]) + args = " ".join(event["args_str"]) if args: args = " %s" % args line_minimal = "%s set mode %s%s" % ( - event["user"].nickname, "".join(event["modes"]), args) + event["user"].nickname, "".join(event["modes_str"]), args) line = "- %s" % line_minimal self._event("mode.channel", event["server"], line, diff --git a/modules/line_handler/__init__.py b/modules/line_handler/__init__.py index fed529e9..2b9891af 100644 --- a/modules/line_handler/__init__.py +++ b/modules/line_handler/__init__.py @@ -226,9 +226,9 @@ class Module(ModuleManager.BaseModule): core.handle_354(event) # response to an empty mode command - @utils.hook("raw.received.324", default_event=True) + @utils.hook("raw.received.324") def handle_324(self, event): - channel.handle_324(event) + channel.handle_324(self.events, event) # channel creation unix timestamp @utils.hook("raw.received.329", default_event=True) diff --git a/modules/line_handler/channel.py b/modules/line_handler/channel.py index 7dfea4ca..77091206 100644 --- a/modules/line_handler/channel.py +++ b/modules/line_handler/channel.py @@ -117,12 +117,15 @@ def part(events, event): events.on("self.part").call(channel=channel, reason=reason, server=event["server"]) -def handle_324(event): +def handle_324(events, event): if event["line"].args[1] in event["server"].channels: channel = event["server"].channels.get(event["line"].args[1]) modes = event["line"].args[2] args = event["line"].args[3:] - channel.parse_modes(modes, args[:]) + new_modes = channel.parse_modes(modes, args[:]) + events.on("received.324").call(modes=new_modes, + channel=channel, server=event["server"], mode_str=modes, + args_str=args) def handle_329(event): channel = event["server"].channels.get(event["line"].args[1]) diff --git a/modules/line_handler/core.py b/modules/line_handler/core.py index 8957f958..3207a1a9 100644 --- a/modules/line_handler/core.py +++ b/modules/line_handler/core.py @@ -83,10 +83,11 @@ def mode(events, event): modes = event["line"].args[1] args = event["line"].args[2:] - channel.parse_modes(modes, args[:]) + new_modes = channel.parse_modes(modes, args[:]) - events.on("received.mode.channel").call(modes=modes, mode_args=args, - channel=channel, server=event["server"], user=user) + events.on("received.mode.channel").call(modes=new_modes, + channel=channel, server=event["server"], user=user, modes_str=modes, + args_str=args) elif event["server"].is_own_nickname(target): modes = event["line"].args[1] _own_modes(event["server"], modes) diff --git a/src/IRCChannel.py b/src/IRCChannel.py index dd564065..f03bc837 100644 --- a/src/IRCChannel.py +++ b/src/IRCChannel.py @@ -109,23 +109,32 @@ class Channel(IRCObject.Object): else: self.add_mode(mode, arg) - def parse_modes(self, modes: str, args: typing.List[str]): + def parse_modes(self, modes: str, args: typing.List[str] + ) -> typing.List[typing.Tuple[str, typing.Optional[str]]]: + new_modes: typing.List[typing.Tuple[str, typing.Optional[str]]] = [] for chunk in RE_MODES.findall(modes): remove = chunk[0] == "-" for mode in chunk[1:]: + new_arg = None if mode in self.server.channel_list_modes: - args.pop(0) + new_arg = args.pop(0) elif (mode in self.server.channel_paramatered_modes or mode in self.server.prefix_modes): - self.change_mode(remove, mode, args.pop(0)) + new_arg = args.pop(0) + self.change_mode(remove, mode, new_arg) elif mode in self.server.channel_setting_modes: if remove: self.change_mode(remove, mode) else: - self.change_mode(remove, mode, args.pop(0)) + new_arg = args.pop(0) + self.change_mode(remove, mode, new_arg) elif mode in self.server.channel_modes: self.change_mode(remove, mode) + mode_str = "%s%s" % ("-" if remove else "+", mode) + new_modes.append((mode_str, new_arg)) + return new_modes + def set_setting(self, setting: str, value: typing.Any): self.bot.database.channel_settings.set(self.id, setting, value) def get_setting(self, setting: str, default: typing.Any=None