fix session
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pavel_Duron 2022-12-04 17:11:30 +10:00
parent cc4549d598
commit e748ee3913

15
bot.py
View File

@ -66,19 +66,23 @@ async def ident(message: types.Message):
# работа с таблицей # работа с таблицей
if session.query(user).filter(user.user_id == message.from_user.id).first(): if session.query(user).filter(user.user_id == message.from_user.id).first():
b = session.query(user).filter(user.user_id == message.from_user.id).first() b = session.query(user).filter(user.user_id == message.from_user.id).first()
now_time = datetime.datetime.now() now_time = datetime.datetime.now()
session.close()
last_time = b.datetimes last_time = b.datetimes
diff = now_time.day - last_time.day diff = now_time.day - last_time.day
if abs(diff) <= 0: if abs(diff) <= 0:
with session:
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{b.dick_size}</b> см! ') await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{b.dick_size}</b> см! ')
session.close_all() session.close()
print(diff) print(diff)
print(type(diff)) print(type(diff))
else: else:
with session:
a = session.query(user).filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице a = session.query(user).filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице
a.dick_size = (a.dick_size + numb) a.dick_size = (a.dick_size + numb)
a.datetimes = datetime.datetime.now() a.datetimes = datetime.datetime.now()
@ -88,13 +92,15 @@ async def ident(message: types.Message):
session.close() session.close()
else: else:
with session:
int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb, datetimes = datetime.datetime.now(),\ int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb, datetimes = datetime.datetime.now(),\
chat_id = message.chat.id) chat_id = message.chat.id)
session.add(int_table) session.add(int_table)
session.commit() session.commit()
session.close()
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\ await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{int_table.dick_size}</b> см!') Теперь он равен <b>{int_table.dick_size}</b> см!')
session.close()
# int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb) #импортирую юзер из sqdb # int_table = user(user_id = message.from_user.id, user_fullname = message.from_user.full_name, dick_size = numb) #импортирую юзер из sqdb
@ -112,12 +118,13 @@ chat_id = message.chat.id)
@dp.message_handler(commands=["topdick"]) @dp.message_handler(commands=["topdick"])
async def send_topchat(message: types.Message): async def send_topchat(message: types.Message):
with session:
changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first() changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first()
chats = message.chat.id chats = message.chat.id
if changechat_id.chat_id != chats: if changechat_id.chat_id != chats:
changechat_id.chat_id = chats changechat_id.chat_id = chats
session.commit()
session.close() session.close()
with session:
top = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).filter(user.chat_id == chats).limit(10).all() top = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).filter(user.chat_id == chats).limit(10).all()
session.close() session.close()
delimiter = ': ' delimiter = ': '