A
A
Anonymous Coder2020-11-26 23:02:42
Python
Anonymous Coder, 2020-11-26 23:02:42

How to implement "function inactivity timer" after using the function?

A bot where, when you click on a button, a message is published on the channel.

And so, I need to publish can be done no more than once an hour. If an hour has not passed since the last publication, send a message about exactly how much is left to wait.

I don't need auto-posting, I just need manual posting with a timer for the interval between messages.

Python | pyTelegramBotApi (telebot)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-11-27
@trapwalker

It's not clear from your question whether you plan to have a multiplayer bot or a singleplayer. That is, will more than one person use the same bot instance?
It is also not clear in the case of several users, each has its own limit of once per hour, or for all one message per hour.
In any case, your bot needs to store some information - this is called state storage.
You need to return the date of the last message for each user or for all, depending on the problem statement. In general, it is best to use some kind of database like mongi or sqlite for this. In the case of SQLite, you don't need to set anything, that's it. what is required is already bundled with python.
I would recommend doing at startup to create in it, if not already created, a table with the user ID and the date of the last message. In the future, it will be possible to implement both options for functionality.
As a result, you get the date of the last message from the table, add an hour to it, if it turned out later than the current time, then you can’t post. In the case of a post, we simply update the time in the database.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question