From f83f7fd011f979384f8dbfa5cd55bc3de5883b3e Mon Sep 17 00:00:00 2001 From: dece Date: Mon, 2 Nov 2020 18:34:55 +0100 Subject: [PATCH] opinion: add plugin --- README.md | 2 +- config.json.example | 7 +++++++ edmond/plugins/opinion.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 edmond/plugins/opinion.py diff --git a/README.md b/README.md index e445fe1..ff0c8a9 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Missing features - [x] "Journee mondiale" - [ ] Mug - [ ] Music -- [ ] Opinions +- [x] Opinions - [ ] Translate - [x] Wikipedia: find definition, get random page - [ ] Wolframalpha diff --git a/config.json.example b/config.json.example index a867f5a..7b45322 100644 --- a/config.json.example +++ b/config.json.example @@ -54,6 +54,13 @@ "limit": 5, "too_many_notes": "There are too many notes for this user." }, + "opinion": { + "questions": ["what do you think of"], + "thinking": "Hhmmm", + "thinking_time": 2, + "positive": ["I like it."], + "negative": ["I don't like it."] + }, "random": { "commands": ["choose"], "separator": "or" diff --git a/edmond/plugins/opinion.py b/edmond/plugins/opinion.py new file mode 100644 index 0000000..39b42cf --- /dev/null +++ b/edmond/plugins/opinion.py @@ -0,0 +1,28 @@ +import hashlib +import random +import time + +from edmond.plugin import Plugin + + +class OpinionPlugin(Plugin): + + REQUIRED_CONFIGS = [ + "questions", "thinking", "thinking_time", "positive", "negative" + ] + + def __init__(self, bot): + super().__init__(bot) + + def on_pubmsg(self, event): + if not self.should_answer_question(event.arguments[0]): + return False + + self.bot.say(event.target, self.config["thinking"]) + time.sleep(self.config["thinking_time"]) + + content = self.question.content + positive = not bool(hashlib.md5(content.encode()).digest()[0] % 2) + reply_list = self.config["positive" if positive else "negative"] + reply = f"{content}... {random.choice(reply_list)}" + self.bot.say(event.target, reply)