From 0d49fb145715c429bd6155037a55ca181a04908c Mon Sep 17 00:00:00 2001 From: dece Date: Wed, 8 Jun 2022 17:18:51 +0200 Subject: [PATCH] beers: offer a beer to someone in particular --- config.json.example | 3 ++- edmond/plugins/beers.py | 11 +++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config.json.example b/config.json.example index 4a05023..3be70ff 100644 --- a/config.json.example +++ b/config.json.example @@ -25,7 +25,8 @@ "beers": { "commands": ["beer"], "beers": ["Paix-Dieu"], - "opening_text": "/me cracks open a {beer} for {target}" + "opening_text": "/me cracks open a {beer} for {target}", + "target_word": "for" }, "caretaker": { "warm_welcome": ["Hi {target}!"], diff --git a/edmond/plugins/beers.py b/edmond/plugins/beers.py index 0a8ddaf..0b1b195 100644 --- a/edmond/plugins/beers.py +++ b/edmond/plugins/beers.py @@ -5,7 +5,7 @@ from edmond.plugin import Plugin class BeersPlugin(Plugin): - REQUIRED_CONFIGS = ["commands", "beers", "opening_text"] + REQUIRED_CONFIGS = ["commands", "beers", "opening_text", "target_word"] def __init__(self, bot): super().__init__(bot) @@ -13,10 +13,17 @@ class BeersPlugin(Plugin): def on_pubmsg(self, event): if not self.should_handle_command(event.arguments[0]): return False + + 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] + beer = random.choice(self.config["beers"]) opening_text = self.config["opening_text"].format( beer=beer, - target=event.source.nick + target=target ) self.bot.say(event.target, opening_text) return True