Add !syncmodes in modules/auto_mode.py, fire internal.identified in

modules/permissions.py and catch it in modules/auto_mode.py to give users modes
when they identify using the internal identity mechanism
This commit is contained in:
jesopo 2018-10-11 11:20:53 +01:00
parent 41278cba81
commit 23b7223fae
3 changed files with 36 additions and 4 deletions

View file

@ -5,22 +5,49 @@ from src import ModuleManager, utils
class Module(ModuleManager.BaseModule):
_name = "AutoMode"
def _check_modes(self, channel, user):
def _get_modes(self, channel, user):
identified_account = user.get_identified_account()
if identified_account and channel.get_setting("automode", False):
modes = channel.get_user_setting(user.get_id(), "automodes", [])
if modes:
channel.send_mode("+%s" % "".join(modes),
" ".join([user.nickname for mode in modes]))
return modes
return []
def _check_modes(self, channel, user):
modes = self._get_modes(channel, user)
if modes:
channel.send_mode("+%s" % "".join(modes),
" ".join([user.nickname for mode in modes]))
@utils.hook("received.join")
def on_join(self, event):
self._check_modes(event["channel"], event["user"])
@utils.hook("received.account")
@utils.hook("internal.identified")
def on_account(self, event):
for channel in event["user"].channels:
self._check_modes(channel, event["user"])
@utils.hook("received.command.syncmodes", channel_only=True)
def sync_modes(self, event):
"""
:help: Check/sync user modes
:require_mode: o
"""
modes = []
for user in event["target"].users:
user_modes = self._get_modes(event["target"], user)
for user_mode in user_modes:
if not event["target"].has_mode(user, user_mode):
modes.append([user_mode, user.nickname])
# break up in to chunks of (maximum) 3
# https://tools.ietf.org/html/rfc2812.html#section-3.2.3
mode_chunks = [modes[i:i+3] for i in range(0, len(modes), 3)]
for chunk in mode_chunks:
modes = [item[0] for item in chunk]
nicknames = [item[1] for item in chunk]
event["target"].send_mode(
"+%s" % "".join(modes), " ".join(nicknames))
def _add_mode(self, event, mode, mode_name):
target_user = event["server"].get_user(event["args_split"][0])
automodes = event["target"].get_user_setting(target_user.get_id(),

View file

@ -71,6 +71,8 @@ class Module(ModuleManager.BaseModule):
self._identified(event["server"], event["user"], account)
event["stdout"].write("Correct password, you have "
"been identified as '%s'." % account)
self.events.on("internal.identified").call(
user=event["user"])
else:
event["stderr"].write("Incorrect password for '%s'" %
account)

View file

@ -138,5 +138,8 @@ class Channel(IRCObject.Object):
return True
return False
def has_mode(self, user, mode):
return user in self.modes.get(mode, [])
def get_user_status(self, user):
return self.user_modes.get(user, [])