Edm0nd/edmond/plugins/random_choice.py

26 lines
730 B
Python

import random
from edmond.plugin import Plugin
class RandomChoicePlugin(Plugin):
REQUIRED_CONFIGS = ["commands", "separator", "not_enough"]
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}")
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