beers: offer a beer to someone in particular

This commit is contained in:
dece 2022-06-08 17:18:51 +02:00
parent b6929c9453
commit 0d49fb1457
2 changed files with 11 additions and 3 deletions

View file

@ -25,7 +25,8 @@
"beers": { "beers": {
"commands": ["beer"], "commands": ["beer"],
"beers": ["Paix-Dieu"], "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": { "caretaker": {
"warm_welcome": ["Hi {target}!"], "warm_welcome": ["Hi {target}!"],

View file

@ -5,7 +5,7 @@ from edmond.plugin import Plugin
class BeersPlugin(Plugin): class BeersPlugin(Plugin):
REQUIRED_CONFIGS = ["commands", "beers", "opening_text"] REQUIRED_CONFIGS = ["commands", "beers", "opening_text", "target_word"]
def __init__(self, bot): def __init__(self, bot):
super().__init__(bot) super().__init__(bot)
@ -13,10 +13,17 @@ class BeersPlugin(Plugin):
def on_pubmsg(self, event): def on_pubmsg(self, event):
if not self.should_handle_command(event.arguments[0]): if not self.should_handle_command(event.arguments[0]):
return False 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"]) beer = random.choice(self.config["beers"])
opening_text = self.config["opening_text"].format( opening_text = self.config["opening_text"].format(
beer=beer, beer=beer,
target=event.source.nick target=target
) )
self.bot.say(event.target, opening_text) self.bot.say(event.target, opening_text)
return True return True