python_bot/handlers/pipisa.py

135 lines
5.3 KiB
Python
Raw Normal View History

2022-12-05 17:22:23 +10:00
from aiogram import types, Dispatcher
2022-12-05 19:25:06 +10:00
from sqlalchemy.orm.session import close_all_sessions
2022-12-05 17:22:23 +10:00
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(-7,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
# работа с таблицей
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()
now_time = datetime.datetime.now()
session.close()
last_time = b.datetimes
diff = now_time.day - last_time.day
if abs(diff) <= 0:
with session:
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{b.dick_size}</b> см! ')
2022-12-05 19:25:06 +10:00
await close_all_sessions()
2022-12-05 17:22:23 +10:00
print(diff)
print(type(diff))
else:
with session:
a = session.query(user).filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице
a.dick_size = (a.dick_size + numb)
a.datetimes = datetime.datetime.now()
session.commit() #обновляет запись
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{a.dick_size}</b> см! ')
2022-12-05 19:25:06 +10:00
close_all_sessions()
2022-12-05 17:22:23 +10:00
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(),\
chat_id = message.chat.id)
session.add(int_table)
session.commit()
session.close()
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
Теперь он равен <b>{int_table.dick_size}</b> см!')
2022-12-05 19:25:06 +10:00
close_all_sessions()
2022-12-05 17:22:23 +10:00
@dp.message_handler(commands=["topdick"])
async def send_topchat(message: types.Message):
2022-12-05 19:25:06 +10:00
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
2022-12-05 19:38:38 +10:00
session.commit()
2022-12-05 17:22:23 +10:00
session.close()
2022-12-05 19:25:06 +10:00
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()
2022-12-05 17:22:23 +10:00
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')
2022-12-05 19:25:06 +10:00
close_all_sessions()
2022-12-05 17:22:23 +10:00
# если все нормально и участников минимум 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')
session.close()
@dp.message_handler(commands=["globaldick"])
async def send_global_top(message: types.Message):
with session:
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')
2022-12-05 19:25:06 +10:00
close_all_sessions()
2022-12-05 17:22:23 +10:00
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)