2020-11-06 00:42:38 +01:00
|
|
|
from edmond.plugin import Plugin
|
2022-11-29 12:56:11 +01:00
|
|
|
from edmond.plugins.gpt3 import Gpt3Plugin
|
2020-11-06 00:42:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
class UnknownCommandPlugin(Plugin):
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
super().__init__(bot)
|
2022-11-29 12:56:11 +01:00
|
|
|
self.priority: int = -6
|
|
|
|
self.gpt3_plugin: Gpt3Plugin
|
|
|
|
|
|
|
|
def on_welcome(self, _):
|
|
|
|
self.gpt3_plugin = self.bot.get_plugin("gpt3")
|
|
|
|
if self.gpt3_plugin is None or not self.gpt3_plugin:
|
|
|
|
self.bot.log_w("GPT-3 plugin is not available.")
|
|
|
|
self.is_ready = False
|
2020-11-06 00:42:38 +01:00
|
|
|
|
|
|
|
def on_pubmsg(self, event):
|
|
|
|
message = self.should_read_message(event.arguments[0])
|
|
|
|
if not message:
|
|
|
|
return False
|
|
|
|
words = message.split()
|
|
|
|
if len(words) == 0 or words[-1] != self.config["command_suffix"]:
|
2020-11-09 15:50:26 +01:00
|
|
|
return False
|
2020-11-06 00:42:38 +01:00
|
|
|
|
|
|
|
query = " ".join(words[:-1])
|
2022-11-29 13:24:13 +01:00
|
|
|
if not query.endswith("."):
|
|
|
|
query += "."
|
|
|
|
query += "\n\n"
|
2022-11-29 12:56:11 +01:00
|
|
|
self.gpt3_plugin.reply(query, event.target)
|
2020-11-06 00:42:38 +01:00
|
|
|
return True
|