From 77ff83be794f5552f942c4cd4ceab8d940f97147 Mon Sep 17 00:00:00 2001 From: dece Date: Tue, 29 Jun 2021 17:52:59 +0200 Subject: [PATCH] random: only pick a choice if there are at least 2 --- config.json.example | 3 ++- edmond/plugins/random.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/config.json.example b/config.json.example index 8ce13c8..3c7bbe5 100644 --- a/config.json.example +++ b/config.json.example @@ -110,7 +110,8 @@ }, "random": { "commands": ["choose"], - "separator": "or" + "separator": "or", + "not_enough": "Not enough choices!" }, "sleep": { "commands": ["sleep", "wake up"], diff --git a/edmond/plugins/random.py b/edmond/plugins/random.py index 08eef61..0e52570 100644 --- a/edmond/plugins/random.py +++ b/edmond/plugins/random.py @@ -5,7 +5,7 @@ from edmond.plugin import Plugin class RandomPlugin(Plugin): - REQUIRED_CONFIGS = ["commands", "separator"] + REQUIRED_CONFIGS = ["commands", "separator", "not_enough"] def __init__(self, bot): super().__init__(bot) @@ -16,8 +16,10 @@ class RandomPlugin(Plugin): separator = self.config["separator"] choices = self.command.content.split(f" {separator} ") self.bot.log_d(f"Choices: {choices}") - if len(choices): + if len(choices) > 1: choice = random.choice(choices) if choice: self.bot.say(event.target, choice) + else: + self.bot.say(event.target, self.config["not_enough"]) return True