Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/bobbit/modules/choose.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@

NAME = 'choose'
ENABLE = True
PATTERN = '^!choose (?P<options>.*)'
USAGE = '''Usage: !choose <options>
PATTERN = '^!choose (?:-b (?P<best_of>[0-9]) )?(?P<options>.*)'
USAGE = '''Usage: !choose [FLAG] <options>
Given a list of options separated by "or", this chooses one of them.
-b <best_of>
choose <best_of> times
Example:
> !choose stay or go
stay
'''

# 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

Expand Down