2020-10-09 18:57:26 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
from edmond.plugin import Plugin
|
|
|
|
|
|
|
|
|
2022-08-29 14:04:57 +02:00
|
|
|
class RandomChoicePlugin(Plugin):
|
2020-10-09 18:57:26 +02:00
|
|
|
|
2021-06-29 17:52:59 +02:00
|
|
|
REQUIRED_CONFIGS = ["commands", "separator", "not_enough"]
|
2020-10-09 18:57:26 +02:00
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
super().__init__(bot)
|
|
|
|
|
|
|
|
def on_pubmsg(self, event):
|
|
|
|
if not self.should_handle_command(event.arguments[0]):
|
|
|
|
return False
|
|
|
|
separator = self.config["separator"]
|
|
|
|
choices = self.command.content.split(f" {separator} ")
|
|
|
|
self.bot.log_d(f"Choices: {choices}")
|
2021-06-29 17:52:59 +02:00
|
|
|
if len(choices) > 1:
|
2020-10-09 18:57:26 +02:00
|
|
|
choice = random.choice(choices)
|
|
|
|
if choice:
|
2020-10-09 23:37:35 +02:00
|
|
|
self.bot.say(event.target, choice)
|
2021-06-29 17:52:59 +02:00
|
|
|
else:
|
|
|
|
self.bot.say(event.target, self.config["not_enough"])
|
2020-11-06 15:17:29 +01:00
|
|
|
return True
|