python_bot/db_logic/user_stuff.py

86 lines
3.3 KiB
Python
Raw Normal View History

2024-01-23 13:18:51 +10:00
from global_conf import CONFIG
from db_logic import collections
import datetime
2024-01-23 13:29:31 +10:00
def store_new_user(message, result ):
2024-01-23 13:18:51 +10:00
try:
novenkiy = {
'user_id': message.from_user.id,
'user_fullname': message.from_user.full_name,
'dick_size': result,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'attempts': 1,
'chat_id': message.chat.id
}
2024-01-23 13:29:31 +10:00
metadata = collections.get_dicks_collection().insert(novenkiy, overwrite_mode='update')
2024-01-23 13:18:51 +10:00
print(f'Успешно добавлен нового пользователь @{message.from_user.username}')
except Exception as e2:
print(f'ошибка DB в /dick :: добавление нового пользователя @{message.from_user.username}')
print(e2)
2024-01-23 13:29:31 +10:00
def update_attempts(message, user ):
2024-01-23 13:18:51 +10:00
try:
2024-01-23 13:29:31 +10:00
metadata = collections.get_dicks_collection().insert(
2024-01-23 13:18:51 +10:00
{
'_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,
'chat_id': message.chat.id
},
overwrite_mode='update'
)
print(f'Успешно апдейтнули попытку крутить пипису @{message.from_user.username}')
except Exception as e2:
print(f'ошибка DB в /dick :: обновление попытки крутить пипису @{message.from_user.username}')
print(e2)
2024-01-23 13:29:31 +10:00
def update_dick_size(message, user, updatedDick ):
2024-01-23 13:18:51 +10:00
try:
2024-01-23 13:29:31 +10:00
metadata = collections.get_dicks_collection().insert(
2024-01-23 13:18:51 +10:00
{
'_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру
'user_id': user['user_id'],
'user_fullname': message.from_user.full_name,
'dick_size': updatedDick,
'datetimes': datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"),
'attempts': user['attempts'] + 1,
'chat_id': message.chat.id
},
overwrite_mode='update'
)
print(f'Успешно апдейтнули пипису @{message.from_user.username}')
except Exception as e2:
print(f'ошибка DB в /dick :: обновление пиписы @{message.from_user.username}')
print(e2)
2024-01-23 13:29:31 +10:00
def get_user(message):
2024-01-23 13:18:51 +10:00
try:
#### Чекнуть есть ли юзер в базе
2024-01-23 13:29:31 +10:00
candidate_cursor = collections.get_dicks_collection().find(
2024-01-23 13:18:51 +10:00
{
'user_id': message.from_user.id,
'chat_id': message.chat.id
},
skip = 0,
limit = 1488
)
if candidate_cursor.count() > 0:
user = candidate_cursor.pop()
else:
user = None
return user
except Exception as e:
print('ошибка DB в /dick :: поиск юзера')
print(e)