check a user is authenticated before applying modes, catch login too

This commit is contained in:
jesopo 2019-09-12 14:55:26 +01:00
parent 6b5e0791be
commit ad85536389

View file

@ -282,25 +282,34 @@ class Module(ModuleManager.BaseModule):
return [l[i:i+n] for i in range(0, len(l), n)] return [l[i:i+n] for i in range(0, len(l), n)]
@utils.hook("received.join") @utils.hook("received.join")
def flags_on_join(self, event): def on_join(self, event):
flags = event["channel"].get_user_setting(event["user"].get_id(), self._check_flags(event["channel"], event["user"])
"flags", "") @utils.hook("received.account.login")
@utils.hook("internal.identified")
def on_account(self, event):
for channel in event["user"].channels:
self._check_flags(channel, event["user"])
modes = [] def _check_flags(self, channel, user):
kick_reason = None flags = channel.get_user_setting(user.get_id(), "flags", "")
if flags:
modes = []
kick_reason = None
identified = not user.get_identified_account() == None
for flag in list(flags): for flag in list(flags):
if flag == "O": if flag == "O":
modes.append(("o", event["user"].nickname)) modes.append(("o", user.nickname))
elif flag == "V": elif flag == "V":
modes.append(("v", event["user"].nickname)) modes.append(("v", user.nickname))
elif flag == "b": elif flag == "b":
modes.append( modes.append(("b", self._get_hostmask(channel, user)))
("b", self._get_hostmask(event["channel"], event["user"]))) kick_reason = "User is banned from this channel"
kick_reason = "User is banned from this channel"
for chunk in self._chunk(modes, 4): print(flags)
chars, args = list(zip(*chunk)) print(modes)
event["channel"].send_mode("+%s" % "".join(chars), list(args)) for chunk in self._chunk(modes, 4):
if not kick_reason == None: chars, args = list(zip(*chunk))
event["channel"].send_kick(event["user"].nickname, kick_reason) channel.send_mode("+%s" % "".join(chars), list(args))
if not kick_reason == None:
channel.send_kick(user.nickname, kick_reason)