rewrite code with try exc finaly
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
4749ee885d
commit
18b1a1d7f8
@ -10,7 +10,7 @@ import datetime
|
||||
@dp.message_handler(commands=["dick"])
|
||||
async def up_dick(message: types.Message):
|
||||
# рандомайзер
|
||||
numb = randint(-7,10)
|
||||
numb = randint(-6,10)
|
||||
global size_change, dick_plus, dick_minus
|
||||
dick_plus = f'<b>вырос</b> 🚀 на <b>{numb}</b> см!'
|
||||
dick_minus = f'<b>уменьшился</b> ✂ на <b>{abs(numb)}</b> см!'
|
||||
@ -20,52 +20,81 @@ async def up_dick(message: types.Message):
|
||||
|
||||
|
||||
# работа с таблицей
|
||||
try:
|
||||
b = session.query(user).filter(user.user_id == message.from_user.id).first()
|
||||
if b:
|
||||
last_time = b.datetimes
|
||||
now_time = datetime.datetime.now()
|
||||
diff = now_time.day - last_time.day
|
||||
|
||||
|
||||
|
||||
if abs(diff) <= 0:
|
||||
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{b.dick_size}</b> см! ')
|
||||
session.close()
|
||||
print(diff)
|
||||
print(type(diff))
|
||||
try:
|
||||
current_dick = b.dick_size
|
||||
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{current_dick}</b> см! ')
|
||||
except:
|
||||
print('ошибка в if diff <=0')
|
||||
session.rollback()
|
||||
finally:
|
||||
session.close_all()
|
||||
print('пользвоатель уже крутил')
|
||||
|
||||
else:
|
||||
try:
|
||||
a = session.query(user).filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице
|
||||
a.dick_size = (a.dick_size + numb)
|
||||
updetedDick = a.dick_size = (a.dick_size + numb)
|
||||
a.datetimes = datetime.datetime.now()
|
||||
session.flush()
|
||||
session.commit() #обновляет запись
|
||||
|
||||
|
||||
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
|
||||
Теперь он равен <b>{a.dick_size}</b> см! ')
|
||||
session.close()
|
||||
Теперь он равен <b>{updetedDick}</b> см! ')
|
||||
except:
|
||||
session.rollback()
|
||||
print('ошибка в обновлении пиписы')
|
||||
finally:
|
||||
session.close_all()
|
||||
print('пиписа обновлена')
|
||||
|
||||
|
||||
|
||||
else:
|
||||
session.close()
|
||||
try:
|
||||
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)
|
||||
session.add(int_table)
|
||||
session.commit()
|
||||
|
||||
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
|
||||
Теперь он равен <b>{int_table.dick_size}</b> см!')
|
||||
session.add(int_table)
|
||||
session.flush()
|
||||
session.commit()
|
||||
session.close()
|
||||
|
||||
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
|
||||
Теперь он равен <b>{numb}</b> см!')
|
||||
except:
|
||||
print('ошибка в добавлении нового пользователя')
|
||||
session.rollback()
|
||||
finally:
|
||||
session.close_all()
|
||||
print('Успешно добавлен пользователь')
|
||||
|
||||
except:
|
||||
session.rollback()
|
||||
print('ошибка в основном коде')
|
||||
finally:
|
||||
session.close_all()
|
||||
|
||||
|
||||
@dp.message_handler(commands=["topdick"])
|
||||
async def send_topchat(message: types.Message):
|
||||
try:
|
||||
changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first()
|
||||
chats = message.chat.id
|
||||
if changechat_id.chat_id != chats:
|
||||
changechat_id.chat_id = chats
|
||||
session.commit()
|
||||
session.close()
|
||||
else:
|
||||
session.close()
|
||||
top = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).filter(user.chat_id == chats).limit(10).all()
|
||||
delimiter = ': '
|
||||
@ -103,14 +132,19 @@ async def send_topchat(message: types.Message):
|
||||
🌶 {delimiter.join(map(str, top[7]))}\n\
|
||||
👌 {delimiter.join(map(str, top[8]))}\n\
|
||||
💩 {delimiter.join(map(str, top[9]))}\n')
|
||||
session.close()
|
||||
except:
|
||||
session.rollback()
|
||||
print('ошибка в /topdick')
|
||||
finally:
|
||||
session.close_all()
|
||||
|
||||
|
||||
|
||||
@dp.message_handler(commands=["globaldick"])
|
||||
async def send_global_top(message: types.Message):
|
||||
try:
|
||||
top_chat = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).limit(10).all()
|
||||
session.close()
|
||||
|
||||
delimiter = ': '
|
||||
|
||||
|
||||
@ -125,7 +159,11 @@ async def send_global_top(message: types.Message):
|
||||
8. {delimiter.join(map(str, top_chat[7]))}\n\
|
||||
9. {delimiter.join(map(str, top_chat[8]))}\n\
|
||||
10. {delimiter.join(map(str, top_chat[9]))}\n')
|
||||
|
||||
except:
|
||||
session.rollback()
|
||||
print('ошибка в /glovaldick')
|
||||
finally:
|
||||
session.close_all()
|
||||
|
||||
|
||||
def register_handlers_pipisa(dp: Dispatcher):
|
||||
|
Loading…
Reference in New Issue
Block a user