D
D
duduychvbk992021-10-07 00:42:30
Telegram
duduychvbk99, 2021-10-07 00:42:30

How to implement this through telebot and datetime?

The person writes: send
Bot answers: ready
Otherwise: if an hour has not passed after the next request, the bot cannot write.
Preferably with code, because I'm a nerd at this

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
InternetMaster, 2021-10-07
@InternetMaster

We need to work with the database. sqlite3 will do.
After the bot sends a message "done", you need to add a record about this (if the user is new to the bot, or update the record if he has already sent a request). Where table is the name of the table.

sql = ('INSERT INTO table (user_id, date) VALUES (?, ?)')
val = (str(message.chat.id), date) #date - Это ЧЧ:ММ в формате 24часовой системы. Не надо полную дату.
cursor.execute(sql, val)
db.commit()

#Или обновить

cursor.execute('UPDATE date  = "' + date + '" FROM table WHERE user_id = "' + str(message.chat.id) + '"')
db.commit

Then, after each user command "send", the script will check the value with the previous one, and if the difference is more than 1 hour, then the bot will answer "done". To do this, you need to pull out the previous value with a search by user_id. In order not to worry about the line id, after checking, replace the value with a new one. Hope you can figure it out yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question