link.send("The pinata is filled with %s, and can be hit with %s - %s (in increments of %s) - min win %s"%(AmountToString(pinata_units),AmountToString(min_target),AmountToString(max_target),AmountToString(config.pinata_target_increment*coinspecs.atomic_units),AmountToString(min_win_units)))
return
try:
amount=float(cmd[1])
units=long(amount*coinspecs.atomic_units+0.5)
aim=GetTarget(units)
exceptException,e:
link.send("Usage: !pinata <amount>")
return
ifaim<min_target:
link.send("The pinata can only be hit by at least %s"%AmountToString(min_target))
return
ifaim>max_target:
link.send("The pinata can only be hit by at most %s"%AmountToString(max_target))
return
try:
target=long(redis_hget('pinata','target'))
exceptException,e:
log_error('Failed to get pinata target: %s'%str(e))
link.send('An error occured')
return
iftarget<min_targetortarget>max_target:
log_error('Pinata target out of range: %s'%target)
link.send('An error occured')
return
account=GetAccount(identity)
log_info("Pinata: %s wants to swing %s at the pinata, aim is %d, target is %d"%(identity,amount,aim,target))
log_log("The pinata rains %s on: %s"%(AmountToString(user_units),str([user.identity()foruserinuserlist])))
link.send('%s rains on everyone else'%(AmountToString(user_units)))
forninuserlist:
a=GetAccount(n)
p.hincrby('balances',a,user_units)
p.hincrby('pinata','games',1)
p.hincrby('pinata','profit',profit_units)
p.execute()
PreparePinata(True,carry_units)
link.send('A new pinata appears filled with %s!'%AmountToString(carry_units))
else:
p=redis_pipeline()
p.hincrby('balances',account,-units)
p.hincrby('pinata','units',units)
p.hincrby('earmarked','pinata',units)
p.execute()
link.send('%s swings at the pinata with %s and misses! The pinata now contains %s'%(link.user.nick,AmountToString(units),AmountToString(pinata_units+units)))
exceptException,e:
log_error('Pinata: error: %s'%str(e))
link.send('An error occured')
return
defPinataHelp(link):
link.send_private("A pinata full of %s is floating in the air. Swing some %s at it!"%(coinspecs.name,coinspecs.name))
link.send_private("This pinata can only be smashed by a secret amount of %s,"%(coinspecs.name))
link.send_private("between %s and %s (inclusive), in %s increments"%(AmountToString(min_target),AmountToString(max_target),AmountToString(config.pinata_target_increment*coinspecs.atomic_units)))
link.send_private("If you hit with the secret amount, it breaks and you get %u%% - %u%% of the %s in it,"%(100*min_winner_share,100*max_winner_share,coinspecs.name))
link.send_private("%u%% of the rest rains down on others in the channel, and %u%% are placed"%(100*config.pinata_rain_remainder_share,100*config.pinata_carry_remainder_share))
link.send_private("in a new pinata. If you miss it, your %s end up in the pinata,"%(coinspecs.name))
link.send_private("increasing the bounty for next attempt")
link.send_private("The winner's share is proportional to the amount of %s on the winning hit,"%coinspecs.name)
link.send_private("so you don't lose out by trying higher amounts")
link.send_private("Remember, only one particular amount will manage to smash the pinata, try to find it!")
random.seed(time.time())
RegisterModule({
'name':__name__,
'help':PinataHelp,
})
RegisterCommand({
'module':__name__,
'name':'pinata',
'parms':'<amount-in-monero>',
'function':Pinata,
'registered':True,
'help':"swing some %s at the pinata"%(coinspecs.name)