plugins: improve logging

master
dece 4 years ago
parent 4a0d780b45
commit f71df26493

@ -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,16 +171,17 @@ class Plugin:
aliases = self.config.get("aliases", {}).get(preamble, [])
for q in (preamble, *aliases):
if question.startswith(q):
content = question[len(q):].strip()
content = content.rstrip("?").rstrip()
question = Question(preamble, content)
self.question = question
self.bot.log_d(
f"Answering from plugin {self.name}: {question}"
)
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_i(f"Answering from plugin {self.name}: {question}")
def should_handle_command(
self,
message,
@ -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

@ -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):

Loading…
Cancel
Save