From edc63e15021f9d11be5639edecc4874a3a6659cf Mon Sep 17 00:00:00 2001 From: Colin McKechney Date: Thu, 8 Aug 2024 23:07:06 -0700 Subject: [PATCH] Add best of flag to choose --- src/bobbit/modules/choose.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/bobbit/modules/choose.py b/src/bobbit/modules/choose.py index b00024f..35407cd 100644 --- a/src/bobbit/modules/choose.py +++ b/src/bobbit/modules/choose.py @@ -6,9 +6,11 @@ NAME = 'choose' ENABLE = True -PATTERN = '^!choose (?P.*)' -USAGE = '''Usage: !choose +PATTERN = '^!choose (?:-b (?P[0-9]) )?(?P.*)' +USAGE = '''Usage: !choose [FLAG] Given a list of options separated by "or", this chooses one of them. +-b + choose times Example: > !choose stay or go stay @@ -16,9 +18,16 @@ # Command -async def choose(bot, message, options=None): +async def choose(bot, message, options=None, best_of=None): options = options.split(' or ') - return message.with_body(random.choice(options)) + if best_of is None: + return message.with_body(random.choice(options)) + else: + choices = '' + for i in range(0, int(best_of)): + choices += random.choice(options) + '\n' + return message.with_body(choices.strip()) + # Register