Untitled

 avatar
unknown
plain_text
2 years ago
17 kB
5
Indexable
import discord
from discord.ext import commands
import datetime
import os

# Initialize the bot
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)

# Dictionary to store balances for users
balances = {}

# Dictionary to store transaction history for users
transaction_history = {}

# Path to the log file
LOG_FILE_PATH = "transaction_log.txt"

# Function to log a transaction
def log_transaction(user_id, transaction):
    timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    log_entry = f"[{timestamp}] User ID {user_id}: {transaction}\n"
    
    with open(LOG_FILE_PATH, "a") as log_file:
        log_file.write(log_entry)

# Function to retrieve a summary for a given day
def get_daily_summary(date):
    if not os.path.exists(LOG_FILE_PATH):
        with open(LOG_FILE_PATH, "w") as log_file:
            log_file.write("")

    with open(LOG_FILE_PATH, "r") as log_file:
        lines = log_file.readlines()

    total_deposits = 0
    total_withdrawals = 0

    for line in lines:
        if line.startswith(f"[{date}"):
            parts = line.strip().split(" ")
            amount = float(parts[1][1:])  # Adjusted to remove the '$' sign
            transaction_type = parts[2]

            if transaction_type == "Deposited":
                total_deposits += amount
            elif transaction_type == "Withdrew":
                total_withdrawals += amount

    final_balance = total_deposits - total_withdrawals

    if total_deposits == 0 and total_withdrawals == 0:
        return None

    summary = f"Total Deposits: ${total_deposits}\nTotal Withdrawals: ${total_withdrawals}\nFinal Balance: ${final_balance}"
    return summary

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')

@bot.command()
async def menu(ctx):
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description="Welcome to Brotherhood Bank",
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")  # Replace with your thumbnail URL
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    embed.add_field(name="MENU OPTIONS\n\n", value="\n\n[ 🤑 ] !deposit <- for deposit money\n\n[ 🤒 ] !withdraw <- for withdraw money\n\n[ 🧐 ] !balance <- for check balance", inline=False)
    await ctx.send(embed=embed)

@bot.command()
async def deposit(ctx, amount: int):
    user = ctx.author
    if user.id not in balances:
        balances[user.id] = 0

    balances[user.id] += amount

    # Create an embed
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description=f"Deposited ${amount}. Your balance is now ${balances[user.id]}."
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    # Display the embed
    await ctx.send(embed=embed)

    # Log the deposit transaction with the correct date format
    log_transaction(ctx.author.id, f"Deposited ${amount} on {datetime.datetime.now().strftime('%Y-%m-%d')}")

@bot.command()
async def withdraw(ctx, amount: int):
    user = ctx.author
    if user.id not in balances:
        embed = discord.Embed(
            colour=discord.Colour.pink(),
            title="BROTHERHOOD BANKING SYSTEM",
            description="You don't have anything in your account. Use !deposit to create one 🫡."
        )
        embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        await ctx.send(embed=embed)
        return

    if balances[user.id] < amount:
        embed = discord.Embed(
            colour=discord.Colour.pink(),
            title="BROTHERHOOD BANKING SYSTEM",
            description="Insufficient funds 🥵."
        )
        embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        await ctx.send(embed=embed)
        return

    balances[user.id] -= amount

    # Create an embed
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description=f"Withdrew ${amount}. Your balance is now ${balances[user.id]}."
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    # Display the embed
    await ctx.send(embed=embed)

    # Log the withdrawal transaction with the correct date format
    log_transaction(ctx.author.id, f"Withdrew ${amount} on {datetime.datetime.now().strftime('%Y-%m-%d')}")

@bot.command()
async def balance(ctx):
    user = ctx.author
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description="Welcome to Brotherhood Bank"
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")  # Replace with your thumbnail URL
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    if user.id not in balances:
        embed.add_field(name="Balance", value="You don't have anything in your account. Use !deposit to create one 🫡.")
    else:
        embed.add_field(name="Balance", value=f"Your balance is ${balances[user.id]}.")

    await ctx.send(embed=embed)

import discord
from discord.ext import commands
import datetime
import os

# Initialize the bot
intents = discord.Intents.all()
bot = commands.Bot(command_prefix='!', intents=intents)

# Dictionary to store balances for users
balances = {}

# Dictionary to store transaction history for users
transaction_history = {}

# Path to the log file
LOG_FILE_PATH = "transaction_log.txt"

# Function to log a transaction
def log_transaction(user_id, transaction):
    timestamp = datetime.datetime.now().strftime("[%d/%m/%Y %H:%M:%S]")
    log_entry = f"{timestamp} User ID {user_id}: {transaction}\n"
    
    with open(LOG_FILE_PATH, "a") as log_file:
        log_file.write(log_entry)

def get_daily_summary(date):
    if not os.path.exists(LOG_FILE_PATH):
        return "No transactions found for the specified date."

    with open(LOG_FILE_PATH, "r") as log_file:
        lines = log_file.readlines()

    total_deposits = 0
    total_withdrawals = 0

    for line in lines:
        if line.startswith(date):
            parts = line.strip().split(" ")
            amount = float(parts[3][1:])  # Adjusted to remove the '$' sign
            transaction_type = parts[4]

            if transaction_type == "Deposited":
                total_deposits += amount
            elif transaction_type == "Withdrew":
                total_withdrawals += amount

    final_balance = total_deposits - total_withdrawals

    if total_deposits == 0 and total_withdrawals == 0:
        return "No transactions found for the specified date."

    summary = f"Total Deposits: ${total_deposits}\nTotal Withdrawals: ${total_withdrawals}\nFinal Balance: ${final_balance}"
    return summary

@bot.event
async def on_ready():
    print(f'Logged in as {bot.user}')

@bot.command()
async def menu(ctx):
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description="Welcome to Brotherhood Bank",
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")  # Replace with your thumbnail URL
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    embed.add_field(name="MENU OPTIONS\n\n", value="\n\n[ 🤑 ] !deposit <- for deposit money\n\n[ 🤒 ] !withdraw <- for withdraw money\n\n[ 🧐 ] !balance <- for check balance", inline=False)
    await ctx.send(embed=embed)

@bot.command()
async def deposit(ctx, amount: int):
    user = ctx.author
    if user.id not in balances:
        balances[user.id] = 0

    balances[user.id] += amount

    # Create an embed
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description=f"Deposited ${amount}. Your balance is now ${balances[user.id]}."
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    # Display the embed
    await ctx.send(embed=embed)

    # Log the deposit transaction with the correct date format
    log_transaction(ctx.author.id, f"Deposited ${amount} on {datetime.datetime.now().strftime('%Y-%m-%d')}")

@bot.command()
async def withdraw(ctx, amount: int):
    user = ctx.author
    if user.id not in balances:
        embed = discord.Embed(
            colour=discord.Colour.pink(),
            title="BROTHERHOOD BANKING SYSTEM",
            description="You don't have anything in your account. Use !deposit to create one 🫡."
        )
        embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        await ctx.send(embed=embed)
        return

    if balances[user.id] < amount:
        embed = discord.Embed(
            colour=discord.Colour.pink(),
            title="BROTHERHOOD BANKING SYSTEM",
            description="Insufficient funds 🥵."
        )
        embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
        await ctx.send(embed=embed)
        return

    balances[user.id] -= amount

    # Create an embed
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description=f"Withdrew ${amount}. Your balance is now ${balances[user.id]}."
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    # Display the embed
    await ctx.send(embed=embed)

    # Log the withdrawal transaction with the correct date format
    log_transaction(ctx.author.id, f"Withdrew ${amount} on {datetime.datetime.now().strftime('%Y-%m-%d')}")

@bot.command()
async def balance(ctx):
    user = ctx.author
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description="Welcome to Brotherhood Bank"
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")  # Replace with your thumbnail URL
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")
    if user.id not in balances:
        embed.add_field(name="Balance", value="You don't have anything in your account. Use !deposit to create one 🫡.")
    else:
        embed.add_field(name="Balance", value=f"Your balance is ${balances[user.id]}.")

    await ctx.send(embed=embed)

@bot.command()
async def summary(ctx, date: str):
    # Get the summary for the provided date
    daily_summary = get_daily_summary(date)

    # Create an embed
    embed = discord.Embed(
        colour=discord.Colour.pink(),
        title="BROTHERHOOD BANKING SYSTEM",
        description="Welcome to Brotherhood Bank"
    )
    embed.set_thumbnail(url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")  # Replace with your thumbnail URL
    embed.set_author(name="Created for BrotherHood by Jimm yK", icon_url="https://media.discordapp.net/attachments/1156415255405150349/1159428494082719784/Logo_BH.png?ex=6530fcee&is=651e87ee&hm=0be6b2e14a3bc6011c399619cf1fb36d8a882c1616f562c330540802a38c214c&=&width=1040&height=701")

    # Set the description based on the daily summary
    embed.description = daily_summary if daily_summary else "No transactions found for the specified date."

    await ctx.send(embed=embed)
Editor is loading...