return parsed modes from IRCChannel.parse_modes, pass through mode events
This commit is contained in:
parent
6e2259131a
commit
76ab7935a0
5 changed files with 26 additions and 13 deletions
|
@ -127,12 +127,12 @@ class Module(ModuleManager.BaseModule):
|
||||||
|
|
||||||
@utils.hook("received.mode.channel")
|
@utils.hook("received.mode.channel")
|
||||||
def mode(self, event):
|
def mode(self, event):
|
||||||
args = " ".join(event["mode_args"])
|
args = " ".join(event["args_str"])
|
||||||
if args:
|
if args:
|
||||||
args = " %s" % args
|
args = " %s" % args
|
||||||
|
|
||||||
line_minimal = "%s set mode %s%s" % (
|
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
|
line = "- %s" % line_minimal
|
||||||
|
|
||||||
self._event("mode.channel", event["server"], line,
|
self._event("mode.channel", event["server"], line,
|
||||||
|
|
|
@ -226,9 +226,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
core.handle_354(event)
|
core.handle_354(event)
|
||||||
|
|
||||||
# response to an empty mode command
|
# response to an empty mode command
|
||||||
@utils.hook("raw.received.324", default_event=True)
|
@utils.hook("raw.received.324")
|
||||||
def handle_324(self, event):
|
def handle_324(self, event):
|
||||||
channel.handle_324(event)
|
channel.handle_324(self.events, event)
|
||||||
|
|
||||||
# channel creation unix timestamp
|
# channel creation unix timestamp
|
||||||
@utils.hook("raw.received.329", default_event=True)
|
@utils.hook("raw.received.329", default_event=True)
|
||||||
|
|
|
@ -117,12 +117,15 @@ def part(events, event):
|
||||||
events.on("self.part").call(channel=channel, reason=reason,
|
events.on("self.part").call(channel=channel, reason=reason,
|
||||||
server=event["server"])
|
server=event["server"])
|
||||||
|
|
||||||
def handle_324(event):
|
def handle_324(events, event):
|
||||||
if event["line"].args[1] in event["server"].channels:
|
if event["line"].args[1] in event["server"].channels:
|
||||||
channel = event["server"].channels.get(event["line"].args[1])
|
channel = event["server"].channels.get(event["line"].args[1])
|
||||||
modes = event["line"].args[2]
|
modes = event["line"].args[2]
|
||||||
args = event["line"].args[3:]
|
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):
|
def handle_329(event):
|
||||||
channel = event["server"].channels.get(event["line"].args[1])
|
channel = event["server"].channels.get(event["line"].args[1])
|
||||||
|
|
|
@ -83,10 +83,11 @@ def mode(events, event):
|
||||||
modes = event["line"].args[1]
|
modes = event["line"].args[1]
|
||||||
args = event["line"].args[2:]
|
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,
|
events.on("received.mode.channel").call(modes=new_modes,
|
||||||
channel=channel, server=event["server"], user=user)
|
channel=channel, server=event["server"], user=user, modes_str=modes,
|
||||||
|
args_str=args)
|
||||||
elif event["server"].is_own_nickname(target):
|
elif event["server"].is_own_nickname(target):
|
||||||
modes = event["line"].args[1]
|
modes = event["line"].args[1]
|
||||||
_own_modes(event["server"], modes)
|
_own_modes(event["server"], modes)
|
||||||
|
|
|
@ -109,23 +109,32 @@ class Channel(IRCObject.Object):
|
||||||
else:
|
else:
|
||||||
self.add_mode(mode, arg)
|
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):
|
for chunk in RE_MODES.findall(modes):
|
||||||
remove = chunk[0] == "-"
|
remove = chunk[0] == "-"
|
||||||
for mode in chunk[1:]:
|
for mode in chunk[1:]:
|
||||||
|
new_arg = None
|
||||||
if mode in self.server.channel_list_modes:
|
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
|
elif (mode in self.server.channel_paramatered_modes or
|
||||||
mode in self.server.prefix_modes):
|
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:
|
elif mode in self.server.channel_setting_modes:
|
||||||
if remove:
|
if remove:
|
||||||
self.change_mode(remove, mode)
|
self.change_mode(remove, mode)
|
||||||
else:
|
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:
|
elif mode in self.server.channel_modes:
|
||||||
self.change_mode(remove, mode)
|
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):
|
def set_setting(self, setting: str, value: typing.Any):
|
||||||
self.bot.database.channel_settings.set(self.id, setting, value)
|
self.bot.database.channel_settings.set(self.id, setting, value)
|
||||||
def get_setting(self, setting: str, default: typing.Any=None
|
def get_setting(self, setting: str, default: typing.Any=None
|
||||||
|
|
Loading…
Reference in a new issue