This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/choose.py

19 lines
397 B
Python
Raw Normal View History

2011-11-20 10:23:31 +01:00
import re
import random
from util import hook
@hook.command
def choose(inp):
2012-02-29 06:47:11 +01:00
".choose <choice1>, [choice2], [choice3], [choice4], ... -- "\
"Randomly picks one of the given choices."
2011-11-20 10:23:31 +01:00
c = re.findall(r'([^,]+)', inp)
if len(c) == 1:
c = re.findall(r'(\S+)', inp)
if len(c) == 1:
return 'the decision is up to you'
return random.choice(c).strip()