@MaDn1me

Как узнать прошлое сообщение которое было отправлено ботом telebot?

Я пишу пользователям в определенное время и они должны ответить и их голос будет записан в гугл таблицу, но проблема в том, что после того как пользователь проголосует у него все еще будет возможность голосовать дальше тем самым портить статистику. Решение которое я хотел сделать, но не получилось заключается в изменении либо же удалении его, однако тут встаёт другой вопрос, как узнать айди сообщения который ТОЛЬКО ЧТО проголосовал?
@bot.message_handler(commands=['start'])
def start(message):
    chat = int(message.from_user.id)
    print(chat, type(chat))
    conn = sqlite3.connect(r'place')
    cur = conn.cursor()
    cur.execute(f"INSERT OR IGNORE INTO users_id (ID) VALUES({chat});")
    conn.commit()
    bot.send_message(message.from_user.id, f'Здравствуйте! Вот ваш айди {chat}')


def schedule_checker():
    while True:
        schedule.run_pending()
        sleep(1)


def first():
    conn = sqlite3.connect(r'place')
    cur = conn.cursor()
    for id in cur.execute("SELECT * FROM users_id"):
        keyboard = telebot.types.InlineKeyboardMarkup()
        key_1 = telebot.types.InlineKeyboardButton(text='1', callback_data='1|breakfast')
        key_2 = telebot.types.InlineKeyboardButton(text='2', callback_data='2|breakfast')
        key_3 = telebot.types.InlineKeyboardButton(text='3', callback_data='3|breakfast')
        key_4 = telebot.types.InlineKeyboardButton(text='4', callback_data='4|breakfast')
        key_5 = telebot.types.InlineKeyboardButton(text='5', callback_data='5|breakfast')
        keyboard.add(key_1, key_2, key_3, key_4, key_5)
        msg = bot.send_message(id[0], "Оцените сегодняшний завтрак пожалуйста.", reply_markup=keyboard)


def second():
    conn = sqlite3.connect(r'place')
    cur = conn.cursor()
    for id in cur.execute("SELECT * FROM users_id"):
        keyboard = telebot.types.InlineKeyboardMarkup()
        key_1 = telebot.types.InlineKeyboardButton(text='1', callback_data='1|lunch')
        key_2 = telebot.types.InlineKeyboardButton(text='2', callback_data='2|lunch')
        key_3 = telebot.types.InlineKeyboardButton(text='3', callback_data='3|lunch')
        key_4 = telebot.types.InlineKeyboardButton(text='4', callback_data='4|lunch')
        key_5 = telebot.types.InlineKeyboardButton(text='5', callback_data='5|lunch')
        keyboard.add(key_1, key_2, key_3, key_4, key_5)
        msg = bot.send_message(id[0], "Оцените сегодняшний завтрак пожалуйста.", reply_markup=keyboard)


def third():
    conn = sqlite3.connect(r'place')
    cur = conn.cursor()
    for id in cur.execute("SELECT * FROM users_id"):
        keyboard = telebot.types.InlineKeyboardMarkup()
        key_1 = telebot.types.InlineKeyboardButton(text='1', callback_data='1|dinner|')
        key_2 = telebot.types.InlineKeyboardButton(text='2', callback_data='2|dinner|11')
        key_3 = telebot.types.InlineKeyboardButton(text='3', callback_data='3|dinner')
        key_4 = telebot.types.InlineKeyboardButton(text='4', callback_data='4|dinner')
        key_5 = telebot.types.InlineKeyboardButton(text='5', callback_data='5|dinner')
        keyboard.add(key_1, key_2, key_3, key_4, key_5)
        msg = bot.send_message(id[0], "Оцените сегодняшний завтрак пожалуйста.", reply_markup=keyboard)


@bot.callback_query_handler(func=lambda call: True, column=None)
def callback_worker(call):
    x = call.data.split('|')
    print(x)
    if x[0] == '1' and x[1] == 'breakfast':
        worksheet.update_cell(2, 2, int(worksheet.cell(2, 2).value) + 1)
    elif x[0] == '1' and x[1] == 'lunch':
        worksheet.update_cell(day_counter, 7, int(worksheet.cell(day_counter, 7).value) + 1)
    elif x[0] == '1' and x[1] == 'dinner':
        worksheet.update_cell(day_counter, 12, int(worksheet.cell(day_counter, 12).value) + 1)
    elif x[0] == '2' and x[1] == 'breakfast':
        worksheet.update_cell(day_counter, 3, int(worksheet.cell(day_counter, 3).value) + 1)
    elif x[0] == '2' and x[1] == 'lunch':
        worksheet.update_cell(day_counter, 8, int(worksheet.cell(day_counter, 8).value) + 1)
    elif x[0] == '2' and x[1] == 'dinner':
        worksheet.update_cell(day_counter, 13, int(worksheet.cell(day_counter, 13).value) + 1)
    elif x[0] == '3' and x[1] == 'breakfast':
        worksheet.update_cell(day_counter, 4, int(worksheet.cell(day_counter, 4).value) + 1)
    elif x[0] == '3' and x[1] == 'lunch':
        worksheet.update_cell(day_counter, 9, int(worksheet.cell(day_counter, 9).value) + 1)
    elif x[0] == '3' and x[1] == 'dinner':
        worksheet.update_cell(day_counter, 14, int(worksheet.cell(day_counter, 14).value) + 1)
    elif x[0] == '4' and x[1] == 'breakfast':
        worksheet.update_cell(day_counter, 5, int(worksheet.cell(day_counter, 5).value) + 1)
    elif x[0] == '4' and x[1] == 'dinner':
        worksheet.update_cell(day_counter, 10, int(worksheet.cell(day_counter, 10).value) + 1)
    elif x[0] == '4' and x[1] == 'lunch':
        worksheet.update_cell(day_counter, 15, int(worksheet.cell(day_counter, 15).value) + 1)
    elif x[0] == '5' and x[1] == 'breakfast':
        worksheet.update_cell(day_counter, 6, int(worksheet.cell(day_counter, 6).value) + 1)
    elif x[0] == '5' and x[1] == 'dinner':
        worksheet.update_cell(day_counter, 11, int(worksheet.cell(day_counter, 11).value) + 1)
    elif x[0] == '5' and x[1] == 'lunch':
        worksheet.update_cell(day_counter, 16, int(worksheet.cell(day_counter, 16).value) + 1)
    bot.delete_message(call.message.chat.id, )
    bot.send_message(call.message.chat.id, 'Спасибо за ваш ответ!')
    x = []


if __name__ == "__main__":
    # Create the job in schedule.
    schedule.every().day.at('10:24').do(first)
    schedule.every().day.at('12:00').do(second)
    schedule.every().day.at('18:00').do(third)
    Thread(target=schedule_checker).start()
    print('Hello world!')
    # And then of course, start your server.
    bot.polling(none_stop=True, interval=0)
  • Вопрос задан
  • 121 просмотр
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы