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
|
2023-06-19 17:09:04 +10:00
|
|
|
|
from sqdb import user, session, DickRequest
|
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-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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@dp.message_handler(commands=["maintainance"])
|
|
|
|
|
async def stop_for_maintenance(message: types.Message): # остановить бота
|
|
|
|
|
if message.from_user.id == 226765676:
|
|
|
|
|
close_all_sessions() # TODO Вспомнить, как это, блять, делается.
|
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())
|
2022-12-07 21:12:21 +10:00
|
|
|
|
b = session.query(user).filter(user.user_id == message.from_user.id).first()
|
|
|
|
|
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-19 17:09:04 +10:00
|
|
|
|
usr = session.query(user)
|
|
|
|
|
a = usr.filter(user.user_id == message.from_user.id).first() # запрос на поиск в таблице
|
|
|
|
|
updated_dick = a.dick_size = (a.dick_size + numb)
|
|
|
|
|
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-19 17:09:04 +10:00
|
|
|
|
int_table = user(user_id=message.from_user.id,
|
|
|
|
|
user_fullname=message.from_user.full_name,
|
|
|
|
|
dick_size=numb,
|
|
|
|
|
date_updated=datetime.datetime.now(),
|
|
|
|
|
date_created=datetime.datetime.now(),
|
|
|
|
|
chat_id=message.chat.id)
|
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-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}, '
|
|
|
|
|
f'ваш писюн {size_change}\n'
|
|
|
|
|
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"])
|
|
|
|
|
async def send_topchat(message: types.Message):
|
2022-12-07 21:12:21 +10:00
|
|
|
|
try:
|
|
|
|
|
changechat_id = session.query(user).filter(user.user_id == message.from_user.id).first()
|
2023-06-19 17:09:04 +10:00
|
|
|
|
delimiter = ': '
|
2022-12-07 21:12:21 +10:00
|
|
|
|
chats = message.chat.id
|
|
|
|
|
if changechat_id.chat_id != chats:
|
|
|
|
|
changechat_id.chat_id = chats
|
|
|
|
|
session.commit()
|
|
|
|
|
session.close()
|
|
|
|
|
else:
|
|
|
|
|
session.close()
|
2023-06-19 19:24:40 +10:00
|
|
|
|
users = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc())
|
|
|
|
|
top = users.filter(user.chat_id == chats).limit(10).all()
|
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
|
|
|
|
|
top.extend(('-'*len_minus))
|
|
|
|
|
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:
|
|
|
|
|
top_chat = session.query(user.user_fullname, user.dick_size).order_by(user.dick_size.desc()).limit(10).all()
|
2022-12-05 17:22:23 +10:00
|
|
|
|
|
2022-12-07 21:12:21 +10:00
|
|
|
|
delimiter = ': '
|
2023-06-19 17:33:06 +10:00
|
|
|
|
|
|
|
|
|
await bot.send_message(message.chat.id, top_dick_message(delimiter, top_chat))
|
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)
|