plugins: improve logging
This commit is contained in:
parent
4a0d780b45
commit
f71df26493
|
@ -137,13 +137,15 @@ class Plugin:
|
||||||
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 False
|
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:
|
||||||
if num_parts == 1:
|
if num_parts == 1:
|
||||||
return ""
|
content = ""
|
||||||
else:
|
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):
|
def should_answer_question(self, message):
|
||||||
"""Store Question in object and return True if I should answer it.
|
"""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, [])
|
aliases = self.config.get("aliases", {}).get(preamble, [])
|
||||||
for q in (preamble, *aliases):
|
for q in (preamble, *aliases):
|
||||||
if question.startswith(q):
|
if question.startswith(q):
|
||||||
content = question[len(q):].strip()
|
self.__save_question(question, q, preamble)
|
||||||
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 True
|
||||||
return False
|
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(
|
def should_handle_command(
|
||||||
self,
|
self,
|
||||||
message,
|
message,
|
||||||
|
@ -262,7 +265,7 @@ class Plugin:
|
||||||
def __save_command(self, command):
|
def __save_command(self, command):
|
||||||
"""Save command in instance for further processing by the plugin."""
|
"""Save command in instance for further processing by the plugin."""
|
||||||
self.command = command
|
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):
|
def __respects_handling_conditions(self, exclude_conditions=None):
|
||||||
"""Check if question conditions are valid."""
|
"""Check if question conditions are valid."""
|
||||||
|
@ -273,9 +276,6 @@ class Plugin:
|
||||||
for condition_key, condition_value in plugin_conditions.items():
|
for condition_key, condition_value in plugin_conditions.items():
|
||||||
value = self.get_runtime_value(condition_key, ns=plugin_ns)
|
value = self.get_runtime_value(condition_key, ns=plugin_ns)
|
||||||
if condition_value != value:
|
if condition_value != value:
|
||||||
self.bot.log_d(
|
|
||||||
f"Handling condition {plugin_ns}.{condition_key} false."
|
|
||||||
)
|
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -63,6 +63,7 @@ class MiscReactionsPlugin(Plugin):
|
||||||
|
|
||||||
def on_pubmsg(self, event):
|
def on_pubmsg(self, event):
|
||||||
if proc(self.config["rate"]):
|
if proc(self.config["rate"]):
|
||||||
|
self.bot.log_d("Proc random reaction.")
|
||||||
self.react(event)
|
self.react(event)
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -72,6 +73,7 @@ class MiscReactionsPlugin(Plugin):
|
||||||
method = random.choices(self.reactions, self.weights)[0]
|
method = random.choices(self.reactions, self.weights)[0]
|
||||||
else:
|
else:
|
||||||
method = random.choice(self.reactions)
|
method = random.choice(self.reactions)
|
||||||
|
self.bot.log_d(f"Using reaction {method.__name__}.")
|
||||||
method(event)
|
method(event)
|
||||||
|
|
||||||
def react_with_sentence(self, event):
|
def react_with_sentence(self, event):
|
||||||
|
|
Loading…
Reference in a new issue