2020-10-09 18:57:08 +02:00
|
|
|
import random
|
|
|
|
|
|
|
|
from edmond.plugin import Plugin
|
|
|
|
|
|
|
|
|
|
|
|
class BeersPlugin(Plugin):
|
|
|
|
|
2022-06-08 17:18:51 +02:00
|
|
|
REQUIRED_CONFIGS = ["commands", "beers", "opening_text", "target_word"]
|
2020-10-09 18:57:08 +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
|
2022-06-08 17:18:51 +02:00
|
|
|
|
|
|
|
target = event.source.nick
|
|
|
|
if self.command.content:
|
|
|
|
words = self.command.content.split(maxsplit=1)
|
|
|
|
if len(words) == 2 and words[0] == self.config["target_word"]:
|
|
|
|
target = words[1]
|
|
|
|
|
2020-10-09 18:57:08 +02:00
|
|
|
beer = random.choice(self.config["beers"])
|
|
|
|
opening_text = self.config["opening_text"].format(
|
2022-08-09 23:47:28 +02:00
|
|
|
beer=beer, target=target
|
2020-10-09 18:57:08 +02:00
|
|
|
)
|
|
|
|
self.bot.say(event.target, opening_text)
|
|
|
|
return True
|