N
N
nuribairamov2022-03-13 00:42:05
Python
nuribairamov, 2022-03-13 00:42:05

How to get user_id from sqlite database, check if there is a subscription and send this person a message in a chat with a bot?

Initially, after entering the /start command, the bot registers the usek_id in the database.
Then, the user can buy a paid subscription, when he does, in the database, in the time_sub column, he is given 30 days in seconds.

def set_time_sub(self, user_id, time_sub):
        with self.connection:
            return self.cursor.execute("UPDATE `users` SET `time_sub` = ? WHERE `user_id` = ?", (time_sub, user_id,))

The idea is this: if the admin posts a post in the admin group, then it processes the text handler with the condition if message.chat.type == 'group', and launches a mailing list for the id that the next function received, the
function should pull the user_id from the database, which have time_sub not 0, and posts from the admin group would be sent to these id. I can’t figure out how to implement the extraction of id of paid subscribers and mailing specifically to them. If there are any other ways to implement posting to paid subscribers, I'm ready to see. Do not offer third party services. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2022-03-13
@phaggi

Didn't understand what the problem is? In the database, store for each userid the "subscription end date and time" field. It is necessary to make a mailing list - you sort through all the userid and send a message to those who have this field greater than the current datetime; do not send to others.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question