From 49a36df11f62997c7926234960aa3e77d589f1be Mon Sep 17 00:00:00 2001 From: urlbot Date: Sat, 20 Dec 2014 17:10:26 +0100 Subject: [PATCH] command_dice: fix random() calls, compress output to single line --- plugins.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/plugins.py b/plugins.py index 1458ff4..a260fac 100644 --- a/plugins.py +++ b/plugins.py @@ -275,16 +275,7 @@ def command_dice(args): if 'dice' != args['argv0']: return - if args['reply_user'] in conf('enhanced-random-user'): - rnd = 0 # this might confuse users. good. - logger('plugin', 'sent random (enhanced)') - else: - rnd = random.randint(1, 6) - logger('plugin', 'sent random') - - dice_char = ['◇', '⚀', '⚁', '⚂', '⚃', '⚄', '⚅'] count = 0 - msg = None try: count = 1 if None is args['argv1'] else int(args['argv1']) @@ -300,13 +291,25 @@ def command_dice(args): 'msg': '%s: dice: invalid arguments (0 < N < 5)' % args['reply_user'] } - msg = [ - 'rolling a dice for %s: %s (%d)' % (args['reply_user'], dice_char[rnd], rnd) - for i in range(count) - ] + dice_char = ['◇', '⚀', '⚁', '⚂', '⚃', '⚄', '⚅'] + + msg = 'rolling %s for %s:' % ( + 'a dice' if 1 == count else '%d dices' % count, args['reply_user'] + ) + + for i in range(count): + rnd = 0 + if args['reply_user'] in conf('enhanced-random-user'): + rnd = 0 # this might confuse users. good. + logger('plugin', 'sent random (enhanced)') + else: + rnd = random.randint(1, 6) + logger('plugin', 'sent random') + + msg += ' %s (%d)' % (dice_char[rnd], rnd) return { - 'msg': msg[0] if 1 == count else msg + 'msg': msg } def command_uptime(args):