Support ignoring users per-channel

This commit is contained in:
jesopo 2019-07-01 19:32:40 +01:00
parent ba581d8622
commit 863e87c9ca

View file

@ -8,20 +8,35 @@ class Module(ModuleManager.BaseModule):
return user.get_setting("ignore", False) return user.get_setting("ignore", False)
def _user_command_ignored(self, user, command): def _user_command_ignored(self, user, command):
return user.get_setting("ignore-%s" % command, False) return user.get_setting("ignore-%s" % command, False)
def _user_channel_ignored(self, channel, user):
return channel.get_user_setting(user.get_id(), "ignore", False)
def _server_command_ignored(self, server, command): def _server_command_ignored(self, server, command):
return server.get_setting("ignore-%s" % command, False) return server.get_setting("ignore-%s" % command, False)
def _is_command_ignored(self, server, user, command):
if self._user_command_ignored(user, command):
return True
elif self._server_command_ignored(server, command):
return True
@utils.hook("received.message.private") @utils.hook("received.message.private")
@utils.hook("received.message.channel") @utils.hook("received.message.channel")
def message(self, event): def message(self, event):
if self._user_ignored(event["user"]): if self._user_ignored(event["user"]):
event.eat() event.eat()
elif event["is_channel"] and self._user_channel_ignored(event["target"],
event["user"]):
event.eat()
@utils.hook("preprocess.command") @utils.hook("preprocess.command")
def preprocess_command(self, event): def preprocess_command(self, event):
if self._user_command_ignored(event["user"], event["command"]): if self._user_ignored(event["user"]):
return utils.consts.PERMISSION_HARD_FAIL return utils.consts.PERMISSION_HARD_FAIL
elif self._server_command_ignored(event["server"], event["command"]): elif event["is_channel"] and self._user_channel_ignored(event["target"],
event["user"]):
return utils.consts.PERMISSION_HARD_FAIL
elif self._is_command_ignored(event["server"], event["user"],
event["command"]):
return utils.consts.PERMISSION_HARD_FAIL return utils.consts.PERMISSION_HARD_FAIL
@utils.hook("received.command.ignore", min_args=1) @utils.hook("received.command.ignore", min_args=1)
@ -70,6 +85,36 @@ class Module(ModuleManager.BaseModule):
event["stdout"].write("Removed ignore for '%s'%s" % event["stdout"].write("Removed ignore for '%s'%s" %
(user.nickname, for_str)) (user.nickname, for_str))
@utils.hook("received.command.cignore",
help="Ignore a user in this channel")
@utils.hook("received.command.cunignore",
help="Unignore a user in this channel")
@utils.kwarg("channel_only", True)
@utils.kwarg("min_args", 1)
@utils.kwarg("usage", "<nickname>")
@utils.kwarg("require-mode", "o")
@utils.kwarg("require-access", "cignore")
def cignore(self, event):
remove = event.name == "received.command.cunignore"
target_user = event["server"].get_user(event["args_split"][0])
is_ignored = event["target"].get_user_setting(target_user.get_id(),
"ignore", False)
if remove:
if not is_ignored:
raise utils.EventError("I'm not ignoring %s in this channel" %
target_user.nickname)
event["target"].del_user_setting(target_user.get_id(), "ignore")
event["stdout"].write("Unignored %s" % target_user.nickname)
else:
if is_ignored:
raise utils.EventError("I'm already ignoring %s in this channel"
% target_user.nickname)
event["target"].set_user_setting(target_user.get_id(), "ignore",
True)
event["stdout"].write("Ignoring %s" % target_user.nickname)
@utils.hook("received.command.serverignore", min_args=1) @utils.hook("received.command.serverignore", min_args=1)
def server_ignore(self, event): def server_ignore(self, event):
""" """