Edm0nd/edmond/plugins/unknown_question.py

42 lines
1.1 KiB
Python
Raw Normal View History

2020-11-05 23:52:20 +01:00
import random
from edmond.plugin import Plugin
from edmond.utils import proc
class UnknownQuestionPlugin(Plugin):
"""Handle unknown questions.
"""
def __init__(self, bot):
super().__init__(bot)
2021-06-06 18:28:43 +02:00
self.priority = -7
2020-11-05 23:52:20 +01:00
self.misc_plugin = None
self.gpt3_plugin = None
2020-11-05 23:52:20 +01:00
def on_welcome(self, _):
2020-11-05 23:52:20 +01:00
self.misc_plugin = self.bot.get_plugin("miscreactions")
self.gpt3_plugin = self.bot.get_plugin("gpt3")
2020-11-05 23:52:20 +01:00
def on_pubmsg(self, event):
message = self.should_read_message(event.arguments[0])
if message is None:
return False
2022-11-29 13:24:13 +01:00
if self.gpt3_plugin and message.endswith(self.config["question_mark"]):
message += "\n\n"
return self.gpt3_plugin.reply(message, event.target)
else:
return self.classic_reply(event)
def classic_reply(self, event):
if (
self.misc_plugin
and "pass_to_misc_rate" in self.config
and proc(self.config["pass_to_misc_rate"])
):
self.misc_plugin.react(event)
2020-11-05 23:52:20 +01:00
else:
self.bot.say(event.target, "?" * random.randint(1, 3))