2019-06-20 11:08:24 +00:00
|
|
|
#--depends-on commands
|
|
|
|
#--depends-on permissions
|
|
|
|
|
2019-07-01 19:13:16 +00:00
|
|
|
from src import EventManager, ModuleManager, utils
|
2019-06-20 10:51:04 +00:00
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
def _user_ignored(self, user):
|
|
|
|
return user.get_setting("ignore", False)
|
|
|
|
def _user_command_ignored(self, user, command):
|
|
|
|
return user.get_setting("ignore-%s" % command, False)
|
2019-07-01 18:32:40 +00:00
|
|
|
def _user_channel_ignored(self, channel, user):
|
|
|
|
return channel.get_user_setting(user.get_id(), "ignore", False)
|
2019-06-20 10:51:04 +00:00
|
|
|
def _server_command_ignored(self, server, command):
|
|
|
|
return server.get_setting("ignore-%s" % command, False)
|
|
|
|
|
2019-07-01 18:32:40 +00:00
|
|
|
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
|
|
|
|
|
2019-06-20 10:51:04 +00:00
|
|
|
@utils.hook("received.message.private")
|
|
|
|
@utils.hook("received.message.channel")
|
2019-07-01 18:52:49 +00:00
|
|
|
@utils.hook("received.notice.private")
|
|
|
|
@utils.hook("received.notice.channel")
|
2019-07-01 19:13:16 +00:00
|
|
|
@utils.kwarg("priority", EventManager.PRIORITY_HIGH)
|
2019-06-20 10:51:04 +00:00
|
|
|
def message(self, event):
|
|
|
|
if self._user_ignored(event["user"]):
|
|
|
|
event.eat()
|
2019-07-01 18:32:40 +00:00
|
|
|
elif event["is_channel"] and self._user_channel_ignored(event["target"],
|
|
|
|
event["user"]):
|
|
|
|
event.eat()
|
2019-06-20 10:51:04 +00:00
|
|
|
|
|
|
|
@utils.hook("preprocess.command")
|
|
|
|
def preprocess_command(self, event):
|
2019-07-01 18:32:40 +00:00
|
|
|
if self._user_ignored(event["user"]):
|
2019-10-04 11:05:28 +00:00
|
|
|
return utils.consts.PERMISSION_HARD_FAIL, None
|
2019-07-01 18:32:40 +00:00
|
|
|
elif event["is_channel"] and self._user_channel_ignored(event["target"],
|
|
|
|
event["user"]):
|
2019-10-04 11:05:28 +00:00
|
|
|
return utils.consts.PERMISSION_HARD_FAIL, None
|
2019-07-01 18:32:40 +00:00
|
|
|
elif self._is_command_ignored(event["server"], event["user"],
|
|
|
|
event["command"]):
|
2019-10-04 11:05:28 +00:00
|
|
|
return utils.consts.PERMISSION_HARD_FAIL, None
|
2019-06-20 10:51:04 +00:00
|
|
|
|
|
|
|
@utils.hook("received.command.ignore", min_args=1)
|
|
|
|
def ignore(self, event):
|
|
|
|
"""
|
|
|
|
:help: Ignore commands from a given user
|
|
|
|
:usage: <nickname> [command]
|
|
|
|
:permission: ignore
|
|
|
|
"""
|
|
|
|
setting = "ignore"
|
|
|
|
for_str = ""
|
|
|
|
if len(event["args_split"]) > 1:
|
|
|
|
command = event["args_split"][1].lower()
|
|
|
|
setting = "ignore-%s" % command
|
|
|
|
for_str = " for '%s'" % command
|
|
|
|
|
|
|
|
user = event["server"].get_user(event["args_split"][0])
|
|
|
|
if user.get_setting(setting, False):
|
|
|
|
event["stderr"].write("I'm already ignoring '%s'%s" %
|
|
|
|
(user.nickname, for_str))
|
|
|
|
else:
|
|
|
|
user.set_setting(setting, True)
|
|
|
|
event["stdout"].write("Now ignoring '%s'%s" %
|
|
|
|
(user.nickname, for_str))
|
|
|
|
|
|
|
|
@utils.hook("received.command.unignore", min_args=1)
|
|
|
|
def unignore(self, event):
|
|
|
|
"""
|
|
|
|
:help: Unignore commands from a given user
|
|
|
|
:usage: <nickname> [command]
|
|
|
|
:permission: unignore
|
|
|
|
"""
|
|
|
|
setting = "ignore"
|
|
|
|
for_str = ""
|
|
|
|
if len(event["args_split"]) > 1:
|
|
|
|
command = event["args_split"][1].lower()
|
|
|
|
setting = "ignore-%s" % command
|
|
|
|
for_str = " for '%s'" % command
|
|
|
|
|
|
|
|
user = event["server"].get_user(event["args_split"][0])
|
|
|
|
if not user.get_setting(setting, False):
|
|
|
|
event["stderr"].write("I'm not ignoring '%s'%s" %
|
|
|
|
(user.nickname, for_str))
|
|
|
|
else:
|
|
|
|
user.del_setting(setting)
|
|
|
|
event["stdout"].write("Removed ignore for '%s'%s" %
|
|
|
|
(user.nickname, for_str))
|
|
|
|
|
2019-07-01 18:32:40 +00:00
|
|
|
@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>")
|
2019-07-01 18:36:51 +00:00
|
|
|
@utils.kwarg("permission", "cignore")
|
2019-09-26 11:15:14 +00:00
|
|
|
@utils.kwarg("require_mode", "o")
|
|
|
|
@utils.kwarg("require_access", "cignore")
|
2019-07-01 18:32:40 +00:00
|
|
|
def cignore(self, event):
|
2019-09-10 11:59:52 +00:00
|
|
|
remove = event["command"] == "cunignore"
|
2019-07-01 18:32:40 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2019-07-01 18:23:39 +00:00
|
|
|
@utils.hook("received.command.serverignore", min_args=1)
|
2019-06-20 10:51:04 +00:00
|
|
|
def server_ignore(self, event):
|
|
|
|
"""
|
|
|
|
:permission: server-ignore
|
|
|
|
"""
|
|
|
|
command = event["args_split"][0].lower()
|
|
|
|
setting = "ignore-%s" % command
|
|
|
|
|
|
|
|
if event["server"].get_setting(setting, False):
|
|
|
|
event["stderr"].write("I'm already ignoring '%s' for %s" %
|
|
|
|
(command, str(event["server"])))
|
|
|
|
else:
|
|
|
|
event["server"].set_setting(setting, True)
|
|
|
|
event["stdout"].write("Now ignoring '%s' for %s" %
|
|
|
|
(command, str(event["server"])))
|
|
|
|
|
2019-07-01 18:23:39 +00:00
|
|
|
@utils.hook("received.command.serverunignore", min_args=1)
|
2019-06-20 10:51:04 +00:00
|
|
|
def server_unignore(self, event):
|
|
|
|
"""
|
|
|
|
:permission: server-unignore
|
|
|
|
"""
|
|
|
|
command = event["args_split"][0].lower()
|
|
|
|
setting = "ignore-%s" % command
|
|
|
|
|
|
|
|
if not event["server"].get_setting(setting, False):
|
|
|
|
event["stderr"].write("I'm not ignoring '%s' for %s" %
|
|
|
|
(command, str(event["server"])))
|
|
|
|
else:
|
|
|
|
event["server"].del_setting(setting)
|
|
|
|
event["stdout"].write("No longer ignoring '%s' for %s" %
|
|
|
|
(command, str(event["server"])))
|
|
|
|
|