Expose is-silenced through Exports, use it in karma.py
This commit is contained in:
parent
e8c4a92119
commit
0fbf993201
2 changed files with 14 additions and 1 deletions
|
@ -34,6 +34,10 @@ class Module(ModuleManager.BaseModule):
|
||||||
if is_ignored_f(event["server"], event["user"], "karma"):
|
if is_ignored_f(event["server"], event["user"], "karma"):
|
||||||
return
|
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)
|
verbose = event["channel"].get_setting("karma-verbose", False)
|
||||||
nickname_only = event["server"].get_setting("karma-nickname-only",
|
nickname_only = event["server"].get_setting("karma-nickname-only",
|
||||||
False)
|
False)
|
||||||
|
|
|
@ -4,6 +4,15 @@ from src import ModuleManager, utils
|
||||||
SILENCE_TIME = 60*5 # 5 minutes
|
SILENCE_TIME = 60*5 # 5 minutes
|
||||||
|
|
||||||
class Module(ModuleManager.BaseModule):
|
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)
|
@utils.hook("received.command.silence", channel_only=True)
|
||||||
def silence(self, event):
|
def silence(self, event):
|
||||||
"""
|
"""
|
||||||
|
@ -19,7 +28,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
if event["is_channel"]:
|
if event["is_channel"]:
|
||||||
silence_until = event["target"].get_setting("silence-until", None)
|
silence_until = event["target"].get_setting("silence-until", None)
|
||||||
if silence_until:
|
if silence_until:
|
||||||
if time.time()<silence_until:
|
if self._is_silenced(event["target"]):
|
||||||
return utils.consts.PERMISSION_HARD_FAIL
|
return utils.consts.PERMISSION_HARD_FAIL
|
||||||
else:
|
else:
|
||||||
event["target"].del_setting("silence-until")
|
event["target"].del_setting("silence-until")
|
||||||
|
|
Loading…
Reference in a new issue