python_bot/handlers/pipisa.py
Pavel_Duron 17bb367a3a
All checks were successful
continuous-integration/drone/push Build is passing
fix tabilation
2022-12-08 21:46:03 +10:00

174 lines
6.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from aiogram import types, Dispatcher
from sqlalchemy.orm.session import close_all_sessions
from create_bot import bot, dp
from sqdb import user, session
from random import randint
import datetime
@dp.message_handler(commands=["dick"])
async def up_dick(message: types.Message):
# рандомайзер
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> см!'
if numb > 0:
size_change = dick_plus
else: size_change = dick_minus
# работа с таблицей
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:
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() # запрос на поиск в таблице
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>{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.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 = ': '
# проверка на длину списка, если меньше limit, то:
sizelen = len(top)
if sizelen < 10:
lenminus = 10 - sizelen
top.extend(('-'*lenminus))
await bot.send_message(message.chat.id, f'🏆Топ 10 бубылд чата🏆\n\n\
🚀 {delimiter.join(map(str, top[0]))}\n\
💫 {delimiter.join(map(str, top[1]))}\n\
🍆 {delimiter.join(map(str, top[2]))}\n\
🍌 {delimiter.join(map(str, top[3]))}\n\
🐍 {delimiter.join(map(str, top[4]))}\n\
🐎 {delimiter.join(map(str, top[5]))}\n\
🌭 {delimiter.join(map(str, top[6]))}\n\
🌶 {delimiter.join(map(str, top[7]))}\n\
👌 {delimiter.join(map(str, top[8]))}\n\
💩 {delimiter.join(map(str, top[9]))}\n')
session.close()
# если все нормально и участников минимум 10
else:
await bot.send_message(message.chat.id, f'🏆Топ 10 бубылд чата🏆\n\n\
🚀 {delimiter.join(map(str, top[0]))}\n\
💫 {delimiter.join(map(str, top[1]))}\n\
🍆 {delimiter.join(map(str, top[2]))}\n\
🍌 {delimiter.join(map(str, top[3]))}\n\
🐍 {delimiter.join(map(str, top[4]))}\n\
🐎 {delimiter.join(map(str, top[5]))}\n\
🌭 {delimiter.join(map(str, top[6]))}\n\
🌶 {delimiter.join(map(str, top[7]))}\n\
👌 {delimiter.join(map(str, top[8]))}\n\
💩 {delimiter.join(map(str, top[9]))}\n')
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()
delimiter = ': '
await bot.send_message(message.chat.id, f'🏆Топ 10 пипис в мире🏆\n\n\
1. {delimiter.join(map(str, top_chat[0]))}\n\
2. {delimiter.join(map(str, top_chat[1]))}\n\
3. {delimiter.join(map(str, top_chat[2]))}\n\
4. {delimiter.join(map(str, top_chat[3]))}\n\
5. {delimiter.join(map(str, top_chat[4]))}\n\
6. {delimiter.join(map(str, top_chat[5]))}\n\
7. {delimiter.join(map(str, top_chat[6]))}\n\
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):
dp.register_message_handler(up_dick)
dp.register_message_handler(send_topchat)
dp.register_message_handler(send_global_top)