random: only pick a choice if there are at least 2

This commit is contained in:
dece 2021-06-29 17:52:59 +02:00
parent 47e24eebaa
commit 77ff83be79
2 changed files with 6 additions and 3 deletions

View file

@ -110,7 +110,8 @@
},
"random": {
"commands": ["choose"],
"separator": "or"
"separator": "or",
"not_enough": "Not enough choices!"
},
"sleep": {
"commands": ["sleep", "wake up"],

View file

@ -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