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!')
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."
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.')
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."
async def balance(ctx): balance = ef.check_balance(ctx.message.author.id) await ctx.send(f'{ctx.message.author.name} has ' \ f'{"{:.2f}".format(round(balance, 2))} dollars.')