示例#1
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
示例#2
0
def poistatko(update, context):
    """Handles removing the last action made by the user."""

    if not is_registered(context.bot, update):
        return
    keyboard = [["Kyllä"], ["Ei"]]
    reply_markup = ReplyKeyboardMarkup(keyboard, one_time_keyboard=True)
    edellinen = db.get_last_transaction(update.effective_user.id)
    aika = edellinen[5][:16].split("T")
    paiva = aika[0]
    aika = aika[1]
    tuote = edellinen[3]
    hinta = edellinen[4] / 100
    update.message.reply_text(
        """Haluatko todella poistaa tapahtuman:\n{}  {}   {}   {:.2f}€?\n\nKirjoita missä vaiheessa tahansa /lopeta keskeyttääksesi toiminnon."""
        .format(paiva, aika, tuote, hinta),
        reply_markup=reply_markup)
    return POISTA
示例#3
0
def sort_data(data, addr, sock):
    global clients, c
    if data[0] == "new_event":
        db.check_event(data)
    elif data[0] == "check_db":
        sock.sendto(core.hash(db.get_last_transaction()), addr)
    elif data[0] == "get_peers":
        if len(clients) == 0:
            sock.sendto("peers::None", addr)
        else:
            table = "peers::"
            for i in clients:
                table = str(table + str(i) + ",,")
            sock.sendto(ttb(table), addr)
    elif data[0] == "peers":
        if data[1] == "None":
            print("Новых клиентов не найдено!")
            # init_connection(sock)
        else:
            list = data[1][:-2]
            new_list = list.split(",,")
            for i in new_list:
                if i not in clients:
                    check_user(eval(i))
        next_connection(sock)

    elif data[0] == "ping":
        sock.sendto(bytes("pong::", encoding='utf-8'), addr)

    # Если придёт данный запрос, сообщить клиенту: Я здесь!
    elif data[0] == "check_connect":
        sock.sendto(bytes("here::", encoding='utf-8'), addr)

    elif data[0] == "here":
        global room
        room += 1
        print("Ответ от клиента {}: нахожусь в сети.".format(addr))

    elif data[0] == "message":
        print("Текстовое сообщение от клиента {}: {}".format(
            addr,
            byte_to_string(data[1])[2:-1]))

    elif data[0] == "pong":
        c = 1
        sock.sendto(ttb("get_peers::"), addr)
        if addr not in clients:
            print('Добавлен', addr)
            clients.append(addr)
    elif data[0] == "pingg":
        sock.sendto(ttb("pongg::"), addr)
    elif data[0] == "quit":
        # Если реальный хост присутствуют в клиентах
        for address, poort in clients:
            if addr[0] == address:
                a = (address, poort)
                clients.remove(a)
                print("Отключился клиент {0}".format(a))
        if not clients:
            global client_status
            client_status = 1
示例#4
0
            to = input("Получатель: ")
            if any(to in addr for addr, prt in clients):
                string = (str(public_key[0]) + ":" + str(core.hash(text)) +
                          ":" + str(to))
                try:
                    mess = 'message::' + text
                    s1.sendto(ttb(mess), (to, 9090))
                    db.add_event(string)
                    print("Сообщение отправлено!")
                except:
                    print("Ошибка при отправке сообщения!")
            else:
                print('Клиент с IP - {} не подключен к сети.'.format(to))

        elif choose == "2":
            last_tx = db.get_last_transaction()
            if last_tx is not None:
                print(
                    "Последняя транзакция:\nid {0}\nОт кого: {1}\nсообщение: {2}\nКому: {3}\nДата: {4}\n----------------\n"
                    .format(last_tx[0], last_tx[1], last_tx[2], last_tx[3],
                            date(last_tx[4])))
            else:
                print("Транзакций не найдено!")
        elif choose == "3":
            wallet = input("Введите свой адрес: ")
            result = db.get_transactions(wallet)
            for i in result:
                print(
                    "id {0}\nОт кого: {1}\nСообщение: {2}\nКому: {3}\nДата: {4}\n----------------\n"
                    .format(i[0], i[1], i[2], i[3], date(i[4])))
        elif choose == "4":