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.gpt_plugin = self.bot.get_plugin("kagifastgpt")
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
if self.gpt_plugin and message.endswith(self.config["question_mark"]):
self.gpt_plugin.reply(message, event.target)
else:
self.classic_reply(event)
return True
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))