mood: add calm down command

This commit is contained in:
dece 2020-11-02 16:39:57 +01:00
parent 731f3a2bd7
commit df04de5794
2 changed files with 27 additions and 8 deletions

View file

@ -33,6 +33,7 @@
"url": "https://www.journee-mondiale.com/" "url": "https://www.journee-mondiale.com/"
}, },
"mood": { "mood": {
"commands": ["calm down"],
"questions": ["how are you?"], "questions": ["how are you?"],
"greetings": { "greetings": {
"calm": ["Hi!", "Hello!"], "calm": ["Hi!", "Hello!"],
@ -41,7 +42,8 @@
"answer": { "answer": {
"calm": "Fine!", "calm": "Fine!",
"pissed": "Pissed off..." "pissed": "Pissed off..."
} },
"calmed_message": "I'm calm now."
}, },
"notes": { "notes": {
"commands": ["note down", "notes"], "commands": ["note down", "notes"],

View file

@ -17,11 +17,17 @@ class MoodPlugin(Plugin):
current mood. current mood.
""" """
REQUIRED_CONFIGS = ["questions", "greetings", "answer"] REQUIRED_CONFIGS = [
"commands", "questions", "greetings", "answer", "calmed_message",
]
def __init__(self, bot): def __init__(self, bot):
super().__init__(bot) super().__init__(bot)
@property
def mood(self):
return self.get_runtime_value("mood")
def on_welcome(self, event): def on_welcome(self, event):
mood = random.choice(list(Mood)) mood = random.choice(list(Mood))
self.set_runtime_value("mood", mood) self.set_runtime_value("mood", mood)
@ -35,10 +41,21 @@ class MoodPlugin(Plugin):
self.bot.say(event.target, random.choice(greetings)) self.bot.say(event.target, random.choice(greetings))
def on_pubmsg(self, event): def on_pubmsg(self, event):
if not self.should_answer_question(event.arguments[0]): if self.should_handle_command(event.arguments[0], no_content=True):
return False self.calm_down(event.target)
mood = self.get_runtime_value("mood") return True
answer = self.config["answer"].get(mood.value) if self.should_answer_question(event.arguments[0]):
self.say_mood(event.target)
return True
return False
def calm_down(self, target):
if self.mood != Mood.PISSED:
return
self.set_runtime_value("mood", Mood.CALM)
self.bot.say(target, self.config["calmed_message"])
def say_mood(self, target):
answer = self.config["answer"].get(self.mood.value)
if answer: if answer:
self.bot.say(event.target, answer) self.bot.say(target, answer)
return True