python_bot/handlers/pipisa.py

156 lines
7.8 KiB
Python
Raw Normal View History

2022-12-05 17:22:23 +10:00
from aiogram import types, Dispatcher
from create_bot import bot, dp
import random
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
2024-01-21 17:00:25 +10:00
from dicktxt import change_words
2023-07-16 01:50:12 +10:00
from pipisa_functions import pipisa_time
2024-01-21 17:00:25 +10:00
from DBChat import user_operations
from TopMsg import topdicks
2024-01-23 06:33:53 +10:00
from handlers import post_cleaner
2022-12-05 17:22:23 +10:00
2023-07-12 21:54:24 +10:00
2023-07-12 22:00:17 +10:00
#### https://docs.python-arango.com/en/main/
from arango import ArangoClient
admins = [317051301, 226765676]
2023-07-12 21:54:24 +10:00
2022-12-05 17:22:23 +10:00
@dp.message_handler(commands=["dick"])
async def up_dick(message: types.Message):
2023-07-12 21:54:24 +10:00
#global size_change, dick_plus, dick_minus
if message.from_user.id in admins or message.chat.type != 'private':
arango_client = ArangoClient(hosts='https://arango.guaranteedstruggle.host')
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
dicks_collection = pipisa_db.collection('dicks')
2024-01-21 17:00:25 +10:00
result = randint(-9,10) # главный рандомайзер
try: ## Тело метода прокрутки
candidate_cursor = dicks_collection.find( ## Проверить наличие пользователя в базе
{
'user_id': message.from_user.id,
'chat_id': message.chat.id
},
skip=0, limit=1488)
2024-01-21 17:00:25 +10:00
if candidate_cursor.count() > 0: ## Если пользователь есть то нарастить и отправить сообщение
user = candidate_cursor.pop()
2024-01-21 17:00:25 +10:00
if pipisa_time.rolltime(check_datetime=user['datetimes'], curr_time=datetime.datetime.now()):
2024-01-21 17:00:25 +10:00
updetedDick = user["dick_size"] + result ## получение итогового результата
pipisa_word = ForReadDict.RandomDick()
change_word = change_words.ChangeWord(result)
enl_message = await bot.send_message(message.chat.id, f"@\
{message.from_user.username}, \
ваш <em>{pipisa_word}</em> ,{change_word(result)} на <b>{abs(result)}</b> см!\n\ \
Теперь он равен <b>{updetedDick}</b> см! ")
2024-01-23 06:33:53 +10:00
post_cleaner.cleanup_sequence(user['user_id'], enl_message.id, message.chat.id)
2024-01-21 17:00:25 +10:00
try:
dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
metadata = dicks_collection.insert(
{
2024-01-21 17:00:25 +10:00
'_key': user['_key'], ## этот нужен чтобы апдейт прилетал тому же юзеру
'user_id': user['user_id'],
'user_fullname': message.from_user.full_name,
'dick_size': updetedDick,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'attempts': user['attempts'] + 1,
2024-01-23 06:33:53 +10:00
'chat_id': message.chat.id
},
overwrite_mode='update'
)
print(f'Успешно апдейтнули пипису @{message.from_user.username}')
2024-01-21 17:00:25 +10:00
except Exception as update_err:
print(f'ошибка в обновлении пиписы @{message.from_user.username}')
2024-01-21 17:00:25 +10:00
print(update_err)
else:
error_msg = await bot.send_message(message.chat.id, f'@\
{message.from_user.username},🚫 вы уже крутили пипису, \
ее размер <b>{user["dick_size"]}</b> см! ')
2024-01-23 06:33:53 +10:00
post_cleaner.cleanup_sequence(user['user_id'], error_msg.id, error_msg.chat.id)
try:
metadata = dicks_collection.insert(
{
'_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру
'user_id': user['user_id'] ,
'user_fullname': message.from_user.full_name,
'dick_size': user['dick_size'] ,
'datetimes': user['datetimes'] ,
'attempts': user['attempts'] + 1,
2024-01-21 17:00:25 +10:00
'chat_id': message.chat.id,
},
overwrite_mode='update'
)
print(f'Успешно апдейтнули попытку крутить пипису @{message.from_user.username}')
2024-01-21 17:00:25 +10:00
except Exception as roll_err:
print(f'ошибка в обновлении попытки крутить пипису @{message.from_user.username}')
2024-01-21 17:00:25 +10:00
print(roll_err)
print(f'пользователь @{message.from_user.username} уже крутил')
2024-01-21 17:00:25 +10:00
else: ## если пользователь не найден то создаём ему запись в БД
if result > 0:
new_reply = await bot.send_message(message.chat.id, f'@\
{message.from_user.username}, ваш писюн показал головку 🚀\n\
на <b>{abs(result)}</b> см!\n\
Теперь он равен <b>{result}</b> см!')
else:
new_reply =await bot.send_message(message.chat.id, f'@\
{message.from_user.username}, добро пожаловать в игру!🚀\n\
Ты стартуешь не с лучшей позиции, природа наградила тебя всего <b>{result}</b> см 😬')
2023-07-12 22:40:45 +10:00
2024-01-21 17:00:25 +10:00
user_operations.UserCreate(dicks_collection, message, result, new_reply.id)
2023-07-12 21:54:24 +10:00
print(f'Успешно добавлен пользователь @{message.from_user.username}')
2024-01-21 17:00:25 +10:00
2022-12-05 17:22:23 +10:00
2022-12-07 21:12:21 +10:00
2024-01-21 17:00:25 +10:00
except Exception as crit_err:
print('ошибка DB в /dick')
2024-01-21 17:00:25 +10:00
print(crit_err)
else:
await message.reply('Растить елду можно только в общих чатах!')
2023-07-12 21:54:24 +10:00
2022-12-05 17:22:23 +10:00
@dp.message_handler(commands=["topdick"])
2024-01-21 17:00:25 +10:00
async def send_topchat(message: types.Message): # тело метода лучших результатов отдельной конфы
if message.from_user.id in admins or message.chat.type != 'private':
2023-07-12 21:54:24 +10:00
2024-01-21 17:00:25 +10:00
dickos = topdicks.topdicks_conf(message.chat.id)
await bot.send_message(message.chat.id, '🏆Топ 10 бубылд чата🏆\n\n' + dickos)
2023-07-12 21:54:24 +10:00
else:
await message.reply('Работает только в общих чатах!\n'\
2024-01-21 17:00:25 +10:00
'Вы мсжете посмотреть топ по миру: /globaldick')
2022-12-05 17:22:23 +10:00
2023-07-12 21:54:24 +10:00
2022-12-05 17:22:23 +10:00
@dp.message_handler(commands=["globaldick"])
2024-01-21 17:00:25 +10:00
async def send_global_top(message: types.Message): # тело метода лучших результатов
tops = topdicks.topdicks_global(message.chat.id,)
2023-07-12 21:54:24 +10:00
2024-01-21 17:00:25 +10:00
await bot.send_message(message.chat.id, '🏆Топ 10 пипис в мире🏆\n\n' + tops)
2022-12-05 17:22:23 +10:00