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)