diff --git a/config.json.example b/config.json.example index 82f795b..a168ff9 100644 --- a/config.json.example +++ b/config.json.example @@ -33,6 +33,7 @@ "url": "https://www.journee-mondiale.com/" }, "mood": { + "commands": ["calm down"], "questions": ["how are you?"], "greetings": { "calm": ["Hi!", "Hello!"], @@ -41,7 +42,8 @@ "answer": { "calm": "Fine!", "pissed": "Pissed off..." - } + }, + "calmed_message": "I'm calm now." }, "notes": { "commands": ["note down", "notes"], diff --git a/edmond/plugins/mood.py b/edmond/plugins/mood.py index 9ea4b40..54b5366 100644 --- a/edmond/plugins/mood.py +++ b/edmond/plugins/mood.py @@ -17,11 +17,17 @@ class MoodPlugin(Plugin): current mood. """ - REQUIRED_CONFIGS = ["questions", "greetings", "answer"] + REQUIRED_CONFIGS = [ + "commands", "questions", "greetings", "answer", "calmed_message", + ] def __init__(self, bot): super().__init__(bot) + @property + def mood(self): + return self.get_runtime_value("mood") + def on_welcome(self, event): mood = random.choice(list(Mood)) self.set_runtime_value("mood", mood) @@ -35,10 +41,21 @@ class MoodPlugin(Plugin): self.bot.say(event.target, random.choice(greetings)) def on_pubmsg(self, event): - if not self.should_answer_question(event.arguments[0]): - return False - mood = self.get_runtime_value("mood") - answer = self.config["answer"].get(mood.value) + if self.should_handle_command(event.arguments[0], no_content=True): + self.calm_down(event.target) + return True + 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: - self.bot.say(event.target, answer) - return True + self.bot.say(target, answer)