From cc81956b584495b9fb2153d015941188ed8b2ac7 Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 5 Nov 2020 23:04:39 +0100 Subject: [PATCH] caretaker: add plugin --- README.md | 4 +-- config.json.example | 8 ++++++ edmond/plugins/caretaker.py | 49 +++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 edmond/plugins/caretaker.py diff --git a/README.md b/README.md index 87a0490..e60f605 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,6 @@ Missing features - [ ] Simple word mappings for fun - ~~[ ] Lyrics~~ - [ ] Phonétique -- [ ] Greet other people joining -- [ ] Mourn other people parting +- [x] Greet other people joining +- [x] Mourn other people parting - [ ] unknown questions diff --git a/config.json.example b/config.json.example index f749b86..6633527 100644 --- a/config.json.example +++ b/config.json.example @@ -14,6 +14,14 @@ "beers": ["Paix-Dieu"], "opening_text": "/me cracks open a {beer} for {target}" }, + "caretaker": { + "warm_welcome": ["Hi {target}!"], + "cold_welcome": ["Oh no..."], + "nice_farewell": [":("], + "bad_farewell": ["Good riddance."], + "welcome_rate": 10, + "farewell_rate": 10 + }, "common": { "command_suffix": "please", "handling_conditions": { diff --git a/edmond/plugins/caretaker.py b/edmond/plugins/caretaker.py new file mode 100644 index 0000000..70b3b40 --- /dev/null +++ b/edmond/plugins/caretaker.py @@ -0,0 +1,49 @@ +import random + +from edmond.plugin import Plugin +from edmond.plugins.mood import Mood +from edmond.utils import proc + + +class CaretakerPlugin(Plugin): + """Say hello and farewall on people joining/parting.""" + + REQUIRED_CONFIGS = [ + "warm_welcome", "cold_welcome", "nice_farewell", "bad_farewell", + "welcome_rate", "farewell_rate" + ] + + def __init__(self, bot): + super().__init__(bot) + self.mood_plugin = None + + def on_welcome(self, event): + self.mood_plugin = self.bot.get_plugin("mood") + + def on_join(self, event): + if event.source.nick == self.bot.nick: + return + if not proc(self.config["welcome_rate"]): + return + welcome_type = "warm_welcome" + if self.mood_plugin: + if self.get_runtime_value("mood", ns="mood") == Mood.PISSED: + welcome_type = "cold_welcome" + welcome = random.choice(self.config[welcome_type]) + if "{target}" in welcome: + welcome = welcome.format(target=event.source.nick) + self.bot.say(event.target, welcome) + + def on_part(self, event): + if event.source.nick == self.bot.nick: + return + if not proc(self.config["farewell_rate"]): + return + farewell_type = "nice_farewell" + if self.mood_plugin: + if self.get_runtime_value("mood", ns="mood") == Mood.PISSED: + farewell_type = "bad_farewell" + farewell = random.choice(self.config[farewell_type]) + if "{target}" in farewell: + farewell = farewell.format(target=event.source.nick) + self.bot.say(event.target, farewell)