misc_reactions: do not speak while asleep…

This commit is contained in:
dece 2021-07-03 01:36:18 +02:00
parent 77ff83be79
commit 6ba697656d
2 changed files with 13 additions and 5 deletions

View file

@ -143,7 +143,7 @@ class Plugin:
if num_parts == 0:
return None
# Are the config conditions to answer a question valid?
elif not self.__respects_handling_conditions():
elif not self.respects_handling_conditions():
return None
# Is the message addressed to me?
elif first_word_and_rest[0] in self.bot.names:
@ -169,7 +169,7 @@ class Plugin:
return False
# Are the config conditions to answer a question valid?
if not self.__respects_handling_conditions():
if not self.respects_handling_conditions():
return False
# Is it a question I can answer?
@ -209,7 +209,7 @@ class Plugin:
condition (i.e. do not handle commands when sleeping).
"""
# Are the config conditions to handle a command valid?
if not self.__respects_handling_conditions(exclude_conditions):
if not self.respects_handling_conditions(exclude_conditions):
return False
# Is it a valid command?
@ -274,8 +274,14 @@ class Plugin:
self.command = command
self.bot.log_i(f"Processing command from plugin {self.name}: {command}")
def __respects_handling_conditions(self, exclude_conditions=None):
"""Check if question conditions are valid."""
def respects_handling_conditions(self, exclude_conditions=None):
"""Check if handling conditions are valid.
Handling conditions can be specified by each plugin to create states in
which handling messages can be disabled. It is currently only used by
the sleep plugin (sleeping must disable most interactions) but every
plugin is free to introduce their own condition.
"""
conditions = self.config.get("handling_conditions", {})
for plugin_ns, plugin_conditions in conditions.items():
if exclude_conditions and plugin_ns in exclude_conditions:

View file

@ -62,6 +62,8 @@ class MiscReactionsPlugin(Plugin):
return reactions, weights
def on_pubmsg(self, event):
if not self.respects_handling_conditions():
return False
if proc(self.config["rate"]):
self.bot.log_d("Proc random reaction.")
self.react(event)