random: only pick a choice if there are at least 2
This commit is contained in:
parent
47e24eebaa
commit
77ff83be79
|
@ -110,7 +110,8 @@
|
|||
},
|
||||
"random": {
|
||||
"commands": ["choose"],
|
||||
"separator": "or"
|
||||
"separator": "or",
|
||||
"not_enough": "Not enough choices!"
|
||||
},
|
||||
"sleep": {
|
||||
"commands": ["sleep", "wake up"],
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue