Когда пишу Команду казино [СУММА]
Выдаёт ошибку:
File "<string>", line 7198, in prof_user
UnboundLocalError: local variable 'time' referenced before assignment
Сообственно код:
if message.text.startswith("Казино"):
msg = message
user_id = msg.from_user.id
chat_id = message.chat.id
win = ['', '', '', '']
loser = ['', '', '', '', '']
rx = random.randint(0, 110)
rwin = random.choice(win)
rloser = random.choice(loser)
msg = message
name1 = message.from_user.get_mention(as_html=True)
name = msg.from_user.last_name
summ = int(msg.text.split()[1])
print(f"{name} поставил в казино: {summ} и выиграл/проиграл: {rx}")
balance = cursor.execute("SELECT balance from users where user_id = ?", (message.from_user.id,)).fetchone()
balance = round(int(balance[0]))
period = 5
get = cursor.execute("SELECT last_stavka FROM bot WHERE chat_id = ?", (message.chat.id,)).fetchone()
last_stavka = f"{int(get[0])}"
stavkatime = time.time() - float(last_stavka)
if stavkatime > period:
if balance >= summ:
if summ > 0:
if int(rx) in range(0, 15):
c = Decimal(summ)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы проиграли {c2}$ (x0) {rloser}', parse_mode='html')
cursor.execute(f'UPDATE users SET balance = {balance - summ} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(16, 33):
c = Decimal(summ - summ * 0.25)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы проиграли {c2}$ (x0.25) {rloser}',
parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {balance - summ * 0.75} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(34, 54):
c = Decimal(summ * 0.5)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы проиграли {c2}$ (x0.5) {rloser}',
parse_mode='html')
cursor.execute(f'UPDATE users SET balance = {balance - summ * 0.5} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(54, 62):
c = Decimal(summ - summ * 0.75)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы проиграли {c2}$ (x0.75) {rloser}',
parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {balance - summ * 0.25} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(63, 73):
c = summ * 1
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, ваши деньги остаются при вас {c2}$ (x1) {rwin}',
parse_mode='html')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(74, 83):
c = Decimal(summ * 1.25)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x1.25) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 1.25)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(84, 90):
c = Decimal(summ * 1.5)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x1.5) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 1.5)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(91, 96):
c = Decimal(summ * 1.75)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x1.75) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 1.75)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(97, 102):
c = Decimal(summ * 2)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x2) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 2)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) in range(103, 106):
c = Decimal(summ * 3)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x3) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 3)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
if int(rx) == 110:
c = Decimal(summ * 50)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x50) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 50)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
if int(rx) in range(107, 109):
c = Decimal(summ * 10)
c2 = round(c)
c2 = '{:,}'.format(c2)
await bot.send_message(chat_id, f'{name1}, вы выиграли {c2}$ (x10) {rwin}', parse_mode='html')
cursor.execute(
f'UPDATE users SET balance = {(balance - summ) + (summ * 10)} WHERE user_id = "{user_id}"')
cursor.execute(f'UPDATE bot SET last_stavka=? WHERE chat_id=?', (time.time(), chat_id,))
connect.commit()
return
elif summ <= 1:
await bot.send_message(chat_id, f'{name1}, нельзя ставить отрицательное число! {rloser}',
parse_mode='html')
elif int(balance) <= int(summ):
await bot.send_message(chat_id, f'{name1}, недостаточно средств! {rloser}', parse_mode='html')
else:
await bot.send_message(chat_id, f'{name1}, извини. но играть можно только каждые 5️⃣ секунд. {rloser}',
parse_mode='html')
return
Строка из-за которой ошибка:
get = cursor.execute("SELECT last_stavka FROM bot WHERE chat_id = ?", (message.chat.id,)).fetchone()
last_stavka = f"{int(get[0])}"
stavkatime = time.time() - float(last_stavka)