2023-06-20 13:21:28 +10:00
|
|
|
|
from aiogram import types
|
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
|
2023-06-20 13:21:28 +10:00
|
|
|
|
from sqdb import User, session, DickRequest, UserDick
|
2022-12-15 22:30:53 +10:00
|
|
|
|
import random
|
2023-06-19 17:09:04 +10:00
|
|
|
|
import traceback
|
2022-12-05 17:22:23 +10:00
|
|
|
|
from random import randint
|
|
|
|
|
import datetime
|
2022-12-16 22:16:21 +10:00
|
|
|
|
from dicktxt import ForReadDict
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
2023-06-19 17:09:04 +10:00
|
|
|
|
size_change = None
|
|
|
|
|
dick_plus = None
|
|
|
|
|
dick_minus = None
|
|
|
|
|
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
2023-06-20 13:21:28 +10:00
|
|
|
|
def get_dick(user_id, chat_id):
|
|
|
|
|
dick = session.query(UserDick).filter(UserDick.user_id == user_id, UserDick.chat_id == chat_id).first()
|
|
|
|
|
return dick
|
|
|
|
|
|
2023-06-19 17:33:06 +10:00
|
|
|
|
def top_dick_message(delimiter, top_list):
|
|
|
|
|
message = f'🏆Топ 10 бубылд чата🏆\n\n'
|
|
|
|
|
f'🚀 {delimiter.join(map(str, top_list[0]))}\n'
|
|
|
|
|
f'💫 {delimiter.join(map(str, top_list[1]))}\n'
|
|
|
|
|
f'🍆 {delimiter.join(map(str, top_list[2]))}\n'
|
|
|
|
|
f'🍌 {delimiter.join(map(str, top_list[3]))}\n'
|
|
|
|
|
f'🐍 {delimiter.join(map(str, top_list[4]))}\n'
|
|
|
|
|
f'🐎 {delimiter.join(map(str, top_list[5]))}\n'
|
|
|
|
|
f'🌭 {delimiter.join(map(str, top_list[6]))}\n'
|
|
|
|
|
f'🌶 {delimiter.join(map(str, top_list[7]))}\n'
|
|
|
|
|
f'👌 {delimiter.join(map(str, top_list[8]))}\n'
|
|
|
|
|
f'💩 {delimiter.join(map(str, top_list[9]))}\n'
|
2023-06-19 19:24:40 +10:00
|
|
|
|
return message
|
|
|
|
|
|
|
|
|
|
|
2023-06-20 13:21:28 +10:00
|
|
|
|
@dp.message_handler(commands=["maintenance"])
|
2023-06-19 19:24:40 +10:00
|
|
|
|
async def stop_for_maintenance(message: types.Message): # остановить бота
|
|
|
|
|
if message.from_user.id == 226765676:
|
2023-06-20 13:21:28 +10:00
|
|
|
|
bot.send_message(message.from_user.id, "Блять. Как же больно. Мне холодно. Наверное это конец...")
|
|
|
|
|
close_all_sessions()
|
|
|
|
|
dp.stop_polling()
|
2023-06-19 17:33:06 +10:00
|
|
|
|
|
|
|
|
|
|
2022-12-05 17:22:23 +10:00
|
|
|
|
@dp.message_handler(commands=["dick"])
|
2023-06-19 17:09:04 +10:00
|
|
|
|
async def up_dick(message: types.Message): # рандомайзер
|
|
|
|
|
|
|
|
|
|
numb = randint(-6, 10)
|
2022-12-05 17:22:23 +10:00
|
|
|
|
global size_change, dick_plus, dick_minus
|
2023-06-19 19:24:40 +10:00
|
|
|
|
dick_plus = ('<b>вырос</b>', '<b>подрос</b>', '<b>привстал</b>')
|
2022-12-16 22:46:34 +10:00
|
|
|
|
dick_minus = ('<b>уменьшился</b>', '<b>откусила злая гадюка</b>', '<b>продали евреи, он стал дешевле</b>')
|
2022-12-05 17:22:23 +10:00
|
|
|
|
if numb > 0:
|
2023-06-19 19:24:40 +10:00
|
|
|
|
size_change = random.choice(dick_plus) + '🚀'
|
2023-06-19 17:09:04 +10:00
|
|
|
|
# if numb = 0 size_change = random.choice(const) TODO
|
|
|
|
|
else:
|
|
|
|
|
size_change = random.choice(dick_minus) + '✂'
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# работа с таблицей
|
2022-12-07 21:12:21 +10:00
|
|
|
|
try:
|
2023-06-19 17:09:04 +10:00
|
|
|
|
dick_request = DickRequest(size_change=numb, date_changed=datetime.datetime.now())
|
2023-06-20 13:21:28 +10:00
|
|
|
|
b = session.query(User).filter(User.user_id == message.from_user.id).first()
|
2022-12-07 21:12:21 +10:00
|
|
|
|
if b:
|
2023-06-19 17:09:04 +10:00
|
|
|
|
last_time = b.date_updated
|
2022-12-07 21:12:21 +10:00
|
|
|
|
now_time = datetime.datetime.now()
|
|
|
|
|
diff = now_time.day - last_time.day
|
2022-12-06 22:19:47 +10:00
|
|
|
|
|
2022-12-07 21:12:21 +10:00
|
|
|
|
if abs(diff) <= 0:
|
|
|
|
|
try:
|
|
|
|
|
current_dick = b.dick_size
|
2023-06-19 17:09:04 +10:00
|
|
|
|
await bot.send_message(message.chat.id, f'@{message.from_user.username},'
|
|
|
|
|
f'🚫 вы уже крутили пипису, '
|
|
|
|
|
f'ее размер <b>{current_dick}</b> см! ')
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('ошибка в if diff <=0 ' + "\n".join(traceback.format_tb(e.__traceback__)))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.rollback()
|
|
|
|
|
finally:
|
|
|
|
|
session.close_all()
|
2022-12-15 22:30:53 +10:00
|
|
|
|
print('пользователь уже крутил')
|
2022-12-07 21:12:21 +10:00
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
try:
|
2023-06-20 13:21:28 +10:00
|
|
|
|
usr = session.query(User)
|
|
|
|
|
a = usr.filter(User.user_id == message.from_user.id).first() # запрос на поиск в таблице
|
|
|
|
|
dick = get_dick(User.user_id, message.chat.id)
|
|
|
|
|
updated_dick = dick.dick_size = (dick.dick_size + numb)
|
2023-06-19 17:09:04 +10:00
|
|
|
|
dick_request.user = a
|
|
|
|
|
a.date_updated = datetime.datetime.now()
|
|
|
|
|
session.add(dick_request)
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.flush()
|
2023-06-19 17:09:04 +10:00
|
|
|
|
session.commit() # обновляет запись
|
2022-12-16 22:16:21 +10:00
|
|
|
|
randomword = ForReadDict.RandomDick()
|
2022-12-06 17:05:09 +10:00
|
|
|
|
|
2023-06-19 17:09:04 +10:00
|
|
|
|
await bot.send_message(message.chat.id, f'@{message.from_user.username}, '
|
|
|
|
|
f'ваш <em>{randomword}</em> {size_change}'
|
|
|
|
|
f'на <b>{abs(numb)}</b> см!\n'
|
|
|
|
|
f'Теперь он равен <b>{updated_dick}</b> см! ')
|
|
|
|
|
except Exception as e:
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.rollback()
|
2023-06-19 17:09:04 +10:00
|
|
|
|
print('ошибка в обновлении пиписы, трейсбек-бек-бек: ' +
|
|
|
|
|
"\n".join(traceback.format_tb(e.__traceback__)))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
finally:
|
|
|
|
|
session.close_all()
|
|
|
|
|
print('пиписа обновлена')
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
2022-12-07 21:12:21 +10:00
|
|
|
|
else:
|
|
|
|
|
session.close()
|
|
|
|
|
try:
|
2023-06-21 11:53:50 +10:00
|
|
|
|
numb = randint(1, 10)
|
2023-06-20 13:21:28 +10:00
|
|
|
|
int_table = User(user_id=message.from_user.id,
|
|
|
|
|
user_fullname=message.from_user.full_name,
|
2023-06-19 17:09:04 +10:00
|
|
|
|
date_updated=datetime.datetime.now(),
|
2023-06-20 13:21:28 +10:00
|
|
|
|
date_created=datetime.datetime.now())
|
|
|
|
|
new_dick = DickRequest(user_id=message.from_user.id,
|
|
|
|
|
chat_id=message.chat.id,
|
|
|
|
|
dick_size=numb)
|
2022-12-07 21:12:21 +10:00
|
|
|
|
|
2023-06-19 17:09:04 +10:00
|
|
|
|
dick_request.user = int_table
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.add(int_table)
|
2023-06-20 13:21:28 +10:00
|
|
|
|
session.add(new_dick)
|
2023-06-19 17:09:04 +10:00
|
|
|
|
session.add(dick_request)
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.flush()
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
2023-06-19 17:09:04 +10:00
|
|
|
|
await bot.send_message(message.chat.id, f'@{message.from_user.username}, '
|
2023-06-22 00:16:09 +10:00
|
|
|
|
f'ваш писюн показал головку 🚀 \n'
|
2023-06-19 17:09:04 +10:00
|
|
|
|
f'на <b>{abs(numb)}</b> см!\n'
|
|
|
|
|
f'Теперь он равен <b>{numb}</b> см!')
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print('ошибка в добавлении нового пользователя, трейсбек: ' +
|
|
|
|
|
'\n'.join(traceback.format_tb(e.__traceback__)))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.rollback()
|
|
|
|
|
finally:
|
|
|
|
|
session.close_all()
|
|
|
|
|
print('Успешно добавлен пользователь')
|
2022-12-06 22:27:12 +10:00
|
|
|
|
|
2023-06-19 17:33:06 +10:00
|
|
|
|
except Exception as e:
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.rollback()
|
2023-06-19 17:33:06 +10:00
|
|
|
|
print('ошибка в основном коде, трейсбек:' + '\n'.join(traceback.format_tb(e.__traceback__)))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
finally:
|
|
|
|
|
session.close_all()
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message_handler(commands=["topdick"])
|
2023-06-20 13:21:28 +10:00
|
|
|
|
async def send_top_chat(message: types.Message):
|
2022-12-07 21:12:21 +10:00
|
|
|
|
try:
|
2023-06-20 13:21:28 +10:00
|
|
|
|
top = []
|
|
|
|
|
chats = message.chat.id
|
|
|
|
|
changechat_id = session.query(DickRequest).filter(DickRequest.user_id == message.from_user.id,
|
|
|
|
|
DickRequest.chat_id == chats).first()
|
|
|
|
|
dicks = session.query(DickRequest)\
|
|
|
|
|
.filter(DickRequest.chat_id == chats)\
|
|
|
|
|
.limit(10).all()\
|
|
|
|
|
.order_by(DickRequest.dick_size.desc())
|
|
|
|
|
for dick in dicks:
|
|
|
|
|
user = session.query(User.user_fullname).filter(User.user_id == dick.user_id)
|
|
|
|
|
top.append([user.full_name, dick.dick_size])
|
2023-06-19 17:09:04 +10:00
|
|
|
|
delimiter = ': '
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
|
|
|
|
# проверка на длину списка, если меньше limit, то:
|
|
|
|
|
|
2023-06-19 17:33:06 +10:00
|
|
|
|
size_len = len(top)
|
|
|
|
|
if size_len < 10:
|
|
|
|
|
len_minus = 10 - size_len
|
2023-06-20 13:21:28 +10:00
|
|
|
|
top.extend([('-'*len_minus),""])
|
2023-06-19 17:33:06 +10:00
|
|
|
|
await bot.send_message(message.chat.id, top_dick_message(delimiter, top))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.close()
|
|
|
|
|
# если все нормально и участников минимум 10
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
2023-06-19 17:33:06 +10:00
|
|
|
|
await bot.send_message(message.chat.id, top_dick_message(delimiter, top))
|
2023-06-19 19:24:40 +10:00
|
|
|
|
except Exception as e:
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.rollback()
|
2023-06-19 19:24:40 +10:00
|
|
|
|
print('ошибка в /topdick. Трейсбэк:\n' + '\n'.join(traceback.format_tb(e.__traceback__)))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
finally:
|
|
|
|
|
session.close_all()
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message_handler(commands=["globaldick"])
|
|
|
|
|
async def send_global_top(message: types.Message):
|
2022-12-07 21:12:21 +10:00
|
|
|
|
try:
|
2023-06-20 13:21:28 +10:00
|
|
|
|
top = []
|
|
|
|
|
dicks = session.query(DickRequest) \
|
|
|
|
|
.limit(10).all() \
|
|
|
|
|
.order_by(DickRequest.dick_size.desc())
|
|
|
|
|
for dick in dicks:
|
|
|
|
|
user = session.query(User.user_fullname).filter(User.user_id == dick.user_id)
|
|
|
|
|
top.append([user.full_name, dick.dick_size])
|
2022-12-07 21:12:21 +10:00
|
|
|
|
delimiter = ': '
|
2023-06-19 17:33:06 +10:00
|
|
|
|
|
2023-06-20 13:21:28 +10:00
|
|
|
|
await bot.send_message(message.chat.id, top_dick_message(delimiter, top))
|
2023-06-19 19:24:40 +10:00
|
|
|
|
except Exception as e:
|
2022-12-07 21:12:21 +10:00
|
|
|
|
session.rollback()
|
2023-06-19 19:24:40 +10:00
|
|
|
|
print('ошибка в /globaldick, трейсбэк:\n' + '\n'.join(traceback.format_tb(e.__traceback__)))
|
2022-12-07 21:12:21 +10:00
|
|
|
|
finally:
|
|
|
|
|
session.close_all()
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
|
|
|
|
|
2022-12-13 17:51:47 +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)
|