opinion: add plugin
This commit is contained in:
parent
d21a6dd2be
commit
f83f7fd011
|
@ -36,7 +36,7 @@ Missing features
|
||||||
- [x] "Journee mondiale"
|
- [x] "Journee mondiale"
|
||||||
- [ ] Mug
|
- [ ] Mug
|
||||||
- [ ] Music
|
- [ ] Music
|
||||||
- [ ] Opinions
|
- [x] Opinions
|
||||||
- [ ] Translate
|
- [ ] Translate
|
||||||
- [x] Wikipedia: find definition, get random page
|
- [x] Wikipedia: find definition, get random page
|
||||||
- [ ] Wolframalpha
|
- [ ] Wolframalpha
|
||||||
|
|
|
@ -54,6 +54,13 @@
|
||||||
"limit": 5,
|
"limit": 5,
|
||||||
"too_many_notes": "There are too many notes for this user."
|
"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": {
|
"random": {
|
||||||
"commands": ["choose"],
|
"commands": ["choose"],
|
||||||
"separator": "or"
|
"separator": "or"
|
||||||
|
|
28
edmond/plugins/opinion.py
Normal file
28
edmond/plugins/opinion.py
Normal 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)
|
Loading…
Reference in a new issue