plugins: improve logging

This commit is contained in:
dece 2020-11-09 15:09:29 +01:00
parent 4a0d780b45
commit f71df26493
2 changed files with 16 additions and 14 deletions

View file

@ -137,13 +137,15 @@ class Plugin:
return None
# Are the config conditions to answer a question valid?
elif not self.__respects_handling_conditions():
return False
return None
# Is the message addressed to me?
elif first_word_and_rest[0] in self.bot.names:
if num_parts == 1:
return ""
content = ""
else:
return first_word_and_rest[1].strip()
content = first_word_and_rest[1].strip()
self.bot.log_i(f"Reading message from {self.name}: {content}")
return content
def should_answer_question(self, message):
"""Store Question in object and return True if I should answer it.
@ -169,15 +171,16 @@ class Plugin:
aliases = self.config.get("aliases", {}).get(preamble, [])
for q in (preamble, *aliases):
if question.startswith(q):
content = question[len(q):].strip()
self.__save_question(question, q, preamble)
return True
return False
def __save_question(self, question, match, preamble):
content = question[len(match):].strip()
content = content.rstrip("?").rstrip()
question = Question(preamble, content)
self.question = question
self.bot.log_d(
f"Answering from plugin {self.name}: {question}"
)
return True
return False
self.bot.log_i(f"Answering from plugin {self.name}: {question}")
def should_handle_command(
self,
@ -262,7 +265,7 @@ class Plugin:
def __save_command(self, command):
"""Save command in instance for further processing by the plugin."""
self.command = command
self.bot.log_d(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):
"""Check if question conditions are valid."""
@ -273,9 +276,6 @@ class Plugin:
for condition_key, condition_value in plugin_conditions.items():
value = self.get_runtime_value(condition_key, ns=plugin_ns)
if condition_value != value:
self.bot.log_d(
f"Handling condition {plugin_ns}.{condition_key} false."
)
return False
return True

View file

@ -63,6 +63,7 @@ class MiscReactionsPlugin(Plugin):
def on_pubmsg(self, event):
if proc(self.config["rate"]):
self.bot.log_d("Proc random reaction.")
self.react(event)
return True
return False
@ -72,6 +73,7 @@ class MiscReactionsPlugin(Plugin):
method = random.choices(self.reactions, self.weights)[0]
else:
method = random.choice(self.reactions)
self.bot.log_d(f"Using reaction {method.__name__}.")
method(event)
def react_with_sentence(self, event):