From ce26eda989dc52c3e4182f308c97dbf696301e6e Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 5 Nov 2020 23:52:20 +0100 Subject: [PATCH] unknown_question: add plugin --- README.md | 4 ++-- config.json.example | 3 +++ edmond/plugin.py | 2 ++ edmond/plugins/unknown_question.py | 32 ++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 edmond/plugins/unknown_question.py diff --git a/README.md b/README.md index e60f605..fa15f58 100644 --- a/README.md +++ b/README.md @@ -50,9 +50,9 @@ Missing features - [x] appreciation - [x] detector - [x] "???" -- [ ] Simple word mappings for fun +- ~~[ ] Simple word mappings for fun~~ - ~~[ ] Lyrics~~ - [ ] Phonétique - [x] Greet other people joining - [x] Mourn other people parting -- [ ] unknown questions +- [x] unknown questions diff --git a/config.json.example b/config.json.example index 6633527..3cc905c 100644 --- a/config.json.example +++ b/config.json.example @@ -119,6 +119,9 @@ "param_source": "from", "param_dest": "to" }, + "unknownquestion": { + "pass_to_misc_rate": 50 + }, "wikipedia": { "commands": ["science", "define"], "lang": "en", diff --git a/edmond/plugin.py b/edmond/plugin.py index 14e5420..56f226d 100644 --- a/edmond/plugin.py +++ b/edmond/plugin.py @@ -32,6 +32,8 @@ class Plugin: For now these levels are used: - 0: default - -3: low, misc parsing of messages, answer to various messages + - -8: handling of unknown commands + - -9: handling of unknown questions - -10: lowest, e.g. for random reactions usually with a very low rate """ diff --git a/edmond/plugins/unknown_question.py b/edmond/plugins/unknown_question.py new file mode 100644 index 0000000..7a6b323 --- /dev/null +++ b/edmond/plugins/unknown_question.py @@ -0,0 +1,32 @@ +import random + +from edmond.plugin import Plugin +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 = -9 + self.misc_plugin = None + + def on_welcome(self, event): + self.misc_plugin = self.bot.get_plugin("miscreactions") + + 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"]): + return self.misc_plugin.on_pubmsg(event) + else: + self.bot.say(event.target, "?" * random.randint(1, 3)) + return True