return parsed modes from IRCChannel.parse_modes, pass through mode events

This commit is contained in:
jesopo 2019-07-03 08:13:28 +01:00
parent 6e2259131a
commit 76ab7935a0
5 changed files with 26 additions and 13 deletions

View file

@ -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,

View file

@ -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)

View file

@ -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])

View file

@ -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)

View file

@ -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