python_bot/handlers/pipisa.py

229 lines
9.0 KiB
Python
Raw Normal View History

2022-12-05 17:22:23 +10:00
from aiogram import types, Dispatcher
2023-07-12 21:54:24 +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-07-12 21:54:24 +10:00
#from sqdb import user, session
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
2023-07-16 01:50:12 +10:00
from pipisa_functions import pipisa_time
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
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
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
dicks_collection = pipisa_db.collection('dicks')
# рандомайзер
2023-07-15 05:21:27 +10:00
numb = randint(-9,10)
2023-07-12 21:54:24 +10:00
dick_plus = (
'<b>вырос</b>',
'<b>подрос</b>',
'<b>привстал</b>',
'<b>увеличился</b>',
'<b>преисполнился</b>'
)
dick_minus = (
'<b>неудачно потусил на сходке</b>',
'<b>уменьшился</b>',
'<b>откусила злая гадюка</b>',
2023-07-16 02:00:21 +10:00
'<b>продали евреи, он стал дешевле</b>',
'<b>схуднул</b>'
)
dick_stayed = (
'<b>продвинулся</b>',
'<b>наноуменьшился</b>',
'<b>зафиксировал прибыль</b>'
2023-07-12 21:54:24 +10:00
)
2022-12-05 17:22:23 +10:00
if numb > 0:
2023-07-12 21:54:24 +10:00
size_change = random.choice(dick_plus) + '🚀'
2023-07-16 02:00:21 +10:00
elif numb == 0:
size_change = random.choice(dick_stayed) + '🤨'
2023-07-12 21:54:24 +10:00
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-07-12 21:54:24 +10:00
#### Чекнуть есть ли юзер в базе
2023-07-12 21:58:19 +10:00
candidate_cursor = dicks_collection.find(
{
'user_id': message.from_user.id,
'chat_id': message.chat.id
},
skip=0, limit=1488)
2023-07-13 01:16:26 +10:00
2023-07-12 21:54:24 +10:00
if candidate_cursor.count() > 0:
## Если есть то нарастить и отправить сообщение
2023-07-12 21:58:19 +10:00
user = candidate_cursor.pop()
2023-07-16 02:00:21 +10:00
2023-07-12 21:54:24 +10:00
2023-07-16 01:50:12 +10:00
if pipisa_time.rolltime(check_datetime=user['datetimes']):
2023-07-12 22:33:36 +10:00
# пришло время крутить!!
2023-07-12 21:54:24 +10:00
updetedDick = user["dick_size"] + numb
2022-12-07 21:12:21 +10:00
try:
2023-07-12 22:40:45 +10:00
dt = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
2023-07-12 21:54:24 +10:00
metadata = dicks_collection.insert(
{
2023-07-13 01:16:26 +10:00
'_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру
2023-07-13 01:00:50 +10:00
'user_id': user['user_id'],
'user_fullname': message.from_user.full_name,
2023-07-12 21:54:24 +10:00
'dick_size': updetedDick,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
2023-07-12 22:40:45 +10:00
'attempts': user['attempts'] + 1,
2023-07-12 21:54:24 +10:00
'chat_id': message.chat.id
},
overwrite_mode='update'
)
print(f'Успешно апдейтнули пипису @{message.from_user.username}')
except Exception as e2:
print(f'ошибка в обновлении пиписы @{message.from_user.username}')
print(e2)
randomword = ForReadDict.RandomDick()
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш <em>{randomword}</em> {size_change}\
2023-07-13 00:05:06 +10:00
на <b>{abs(numb)}</b> см!\n\
Теперь он равен <b>{updetedDick}</b> см! ')
2022-12-07 21:12:21 +10:00
else:
2023-07-12 21:54:24 +10:00
await bot.send_message(message.chat.id, f'@{message.from_user.username},🚫 вы уже крутили пипису, ее размер <b>{user["dick_size"]}</b> см! ')
2023-07-12 22:40:45 +10:00
try:
metadata = dicks_collection.insert(
{
2023-07-13 01:16:26 +10:00
'_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру
2023-07-13 01:00:50 +10:00
'user_id': user['user_id'] ,
'user_fullname': message.from_user.full_name,
'dick_size': user['dick_size'] ,
2023-07-12 22:40:45 +10:00
'datetimes': user['datetimes'] ,
'attempts': user['attempts'] + 1,
2023-07-13 00:01:25 +10:00
'chat_id': message.chat.id
2023-07-12 22:40:45 +10:00
},
overwrite_mode='update'
)
print(f'Успешно апдейтнули попытку крутить пипису @{message.from_user.username}')
except Exception as e2:
print(f'ошибка в обновлении попытки крутить пипису @{message.from_user.username}')
print(e2)
2023-07-12 21:54:24 +10:00
print(f'пользователь @{message.from_user.username} уже крутил')
else:
## если нету, то создать
try:
novenkiy = {
'user_id': message.from_user.id,
'user_fullname': message.from_user.full_name,
'dick_size': numb,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
2023-07-12 22:40:45 +10:00
'attempts': 1,
2023-07-12 21:54:24 +10:00
'chat_id': message.chat.id
}
2023-07-16 02:00:21 +10:00
2023-07-13 00:03:16 +10:00
metadata = dicks_collection.insert(novenkiy, overwrite_mode='update')
2023-07-12 21:54:24 +10:00
if numb > 0:
await bot.send_message(message.chat.id, f'@{message.from_user.username}, ваш писюн показал головку 🚀\n\
на <b>{abs(numb)}</b> см!\n\
2023-07-12 21:54:24 +10:00
Теперь он равен <b>{numb}</b> см!')
else:
await bot.send_message(message.chat.id, f'@{message.from_user.username}, добро пожаловать в игру!🚀\n\
2023-07-12 22:07:03 +10:00
Ты стартуешь не с лучшей позиции, природа наградила тебя всего <b>{numb}</b> см 😬')
2022-12-07 21:12:21 +10:00
2023-07-12 21:54:24 +10:00
print(f'Успешно добавлен пользователь @{message.from_user.username}')
except Exception as e1:
print('ошибка в добавлении нового пользователя')
print(e1)
2022-12-05 17:22:23 +10:00
2022-12-07 21:12:21 +10:00
2023-07-12 21:54:24 +10:00
except Exception as e:
print('ошибка DB в /dick')
print(e)
2022-12-05 17:22:23 +10:00
@dp.message_handler(commands=["topdick"])
async def send_topchat(message: types.Message):
2023-07-12 21:54:24 +10:00
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
dicks_collection = pipisa_db.collection('dicks')
2022-12-07 21:12:21 +10:00
try:
2023-07-12 21:54:24 +10:00
dicks = dicks_collection.find({'chat_id': message.chat.id}, skip=0, limit=1100)
dicks = [d for d in dicks]
except Exception as e:
print('ошибка DB в /topdick')
print(e)
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
dick_limit = min(len(top_dicks), 10)
top_dicks = top_dicks[:dick_limit]
dickos = ''
emo = ['🏆','🚀','🍆','🍌','🐍','🐎','🌭','🌶','👌','💩']
if len(top_dicks) == 0:
await bot.send_message(message.chat.id, '🍆 Никто ничего не нарастил! 🍌')
else:
for i in range(len(top_dicks)):
dickos += f' {emo[i]} {i+1}. {top_dicks[i]["user_fullname"]}: {top_dicks[i]["dick_size"]}см\n'
i += 1
2022-12-05 17:22:23 +10:00
2023-07-12 21:54:24 +10:00
await bot.send_message(message.chat.id, '🏆Топ 10 бубылд чата🏆\n\n' + dickos)
2022-12-05 17:22:23 +10:00
@dp.message_handler(commands=["globaldick"])
async def send_global_top(message: types.Message):
2023-07-12 21:54:24 +10:00
arango_client = ArangoClient(hosts='https://arango.vdk2ch.ru')
pipisa_db = arango_client.db('pipisa', username='root', password='stolendick527')
dicks_collection = pipisa_db.collection('dicks')
2022-12-07 21:12:21 +10:00
try:
2023-07-12 21:54:24 +10:00
dicks = dicks_collection.all( )
dicks = [d for d in dicks]
except Exception as e:
print('ошибка DB в /glovaldick')
print(e)
top_dicks = sorted(dicks, key=lambda dick: dick['dick_size'], reverse=True)
dick_limit = min(len(top_dicks), 10)
top_dicks = top_dicks[:dick_limit]
dickos = ''
emo = ['🏆','🚀','💫','🍆','🍌','🐍','🐎','🌭','🌶','👌']
if len(top_dicks) == 0:
await bot.send_message(message.chat.id, '🍆 Никто ничего не нарастил! 🍌')
else:
for i in range(len(top_dicks)):
dickos += f' {emo[i]} {i+1}. {top_dicks[i]["user_fullname"]}: {top_dicks[i]["dick_size"]}см\n'
i += 1
await bot.send_message(message.chat.id, '🏆Топ 10 пипис в мире🏆\n\n' + dickos)
2022-12-05 17:22:23 +10:00