Edm0nd/edmond/plugins/opinion.py
2020-11-02 18:43:54 +01:00

29 lines
794 B
Python

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)