From 6eccd2974bb89f7877f845d6cc939e8a36c71766 Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 29 Nov 2022 12:56:11 +0100 Subject: [PATCH] plugins: unknown cmd/q now use gpt3 if possible --- config.json.example | 4 ---- edmond/plugins/unknown_command.py | 12 ++++++++++-- edmond/plugins/unknown_question.py | 22 +++++++++++++++------- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/config.json.example b/config.json.example index d573096..2d62e78 100644 --- a/config.json.example +++ b/config.json.example @@ -189,10 +189,6 @@ "param_source": "from", "param_dest": "to" }, - "unknowncommand": { - "api_key": "", - "max_pods": 1 - }, "unknownquestion": { "pass_to_misc_rate": 50 }, diff --git a/edmond/plugins/unknown_command.py b/edmond/plugins/unknown_command.py index d5e31e8..8fea003 100644 --- a/edmond/plugins/unknown_command.py +++ b/edmond/plugins/unknown_command.py @@ -1,11 +1,19 @@ from edmond.plugin import Plugin +from edmond.plugins.gpt3 import Gpt3Plugin class UnknownCommandPlugin(Plugin): def __init__(self, bot): super().__init__(bot) - self.priority = -6 + 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]) @@ -16,5 +24,5 @@ class UnknownCommandPlugin(Plugin): return False query = " ".join(words[:-1]) - self.bot.say(event.target, f"UnknownCommand: {query}") + self.gpt3_plugin.reply(query, event.target) return True diff --git a/edmond/plugins/unknown_question.py b/edmond/plugins/unknown_question.py index f4581a6..e276aa3 100644 --- a/edmond/plugins/unknown_question.py +++ b/edmond/plugins/unknown_question.py @@ -7,26 +7,34 @@ from edmond.utils import proc class UnknownQuestionPlugin(Plugin): """Handle unknown questions. - Reply with some question marks, but there is a configurable rate to pass - processing of the message to the misc_reactions if available. """ - REQUIRED_CONFIGS = ["pass_to_misc_rate"] - def __init__(self, bot): super().__init__(bot) self.priority = -7 self.misc_plugin = None + self.gpt3_plugin = None - def on_welcome(self, event): + def on_welcome(self, _): self.misc_plugin = self.bot.get_plugin("miscreactions") + self.gpt3_plugin = self.bot.get_plugin("gpt3") def on_pubmsg(self, event): message = self.should_read_message(event.arguments[0]) if message is None: return False - if self.misc_plugin and proc(self.config["pass_to_misc_rate"]): + + if self.gpt3_plugin: + 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) else: self.bot.say(event.target, "?" * random.randint(1, 3)) - return True