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

dice: clean up the dice "choose" command output (fix #1420) #1425

Merged
merged 2 commits into from
Feb 8, 2019
Merged
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
25 changes: 17 additions & 8 deletions sopel/modules/dice.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,26 +242,35 @@ def _get_pretty_str(dice):
@sopel.module.commands("ch")
@sopel.module.commands("choose")
@sopel.module.priority("medium")
@sopel.module.example(".choose a, b, c", r'Your options: a, b, c. My choice: (a|b|c)', re=True)
@sopel.module.example(".choose a | b | c", r'Your options: a, b, c. My choice: (a|b|c)', re=True)
@sopel.module.example(".choose a,b,c", r'Your options: a, b, c. My choice: (a|b|c)', re=True)
@sopel.module.example(".choose a|b|c", r'Your options: a, b, c. My choice: (a|b|c)', re=True)
@sopel.module.example(".choose a b c", r'Your options: a, b, c. My choice: (a|b|c)', re=True)
@sopel.module.example(".choose a, b | just a",
r'Your options: "a, b", just a. My choice: ((a, b)|(just a))',
re=True)
@sopel.module.example(".choose a", 'Your options: a. My choice: a')
def choose(bot, trigger):
"""
.choice option1|option2|option3 - Makes a difficult choice easy.
"""
if not trigger.group(2):
return bot.reply('I\'d choose an option, but you didn\'t give me any.')
choices = [trigger.group(2)]
for delim in '|\\/,':
for delim in '|\\/, ':
choices = trigger.group(2).split(delim)
if len(choices) > 1:
break
choices = [choice.strip() for choice in choices]
# Use a different delimiter in the output, to prevent ambiguity.
for show_delim in ',|/\\':
if show_delim not in trigger.group(2):
show_delim += ' '
break

pick = random.choice(choices)
return bot.reply('Your options: %s. My choice: %s' % (show_delim.join(choices), pick))

# Always use a comma in the output
display_options = ', '.join(
choice if ',' not in choice else '"%s"' % choice
for choice in choices
)
return bot.reply('Your options: %s. My choice: %s' % (display_options, pick))


if __name__ == "__main__":
Expand Down