Edm0nd/edmond/plugins/unknown_command.py

32 lines
955 B
Python

from edmond.plugin import Plugin
from edmond.plugins.gpt3 import Gpt3Plugin
class UnknownCommandPlugin(Plugin):
def __init__(self, bot):
super().__init__(bot)
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
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"]:
return False
query = " ".join(words[:-1])
if not query.endswith("."):
query += "."
query += "\n\n"
self.gpt3_plugin.reply(query, event.target)
return True