Edm0nd/edmond/plugins/mood.py

37 lines
933 B
Python
Raw Normal View History

2020-10-09 12:19:58 +02:00
import random
from enum import Enum
from edmond.plugin import Plugin
class Mood(Enum):
2020-10-09 12:49:35 +02:00
CALM = "calm"
PISSED = "pissed"
2020-10-09 12:19:58 +02:00
class MoodPlugin(Plugin):
2020-10-09 12:49:35 +02:00
REQUIRED_CONFIGS = ["questions", "greetings", "answer"]
2020-10-09 12:19:58 +02:00
def __init__(self, bot):
super().__init__(bot)
def on_welcome(self, event):
mood = random.choice(list(Mood))
self.set_runtime_value("mood", mood)
2020-10-09 12:49:35 +02:00
def on_join(self, event):
mood = self.get_runtime_value("mood")
greetings = self.config["greetings"].get(mood.value)
if greetings:
self.bot.say(event.target, random.choice(greetings))
2020-10-09 12:19:58 +02:00
def on_pubmsg(self, event):
if not self.should_answer_question(event.arguments[0]):
return False
mood = self.get_runtime_value("mood")
2020-10-09 12:49:35 +02:00
answer = self.config["answer"].get(mood.value)
if answer:
self.bot.say(event.target, answer)
2020-10-09 12:19:58 +02:00
return True