diff --git a/config.json.example b/config.json.example index 2e1c462..53adc76 100644 --- a/config.json.example +++ b/config.json.example @@ -32,6 +32,12 @@ "url": "http://zwergf.elynx.fr/bots/horobot/", "delay": 2 }, + "insults": { + "commands": ["insult"], + "sentences": ["idiot"], + "pissed_rate": 33, + "deny_message": "No." + }, "journeemondiale": { "commands": ["journée mondiale"], "url": "https://www.journee-mondiale.com/" diff --git a/edmond/plugins/insults.py b/edmond/plugins/insults.py new file mode 100644 index 0000000..9706b00 --- /dev/null +++ b/edmond/plugins/insults.py @@ -0,0 +1,54 @@ +import random + +from edmond.plugin import Plugin +from edmond.plugins.mood import Mood +from edmond.utils import proc + + +class InsultsPlugin(Plugin): + + REQUIRED_CONFIGS = ["commands", "sentences", "pissed_rate", "deny_message"] + + 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_pubmsg(self, event): + message = event.arguments[0] + if self.should_handle_command(message): + self.handle_insult_command(event.target) + return True + + content = self.should_read_message(message) + if content is None: + return False + if content in self.config["sentences"]: + self.react_to_insult(event.source.nick, event.target) + return True + + return False + + def handle_insult_command(self, target): + if self.mood_plugin is not None: + mood = self.get_runtime_value("mood", ns="mood") + if mood == Mood.CALM: + self.bot.say(target, self.config["deny_message"]) + return + insult_target = self.command.content + if not insult_target: + return + insult = random.choice(self.config["sentences"]) + reply = f"{insult_target} {insult}" + self.bot.say(target, reply) + + def react_to_insult(self, sender, target): + if self.mood_plugin is not None: + mood = self.get_runtime_value("mood", ns="mood") + if mood == Mood.CALM and proc(self.config["pissed_rate"]): + self.mood_plugin.get_pissed(target) + insult = random.choice(self.config["sentences"]) + reply = f"{sender} {insult}" + self.bot.say(target, reply)