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: if num_parts == 0:
return None return None
# Are the config conditions to answer a question valid? # Are the config conditions to answer a question valid?
elif not self.__respects_handling_conditions(): elif not self.respects_handling_conditions():
return None return None
# Is the message addressed to me? # Is the message addressed to me?
elif first_word_and_rest[0] in self.bot.names: elif first_word_and_rest[0] in self.bot.names:
@ -169,7 +169,7 @@ class Plugin:
return False return False
# Are the config conditions to answer a question valid? # Are the config conditions to answer a question valid?
if not self.__respects_handling_conditions(): if not self.respects_handling_conditions():
return False return False
# Is it a question I can answer? # Is it a question I can answer?
@ -209,7 +209,7 @@ class Plugin:
condition (i.e. do not handle commands when sleeping). condition (i.e. do not handle commands when sleeping).
""" """
# Are the config conditions to handle a command valid? # 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 return False
# Is it a valid command? # Is it a valid command?
@ -274,8 +274,14 @@ class Plugin:
self.command = command self.command = command
self.bot.log_i(f"Processing command from plugin {self.name}: {command}") self.bot.log_i(f"Processing command from plugin {self.name}: {command}")
def __respects_handling_conditions(self, exclude_conditions=None): def respects_handling_conditions(self, exclude_conditions=None):
"""Check if question conditions are valid.""" """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", {}) conditions = self.config.get("handling_conditions", {})
for plugin_ns, plugin_conditions in conditions.items(): for plugin_ns, plugin_conditions in conditions.items():
if exclude_conditions and plugin_ns in exclude_conditions: if exclude_conditions and plugin_ns in exclude_conditions:

View file

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