Пример #1
0
async def wagered_dice(ctx, choice, bet: float):
    faces = [1, 2, 3, 4, 5, 6]
    choice = int(choice)
    if (choice not in faces):
        await ctx.send('Please enter number from 1-6!')
    elif (bet <= 0):
        await ctx.send('Please enter a positive bet!')
    elif (ef.check_balance(ctx.message.author.id) < bet):
        await ctx.send('You don\'t have enough money!')
    else:
        result = random.choice(faces)
        if (choice == result):
            winnings = bet * 2
            ef.ledger_update("Gambling", ctx.guild.id, "\"Casino\"",
                             ctx.message.author.id, winnings)
            ef.money_transfer(ctx.message.author.id, winnings)
            ef.money_transfer("\"Casino\"", -winnings)
            await ctx.send(f'Rolled a {result}. ' \
                            f'You win {winnings:.2f} dollars!')
        else:
            ef.ledger_update("Gambling", ctx.guild.id, ctx.message.author.id,
                             "\"Casino\"", bet)
            ef.money_transfer(ctx.message.author.id, -bet)
            ef.money_transfer("\"Casino\"", bet)
            await ctx.send(f'Rolled a {result}. You lose {bet:.2f} dollars!')
Пример #2
0
def new_deposit(user, amount, guild_id):
    if (amount <= 0):
        return "Please enter a positive amount."
    elif (ef.check_balance(user.id) < amount):
        return "You do not have enough money on you."
    else:
        db = sqlite3.connect('main.sqlite')
        cursor = db.cursor()
        cursor.execute('SELECT dollars FROM bank_deposits WHERE user_id = ?',
                       (user.id, ))
        result = cursor.fetchone()
        if result is None:
            sql = ("INSERT INTO bank_deposits (user_id, dollars) VALUES(?, ?)")
            val = (user.id, amount)
        else:
            current_balance = result[0]
            sql = ("UPDATE bank_deposits SET dollars = ? WHERE user_id = ?")
            val = (current_balance + amount, user.id)
    cursor.execute(sql, val)
    db.commit()
    cursor.close()
    db.close()
    ef.ledger_update("Bank_Deposit", guild_id, user.id, "\"Bank\"", amount)
    ef.money_transfer("\"Bank\"", amount)
    ef.money_transfer(user.id, -amount)
    return f"{user.name} deposited {amount:.2f} dollars."
Пример #3
0
def new_withdrawal(user, amount, guild_id):
    if (amount <= 0):
        return "Please enter a positive amount."
    else:
        db = sqlite3.connect('main.sqlite')
        cursor = db.cursor()
        cursor.execute('SELECT dollars FROM bank_deposits WHERE user_id = ?',
                       (user.id, ))
        result = cursor.fetchone()
        if (result is None or result[0] < amount):
            cursor.close()
            db.close()
            return "You do not have enough money in your account."
        else:
            current_balance = result[0]
            sql = ("UPDATE bank_deposits SET dollars = ? WHERE user_id = ?")
            val = (current_balance - amount, user.id)
            cursor.execute(sql, val)
            db.commit()
            cursor.close()
            db.close()
            ef.ledger_update("Bank_Withdrawal", guild_id, "\"Bank\"", user.id,
                             amount)
            ef.money_transfer(user.id, amount)
            ef.money_transfer("\"Bank\"", -amount)
            return f"{user.name} has withdrawn {amount:.2f} dollars."
Пример #4
0
def sell_stock(stock_name, number, user, guild_id):
    newstock_name = f"\"{stock_name}\""
    # Sell All feature
    if (number == "all" or number == "All" or number == "ALL"):
        db = sqlite3.connect('main.sqlite')
        cursor = db.cursor()
        cursor.execute('SELECT amount FROM stocks WHERE user_id = ? \
                        AND stock = ?', (user.id, newstock_name))
        result = cursor.fetchone()
        if (result is None):
            return f"You have no shares of {stock_name}!"
        else:
            number = result[0]
    # Make sure number is an int
    number = int(number)
    stock_name = stock_name.upper()
    # Error Checking
    data = yf.download(tickers=stock_name, period="1d", interval="2m",
                       auto_adjust=True, prepost=True)
    if (data.empty):
        return f"No results found for {stock_name}. \
                 Are you sure you have the right symbol?"
    # Get quote
    quote = data.tail(1)["Close"].values[0]
    payment = round(quote * number, 2)
    total_owed = payment - BROKERAGE_FEE
    # Check if user has enough stock to sell
    db = sqlite3.connect('main.sqlite')
    cursor = db.cursor()
    cursor.execute('SELECT amount FROM stocks WHERE user_id = ? \
                    AND stock = ?', (user.id, newstock_name))
    result = cursor.fetchone()
    if (result is None):
        return f"You have no shares of {stock_name}!"
    current_number = result[0]
    if (number > current_number):
        return f"You only have {current_number} shares of {stock_name}!"
    # Update portfolio
    elif (number == current_number):
        sql = ('DELETE FROM stocks WHERE user_id = ? AND stock = ?')
        val = (user.id, newstock_name)
    else:
        sql = ('UPDATE stocks SET amount = ? WHERE user_id = ? AND stock = ?')
        val = (current_number - number, user.id, newstock_name)
    cursor.execute(sql, val)
    db.commit()
    cursor.close()
    db.close()
    # Update stock ledger
    stock_ledger_update("\"Sell Order\"", guild_id, user.id,
                        stock_name, quote, number)
    # Update ledger
    ef.ledger_update("Sell_Stock", guild_id, "\"Brokerage\"",
                     user.id, total_owed)
    ef.money_transfer(user.id, total_owed)
    ef.money_transfer("\"Brokerage\"", BROKERAGE_FEE)
    return f"{user.name} sold {number} shares of {stock_name} at {quote:.2f} " \
            f"dollars each. The total value of the transaction was " \
            f"{payment:.2f} dollars, minus the {BROKERAGE_FEE:.2f} " \
            f"dollar brokerage fee."
Пример #5
0
async def give(ctx, member: discord.Member, amount: float):
    amount = round(amount, 2)
    if (ctx.message.author.id == 185902193595908096):
        ef.ledger_update("Test", ctx.guild.id, "\"Admin\"", member.id, amount)
        ef.money_transfer(member.id, amount)
        await ctx.send(f'Gave {"{:.2f}".format(round(amount, 2))} dollars to {member.name}.')
    else:
        await ctx.send(f'You must be a bot admin to do that.')
Пример #6
0
async def dice(ctx, choice):
    faces = [1, 2, 3, 4, 5, 6]
    choice = int(choice)
    if (choice not in faces):
        await ctx.send('Please enter number from 1-6!')
    else:
        result = random.choice(faces)
        if (choice == result):
            ef.ledger_update("Gambling", ctx.guild.id, "\"Casino\"", ctx.message.author.id, 0.01)
            ef.money_transfer(ctx.message.author.id, 0.01)
            ef.money_transfer("\"Casino\"", -0.01)
            await ctx.send(f'Rolled a {result}. You win $0.01!')
        else:
            await ctx.send(f'Rolled a {result}. You lose!')
Пример #7
0
async def pay(ctx, member: discord.Member, amount: float):
    amount = round(amount, 2)
    gbalance = ef.check_balance(ctx.message.author.id)
    if (amount <= 0): 
        await ctx.send(f'Please enter a positive amount!')
    elif (ctx.message.author.id == member.id):
        await ctx.send(f'You can\'t pay yourself!')
    elif (gbalance - amount < 0):
        await ctx.send(f'You do not have enough money!')
    else:
        ef.ledger_update("User_Transfer", ctx.guild.id, ctx.message.author.id, member.id, amount)
        ef.money_transfer(member.id, amount)
        ef.money_transfer(ctx.message.author.id, -amount)
        await ctx.send(f'{ctx.message.author.name} paid {member.name} {"{:.2f}".format(round(amount, 2))} dollars.')
Пример #8
0
def buy_stock(stock_name, number, user, guild_id):
    # Error Checking
    if number <= 0:
        return "Please enter a positive amount!"

    stock_name = stock_name.upper()
    data = yf.download(tickers=stock_name, period="1d",
                       interval="2m", auto_adjust=True, prepost=True)
    if (data.empty):
        return f"No results found for {stock_name}. " \
               f"Are you sure you have the right symbol?"

    # Get quote and payment
    quote = data.tail(1)["Close"].values[0]
    payment = quote * number
    total_owed = payment + BROKERAGE_FEE
    # Check if user had funds
    bal = ef.check_balance(user.id)
    if (bal < total_owed):
        if (bal > 10):
            number_max = math.floor((bal - 10) / quote)
            return f"You do not have the required funds to buy {number} " \
                   f"shares of {stock_name}! The maximum number of shares " \
                   f"you can afford is {number_max}..."
        else:
            return f"You do not have the required funds to buy {number} " \
                   f"shares of {stock_name}! You have less than " \
                   f"{BROKERAGE_FEE:.2f} dollars, the brokerage fee."

    # Update stock ledger
    stock_ledger_update("\"Buy Order\"", guild_id, user.id,
                        stock_name, quote, number)
    # Update ledger
    ef.ledger_update("Buy_Stock", guild_id, user.id,
                     "\"Brokerage\"", total_owed)
    ef.money_transfer(user.id, -total_owed)
    ef.money_transfer("\"Brokerage\"", BROKERAGE_FEE)
    add_to_portfolio(user.id, stock_name, number)
    return f"{user.name} bought {number} shares of {stock_name} at " \
            f"{quote:.2f} dollars each. The total value of the transaction was " \
            f"{payment:.2f} dollars, plus the {BROKERAGE_FEE:.2f} " \
            f"dollar brokerage fee."