mood: add calm down command
This commit is contained in:
parent
731f3a2bd7
commit
df04de5794
|
@ -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"],
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue