F
F
fodiche2021-08-19 09:53:54
Python
fodiche, 2021-08-19 09:53:54

How to make a daily accrual of money in a bot by a written command in the chat, but if the user has already received money within 24 hours, then the bot wrote?

the bottom line is that when a person writes "va" he must replenish the account for a certain amount, but if he has already written it within 24 hours, then the bot gave an error and indicated after how much the command can be written again

if msg == "ва":
          db = sqlite3.connect('server12.db')
          db.row_factory = sqlite3.Row
          cursor = db.cursor()
          vatime = time.time()+1
          if time.time()<vatime:
            sender(id, "Эту команду можно использовать раз в 24 часа!")
          else:
            cursor.execute(f"UPDATE users SET money = money+400 WHERE user_id = {user_id}")
            sender(id, "На счет @{user_id}{fullname} Начисленно 400$")
          db.commit()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-08-19
@fodich

How would you do it in real life? Probably, they remembered the time of issuing money and, upon repeated request, would have calculated whether 24 hours had passed. It's no different in code. Remember the current time when issuing money through the same one , subtract the previous result time.time()from the next request . If the resulting number is greater than 60*60*24, then 24 hours have passed. time.time()time.time()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question