put a pancake on its head
This commit is contained in:
@@ -283,15 +283,24 @@ def command_dice(argv, **args):
|
|||||||
def command_choose(argv, **args):
|
def command_choose(argv, **args):
|
||||||
alternatives = argv
|
alternatives = argv
|
||||||
binary = (
|
binary = (
|
||||||
('Yes.', 'Yeah!', 'Ok!', 'Aye!', 'Great!'),
|
(('Yes.', 'Yeah!', 'Ok!', 'Aye!', 'Great!'), 4),
|
||||||
('No.', 'Naah..', 'Meh.', 'Nay.', 'You stupid?'),
|
(('No.', 'Naah..', 'Meh.', 'Nay.', 'You stupid?'), 4),
|
||||||
('Maybe.', 'Dunno.', 'I don\'t care.')
|
(('Maybe.', 'Dunno.', 'I don\'t care.'), 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def weighted_choice(choices):
|
||||||
|
total = sum(w for c, w in choices)
|
||||||
|
r = random.uniform(0, total)
|
||||||
|
upto = 0
|
||||||
|
for c, w in choices:
|
||||||
|
if upto + w >= r:
|
||||||
|
return c
|
||||||
|
upto += w
|
||||||
|
|
||||||
# single or no choice
|
# single or no choice
|
||||||
if len(alternatives) < 2:
|
if len(alternatives) < 2:
|
||||||
return {
|
return {
|
||||||
'msg': '{}: {}'.format(args['reply_user'], random.choice(random.choice(binary)))
|
'msg': '{}: {}'.format(args['reply_user'], random.choice(weighted_choice(binary)))
|
||||||
}
|
}
|
||||||
elif 'choose' not in alternatives:
|
elif 'choose' not in alternatives:
|
||||||
choice = random.choice(alternatives)
|
choice = random.choice(alternatives)
|
||||||
|
|||||||
Reference in New Issue
Block a user