Exemplo n.º 1
0
async def push(ctx, userMentionString):
    '''DEALER ONLY. Refunds a user's bet in the event of a push. An alias of $pay <user> 1x.'''
    if ctx.message.channel.id in global_constants.validChannels:
        if isDealer(ctx.author):
            if global_constants.deleteDealerMessages == True:
                await ctx.message.delete()
            dbUser = userInDatabase(int(convertMentionToID(userMentionString)))
            if int(convertMentionToID(userMentionString)) not in currentBets:
                await ctx.send(
                    dialogBox(
                        'warning', 'No bets currently standing for this user.',
                        'They may have not placed a bet, or the dealer may have already paid them out.'
                    ))
            else:
                payoutResponse = payUserOut(ctx, userMentionString, 1, 'win')
                finaldialog = dialogBox(
                    'push', '{user} pushes!'.format(
                        user=payoutResponse['userWhoGotPaid'].real_name),
                    'The house has refunded <@!{userID}>\'s bet of **{amount}**, and their wallet balance is now back at **{balance}**.'
                    .format(userID=dbUser.dc_uniqueid,
                            amount=asMoney(payoutResponse),
                            balance=asMoney(dbUser.wallet)))
                finaldialog.set_thumbnail(
                    url=getAvatarURL(ctx, dbUser.dc_uniqueid))
                await ctx.send(embed=finaldialog)
        else:
            await ctx.send(embed=dialogBox(
                'error', 'Only the dealer has access to this command.'))
Exemplo n.º 2
0
async def pay(ctx, userMentionString, payoutRatio):
    '''DEALER ONLY. Pays the @'ed user out. For example, `$pay @Jess 2x` will give Jess back $100 on a bet of $50. Ensure that the username after the @ is an actual mention (i.e. it pings the user).'''
    if ctx.message.channel.id in global_constants.validChannels:
        if isDealer(ctx.author):
            if global_constants.deleteDealerMessages == True:
                await ctx.message.delete()
            dbUser = userInDatabase(int(convertMentionToID(userMentionString)))
            if int(convertMentionToID(userMentionString)) not in currentBets:
                await ctx.send(
                    dialogBox(
                        'warning', 'No bets currently standing for this user.',
                        'They may have not placed a bet, or the dealer may have already paid them out.'
                    ))
            else:
                payoutResponse = payUserOut(ctx, userMentionString,
                                            payoutRatio, 'win')
                finaldialog = dialogBox(
                    'winner', '{user} wins!'.format(user=dbUser.real_name),
                    'The house has paid <@!{userID}> a total of **{amount}**, and their wallet balance is now **{balance}**.'
                    .format(userID=dbUser.dc_uniqueid,
                            amount=asMoney(payoutResponse),
                            balance=asMoney(dbUser.wallet)))
                finaldialog.set_thumbnail(
                    url=getAvatarURL(ctx, dbUser.dc_uniqueid))
                await ctx.send(embed=finaldialog)
        else:
            await ctx.send(embed=dialogBox(
                'error', 'Only the dealer has access to this command.'))
Exemplo n.º 3
0
def payUserOut(ctx, userMention, payoutRatio, winState):
    '''Takes the user's ID, pay-out ratio, and win-state. Pays out the user, tracks it in the database, then returns the user's name and pay-out amount.'''
    userID = convertMentionToID(
        userMention)  # Chop of the first three chars and the last one.
    dbUser = userInDatabase(userID)

    if userID not in currentBets:
        return False
    else:
        payAmount = float(
            currentBets[userID] * float(payoutRatio.strip('x'))
        )  # Calculate pay-out amount (current bet * pay-out ratio).
        currentWalletAmount = dbUser.wallet  # Cache the wallet balance pre-winnings.
        dbUser.update(wallet=currentWalletAmount + float(payAmount)
                      )  # Add the money to the user's wallet in the database.

        # Add the win/loss to the user's record in the database.
        if winState == 'win' or winState == 'blackjack':
            dbUser.update(total_wins=dbUser.total_wins + 1)
            dbUser.update(total_winnings=dbUser.total_winnings +
                          (payAmount - currentBets[userID]))
        elif winState == 'loss':
            dbUser.update(total_losses=dbUser.total_losses + 1)
            dbUser.update(total_winnings=dbUser.total_winnings -
                          (currentBets[userID]))

        # Remove the user's bet from the in-memory bets table.
        del currentBets[userID]
        return payAmount
Exemplo n.º 4
0
async def stats(ctx, userMention=''):
    '''Pull up the lifetime stats for yourself or another user.'''
    if ctx.message.channel.id in global_constants.validChannels:
        # If a user was mentioned, pull the database record for them.
        # If no mention, default to using the author's message ID as passed through via context.
        if userMention:
            await ctx.send(embed=debugMessage('Using mentioned user...'))
            dbUser = userInDatabase(convertMentionToID(userMention))
        else:
            await ctx.send(embed=debugMessage(
                'No mention passed. Using message author...'))
            dbUser = userInDatabase(ctx.author.id)

        # Check if user exists in database. If so, collect stats and display them.
        if dbUser == False:
            None
        else:
            await ctx.send(
                embed=debugMessage('`Command will run for {name}/{id}`'.format(
                    name=dbUser.real_name, id=dbUser.dc_uniqueid)))
            largestBetInfo = largestBet(dbUser.dc_uniqueid)
            finaldialog = dialogBox(
                'die',
                'Lifetime statistics for {user}'.format(user=dbUser.real_name))
            finaldialog.set_thumbnail(
                url=getAvatarURL(ctx, dbUser.dc_uniqueid))
            finaldialog.add_field(name='Total funds:',
                                  value=asMoney(dbUser.wallet),
                                  inline=True)
            finaldialog.add_field(name='Hands played:',
                                  value=dbUser.total_bets,
                                  inline=True)
            finaldialog.add_field(name='Wins:',
                                  value=dbUser.total_wins,
                                  inline=True)
            finaldialog.add_field(name='Losses:',
                                  value=dbUser.total_losses,
                                  inline=True)
            finaldialog.add_field(name='Buy-ins:',
                                  value=dbUser.total_buyins,
                                  inline=True)
            finaldialog.add_field(name='Largest bet:',
                                  value='{amount} at {time}'.format(
                                      amount=asMoney(
                                          largestBetInfo['betAmount']),
                                      time=largestBetInfo['betTime'],
                                      winorlose=largestBetInfo['wasAWin']),
                                  inline=True)
            # finaldialog.set_footer(text='Wins include blackjacks and any payouts of at least 1.1x and above. The largest bet will not show whether the bet was a win or a loss if the bet was made before PLACEHOLDER.')

            await ctx.send(embed=finaldialog)
Exemplo n.º 5
0
async def buyin(ctx, userMentionString):
    '''DEALER ONLY. Adds $100 to a user's wallet.'''
    if ctx.message.channel.id in global_constants.validChannels:
        if isDealer(ctx.author):
            if global_constants.deleteDealerMessages == True:
                await ctx.message.delete()
            dbUser = userInDatabase(convertMentionToID(userMentionString))
            dbUser.update(wallet=dbUser.wallet + float(100))
            dbUser.update(total_buyins=dbUser.total_buyins + 1)
            await ctx.send(embed=dialogBox(
                'handshake', '{} has bought in!'.format(dbUser.real_name),
                'The dealer has topped up {name}\'s wallet with an extra **$100**, bringing their funds up to **{amt}**.'
                .format(name=dbUser.real_name, amt=asMoney(dbUser.wallet))))
        else:
            await ctx.send(embed=dialogBox(
                'error', 'Only the dealer has access to this command.'))