forked from Pavel_Durov/python_bot
135 lines
5.1 KiB
Python
135 lines
5.1 KiB
Python
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(-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
|
||
|
||
|
||
# работа с таблицей
|
||
b = session.query(user).filter(user.user_id == message.from_user.id).first()
|
||
if b:
|
||
session.close()
|
||
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> см! ')
|
||
print(diff)
|
||
print(type(diff))
|
||
else:
|
||
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() #обновляет запись
|
||
session.close()
|
||
close_all_sessions()
|
||
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
|
||
Теперь он равен <b>{a.dick_size}</b> см! ')
|
||
|
||
|
||
else:
|
||
session.close()
|
||
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()
|
||
close_all_sessions()
|
||
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн {size_change}\n\
|
||
Теперь он равен <b>{int_table.dick_size}</b> см!')
|
||
|
||
|
||
|
||
@dp.message_handler(commands=["topdick"])
|
||
async def send_topchat(message: types.Message):
|
||
changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first()
|
||
session.close()
|
||
chats = message.chat.id
|
||
if changechat_id.chat_id != chats:
|
||
changechat_id.chat_id = chats
|
||
session.commit()
|
||
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()
|
||
session.close()
|
||
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')
|
||
|
||
# если все нормально и участников минимум 10
|
||
|
||
else:
|
||
session.close()
|
||
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')
|
||
|
||
|
||
|
||
|
||
@dp.message_handler(commands=["globaldick"])
|
||
async def send_global_top(message: types.Message):
|
||
top_chat = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).limit(10).all()
|
||
session.close()
|
||
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')
|
||
|
||
|
||
|
||
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)
|
||
|