opinion: add plugin

master
dece 4 years ago
parent d21a6dd2be
commit f83f7fd011

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

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

@ -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)
Loading…
Cancel
Save