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
|
2022-11-29 12:56:11 +01:00
|
|
|
self.gpt3_plugin = None
|
2020-11-05 23:52:20 +01:00
|
|
|
|
2022-11-29 12:56:11 +01:00
|
|
|
def on_welcome(self, _):
|
2020-11-05 23:52:20 +01:00
|
|
|
self.misc_plugin = self.bot.get_plugin("miscreactions")
|
2022-11-29 12:56:11 +01:00
|
|
|
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 12:56:11 +01:00
|
|
|
|
2022-11-29 13:24:13 +01:00
|
|
|
if self.gpt3_plugin and message.endswith(self.config["question_mark"]):
|
|
|
|
message += "\n\n"
|
2023-01-30 18:21:34 +01:00
|
|
|
self.gpt3_plugin.reply(message, event.target)
|
2022-11-29 12:56:11 +01:00
|
|
|
else:
|
2023-01-30 18:21:34 +01:00
|
|
|
self.classic_reply(event)
|
|
|
|
return True
|
2022-11-29 12:56:11 +01:00
|
|
|
|
|
|
|
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"])
|
|
|
|
):
|
2020-11-06 12:24:28 +01:00
|
|
|
self.misc_plugin.react(event)
|
2020-11-05 23:52:20 +01:00
|
|
|
else:
|
|
|
|
self.bot.say(event.target, "?" * random.randint(1, 3))
|