command_dice: fix random() calls, compress output to single line

This commit is contained in:
urlbot
2014-12-20 17:10:26 +01:00
parent ab02c3e59a
commit 49a36df11f

View File

@@ -275,16 +275,7 @@ def command_dice(args):
if 'dice' != args['argv0']: if 'dice' != args['argv0']:
return 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 count = 0
msg = None
try: try:
count = 1 if None is args['argv1'] else int(args['argv1']) 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': '%s: dice: invalid arguments (0 < N < 5)' % args['reply_user']
} }
msg = [ dice_char = ['', '', '', '', '', '', '']
'rolling a dice for %s: %s (%d)' % (args['reply_user'], dice_char[rnd], rnd)
for i in range(count) 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 { return {
'msg': msg[0] if 1 == count else msg 'msg': msg
} }
def command_uptime(args): def command_uptime(args):