Beispiel #1
0
def button(bot, update):
    """Callback funtion for the inline keyboard buttons that handles what happens when user chooses an option in the store."""

    if update.callback_query.data.split(" ")[-1] in fiirumi.emojis:
        fiirumi.vote_message(bot, update)
        return

    if not is_registered(bot, update):
        return

    query = update.callback_query

    if query.data == "Poistu":
        query.edit_message_text(text="Osto keskeytetty")
        return

    user = update.effective_user.id
    time = datetime.datetime.today().isoformat()
    price = db.get_price(query.data)
    name = db.get_user(user)[0][2]
    #print(price)

    db.add_transaction(user, name, query.data, time, price)
    db.update_balance(user, -price)

    saldo = db.get_balance(user)
    #print(saldo)
    query.edit_message_text(text="Ostit tuotteen: {}.\n\nSaldo: {:.2f}€".format(query.data, saldo / 100))
Beispiel #2
0
def poista(update, context):
    """Does the actual removing when user wants to remove their last action."""

    if update.message.text == "Kyllä":
        user = update.effective_user.id
        edellinen = db.get_last_transaction(update.effective_user.id)
        print("Removing transaction: ", edellinen[0])
        summa = -edellinen[4] if edellinen[3] == "PANO" else edellinen[4]
        if edellinen[3] != "PANO" and edellinen[3] != "NOSTO":
            try:
                db.update_stock(edellinen[3], 0)
            except TypeError:
                pass
        db.update_balance(user, summa)
        db.delete_transaction(edellinen[0])
        saldo = db.get_balance(user)
        context.bot.send_message(
            update.message.chat.id,
            "Tapahtuma poistettu. Tilisi saldo on {:.2f}€.".format(saldo /
                                                                   100),
            reply_markup=ReplyKeyboardRemove())
    else:
        context.bot.send_message(update.message.chat.id,
                                 "Tapahtumaa ei poistettu",
                                 reply_markup=ReplyKeyboardRemove())
    return ConversationHandler.END
Beispiel #3
0
def nosta(update, context):
    """Withdraw money from account."""

    maara = 0
    try:
        maara = int(float(update.message.text.replace(",", ".")) * 100)
        if maara < 0:
            raise ValueError
    except ValueError:
        context.bot.send_message(update.message.chat.id,
                                 "Antamasi luku ei kelpaa. Nosto keskeytetty.",
                                 reply_markup=ReplyKeyboardRemove())
        return ConversationHandler.END
    user = update.effective_user.id
    time = datetime.datetime.today().isoformat()
    name = db.get_user(user)[0][2]

    db.update_balance(update.effective_user.id, -maara)
    db.add_transaction(user, name, "NOSTO", time, maara)

    saldo = db.get_balance(update.effective_user.id)
    context.bot.send_message(
        update.message.chat.id,
        "Rahan nostaminen saldosta onnistui. Saldosi on nyt {:.2f}€".format(
            saldo / 100),
        reply_markup=ReplyKeyboardRemove())
    return ConversationHandler.END
Beispiel #4
0
def place_bet(name, amount, odds, betted):
    while 1:
        if db.member_exists(name):
            member_balance = db.check_balance(name)
            if member_balance >= amount:
                db.add_bet(name, amount, odds, betted)
                db.update_balance(name, member_balance - amount)
                break
            else:
                pass
        else:
            db.add_member(name)
            continue
Beispiel #5
0
def lisaa(bot, update):
    """Add money to account."""
    maara = 0
    try:
        maara = int(float(update.message.text.replace(",", ".")) * 100)
        if maara < 0:
            raise ValueError
    except ValueError:
        bot.send_message(update.message.chat.id, "Antamasi luku ei kelpaa. Lisääminen keskeytetty.", reply_markup = ReplyKeyboardRemove())
        return ConversationHandler.END

    user = update.effective_user.id
    time = datetime.datetime.today().isoformat()
    name = db.get_user(user)[0][2]


    db.update_balance(update.effective_user.id, maara)
    db.add_transaction(user, name, "PANO", time, maara)

    saldo = db.get_balance(update.effective_user.id)
    bot.send_message(update.message.chat.id, "Saldon lisääminen onnistui. Saldosi on nyt {:.2f}€".format(saldo / 100), reply_markup = ReplyKeyboardRemove())

    return ConversationHandler.END
Beispiel #6
0
def chequing_account(client):
    while True:
        try:
            select_account_operation = int(input("Select: 1 - deposit, 2 - withdrawal, 3 - transfer, 4 - account details, 5 - chequing account balance: "))
            while select_account_operation < 6 and select_account_operation > 0:
                if select_account_operation == 1:
                    print("Deposit")
                    while True:
                        try:
                            transaction_amount = float(input("Enter amount you wish to deposit: "))
                            account_details = fetch_account_details(client.client_id, "Chequing")
                            balance = account_details[4]
                            # account = Account(account_details[4])
                            # account.
                            print("Your chequing account balance is " + str(balance))
                            print("You are depositing " + str(transaction_amount))
                            current_balance = float(current_balance) + float(transaction_amount)
                            print("Your new chequing account balance is " + str(current_balance))
                            update_balance(client.client_id, current_balance, "Chequing")
                            client_return_to(client)
                            return current_balance
                            break
                        except ValueError:
                            print("Enter a number. Try again.")
                        else:
                            return transaction_amount
                            break
                    break
                elif select_account_operation == 2:
                    print("Withdraw")
                    while True:
                        try:
                            transaction_amount = float(input("Enter amount you wish to withdraw: "))
                            account_details = fetch_account_details(client.client_id, "Chequing")
                            balance = account_details[4]
                            # account = Account(account_details[4])
                            # account.
                            print("Your chequing account balance is " + str(balance))
                            print("You are withdrawing " + str(transaction_amount))
                            current_balance = float(balance) - float(transaction_amount)
                            print("Your new chequing account balance is " + str(current_balance))
                            update_balance(client.client_id, current_balance, "Chequing")
                            client_return_to(client)
                            return current_balance
                            break
                        except ValueError:
                            print("Enter a number. Try again.")
                        else:
                            return transaction_amount
                            break
                    break
                elif select_account_operation == 3:
                    print("Transfer")
                    while True:
                        try:
                            transfer_to = int(input("Select 1 - to transfer from chequing to savings account, 2 - to transfer from savings to chequing account: "))
                            while transfer_to > 0 and transfer_to < 3:
                                if transfer_to == 1:
                                    while True:
                                        try:
                                            transaction_amount = float(input("Enter amount you wish to transfer to savings account: "))
                                            chequing_account_details = fetch_account_details(client.client_id, "Chequing")
                                            current_chequing_balance = chequing_account_details[4]
                                            savings_account_details = fetch_account_details(client.client_id, "Savings")
                                            current_savings_balance = savings_account_details[4]
                                            # account = Account(account_details[4])
                                            # account.
                                            print("Your chequing account balance is " + str(current_chequing_balance))
                                            print("Your savings account balance is " + str(current_savings_balance))
                                            print("You are transfering " + str(transaction_amount))
                                            new_chequing_balance = float(current_chequing_balance) - float(transaction_amount)
                                            new_savings_balance = float(current_savings_balance) + float(transaction_amount)
                                            print("Your new chequing account balance is " + str(new_chequing_balance))
                                            print("Your new savings account balance is " + str(new_savings_balance))
                                            update_balance(client.client_id, new_savings_balance, "Savings")
                                            update_balance(client.client_id, new_chequing_balance, "Chequing")
                                            client_return_to(client)
                                            return new_chequing_balance, new_savings_balance
                                            break
                                        except ValueError:
                                            print("Enter a number. Try again.")
                                        else:
                                            return transaction_amount
                                            break
                                if transfer_to == 2:
                                    while True:
                                        try:
                                            transaction_amount = float(input("Enter amount you wish to transfer to chequing account: "))
                                            savings_account_details = fetch_account_details(client.client_id, "Savings")
                                            current_savings_balance = savings_account_details[4]
                                            chequing_account_details = fetch_account_details(client.client_id, "Chequing")
                                            current_chequing_balance = chequing_account_details[4]
                                            # account = Account(account_details[4])
                                            # account
                                            print("Your savings account balance is " + str(current_savings_balance))
                                            print("Your chequing account balance is " + str(current_chequing_balance))
                                            print("You are transfering " + str(transaction_amount))
                                            new_savings_balance = float(current_savings_balance) - float(transaction_amount)
                                            new_chequing_balance = float(current_chequing_balance) + float(transaction_amount)
                                            print("Your new savings account balance is " + str(new_savings_balance))
                                            print("Your new chequing account balance is " + str(new_chequing_balance))
                                            update_balance(client.client_id, new_savings_balance, "Savings")
                                            update_balance(client.client_id, new_chequing_balance, "Chequing")
                                            client_return_to(client)
                                            return new_savings_balance, new_chequing_balance
                                            break
                                        except ValueError:
                                            print("Enter a number. Try again.")
                                        else:
                                            return transaction_amount
                                            break
                            else:
                                print("Try again, please enter option 1 or 2. ")
                                continue
                        except ValueError:
                            print("Enter a number. Try again.")
                        else:
                            return transfer_to
                            break
                    break
                elif select_account_operation == 4:
                    print("Account details")
                    print(' number     status  type       client ID balance')
                    account_details = fetch_account_details(client.client_id, 'Chequing')
                    # show account detals
                    print(account_details) 
                    client_return_to(client)
                    break
                elif select_account_operation == 5:
                    print("Chequing account balance")
                    account_details = fetch_account_details(client.client_id, "Chequing")
                    current_balance = account_details[4]
                    print("Your chequing account balance is " + str(current_balance))
                    client_return_to(client)
                    break
            else:                             
                print("Try again, please enter option number from 1 to 5: ")
                continue
        except ValueError:
            print("Enter a number. Try again.")
        else:
            return select_account_operation
            break