opinion: add plugin

This commit is contained in:
dece 2020-11-02 18:34:55 +01:00
parent d21a6dd2be
commit f83f7fd011
3 changed files with 36 additions and 1 deletions

View file

@ -36,7 +36,7 @@ Missing features
- [x] "Journee mondiale"
- [ ] Mug
- [ ] Music
- [ ] Opinions
- [x] Opinions
- [ ] Translate
- [x] Wikipedia: find definition, get random page
- [ ] Wolframalpha

View file

@ -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"

28
edmond/plugins/opinion.py Normal file
View file

@ -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)