From 7eca5da533430da2d85f951fb6c4b9b6fd17e6a0 Mon Sep 17 00:00:00 2001 From: dece Date: Fri, 9 Oct 2020 18:57:26 +0200 Subject: [PATCH] random: add plugin --- config.json.example | 4 ++++ edmond/plugins/random.py | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 edmond/plugins/random.py diff --git a/config.json.example b/config.json.example index d7385c0..0ec359e 100644 --- a/config.json.example +++ b/config.json.example @@ -32,6 +32,10 @@ "pissed": "Pissed off..." } }, + "random": { + "commands": ["choose"], + "separator": "or" + }, "wikipedia": { "commands": ["science", "define"], "lang": "en", diff --git a/edmond/plugins/random.py b/edmond/plugins/random.py new file mode 100644 index 0000000..2462ebe --- /dev/null +++ b/edmond/plugins/random.py @@ -0,0 +1,26 @@ +import random + +from edmond.plugin import Plugin + + +class RandomPlugin(Plugin): + + REQUIRED_CONFIGS = ["commands", "separator"] + + def __init__(self, bot): + super().__init__(bot) + + def on_pubmsg(self, event): + if not self.should_handle_command(event.arguments[0]): + return False + if self.command.ident == "choose": + self.pick_random(event.target) + + def pick_random(self, target): + separator = self.config["separator"] + choices = self.command.content.split(f" {separator} ") + self.bot.log_d(f"Choices: {choices}") + if len(choices): + choice = random.choice(choices) + if choice: + self.bot.say(target, choice)