Хочу сделать вывод сообщения при кулдауне по типу "Осталось подождать ЧАСОВ:МИНУТ", как сделать такой формат - не знаю.
import telebot
import sqlite3
import datetime
from imports import *
conn = sqlite3.connect('database.db', check_same_thread=False)
cur = conn.cursor()
@bot.message_handler(commands=["start"])
def start(message):
last_command_use_time = cur.execute('SELECT get_card_cd FROM users WHERE user_id={}'.format(message.chat.id)).fetchone()[0]
conn.commit()
p = list(itertools.accumulate([0.01, 0.005, 0.015, 0.05, 0.07, 0.1, 0.15, 0.2, 0.4]))
n = bisect.bisect(p, random.random())
x = datetime.datetime.strptime(last_command_use_time, '%Y-%m-%d %H:%M:%S.%f')
print(type(last_command_use_time), last_command_use_time)
user_id = message.chat.id
if not last_command_use_time or (datetime.datetime.now() - x).seconds/14400 > 1:
cur.execute('UPDATE users SET get_card_cd =? WHERE user_id =?', (datetime.datetime.now(), user_id))
conn.commit()
if n == 0:
print("1%")
bot.send_message()
elif n == 1:
print("0,5%")
elif n == 2:
print("1,5%")
elif n == 3:
print("5%")
elif n == 4:
print("7%")
elif n == 5:
print("10%")
elif n == 6:
print("15%")
elif n == 7:
print("20%")
elif n == 8:
print("40%")
else:
print('Error')
else:
bot.send_message(message.chat.id, text='Осталось подождать времени')