Edm0nd/edmond/plugins/mood.py

45 lines
1.2 KiB
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-11-01 19:29:51 +01:00
"""Handle the mood of the bot.
This plugin exposes the runtime value `mood` (Mood) which can be
used to act differently upon some actions according to the bot
current mood.
"""
2020-10-09 12:19:58 +02:00
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):
if event.source.nick != self.bot.nick:
return
2020-10-09 12:49:35 +02:00
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