Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add best of flag to choose #87

Open
wants to merge 1 commit into
base: bobbit-0.2.x
Choose a base branch
from
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
Loading