1
0
mirror of http://aero2k.de/t/repos/urlbot-native.git synced 2017-09-06 15:25:38 +02:00

patch command_dice to roll N dices

This commit is contained in:
urlbot
2014-12-20 17:02:26 +01:00
parent c0381a7bf4
commit ab02c3e59a

View File

@@ -267,8 +267,8 @@ def command_dice(args):
if 'register' == args:
return {
'name': 'dice',
'desc': 'rolls a dice',
'args': ('argv0', 'reply_user'),
'desc': 'rolls a dice, optional N times',
'args': ('argv0', 'argv1', 'reply_user'),
'ratelimit_class': RATE_INTERACTIVE
}
@@ -283,8 +283,30 @@ def command_dice(args):
logger('plugin', 'sent random')
dice_char = ['', '', '', '', '', '', '']
count = 0
msg = None
try:
count = 1 if None is args['argv1'] else int(args['argv1'])
except ValueError as e:
return {
'msg': 'rolling a dice for %s: %s (%d)' % (args['reply_user'], dice_char[rnd], rnd)
'msg': '%s: dice: error when parsing int(%s): %s' % (
args['reply_user'], args['argv1'], str(e)
)
}
if 0 >= count or 5 <= count:
return {
'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)
]
return {
'msg': msg[0] if 1 == count else msg
}
def command_uptime(args):