Expose is-silenced through Exports, use it in karma.py

This commit is contained in:
jesopo 2019-05-13 20:57:47 +01:00
parent e8c4a92119
commit 0fbf993201
2 changed files with 14 additions and 1 deletions

View file

@ -34,6 +34,10 @@ class Module(ModuleManager.BaseModule):
if is_ignored_f(event["server"], event["user"], "karma"):
return
if_silenced_f = self.exports.get_one("is-silenced", lambda _: False)
if is_silenced_f(event["channel"]):
return
verbose = event["channel"].get_setting("karma-verbose", False)
nickname_only = event["server"].get_setting("karma-nickname-only",
False)

View file

@ -4,6 +4,15 @@ from src import ModuleManager, utils
SILENCE_TIME = 60*5 # 5 minutes
class Module(ModuleManager.BaseModule):
def on_load(self):
self.exports.add("is-silenced", self._is_silenced)
def _is_silenced(self, target):
silence_until = target.get_setting("silence-until", None)
if silence_until and time.time()<silence_until:
return True
return False
@utils.hook("received.command.silence", channel_only=True)
def silence(self, event):
"""
@ -19,7 +28,7 @@ class Module(ModuleManager.BaseModule):
if event["is_channel"]:
silence_until = event["target"].get_setting("silence-until", None)
if silence_until:
if time.time()<silence_until:
if self._is_silenced(event["target"]):
return utils.consts.PERMISSION_HARD_FAIL
else:
event["target"].del_setting("silence-until")