меньше кода - лучше!
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Simple_Not 2024-01-23 13:29:31 +10:00
parent 9d6d8791fd
commit 14c238ec2f
2 changed files with 12 additions and 15 deletions

View File

@ -4,7 +4,7 @@ from db_logic import collections
import datetime import datetime
def store_new_user(dicks_collection, message, result ): def store_new_user(message, result ):
try: try:
novenkiy = { novenkiy = {
@ -15,7 +15,7 @@ def store_new_user(dicks_collection, message, result ):
'attempts': 1, 'attempts': 1,
'chat_id': message.chat.id 'chat_id': message.chat.id
} }
metadata = dicks_collection.insert(novenkiy, overwrite_mode='update') metadata = collections.get_dicks_collection().insert(novenkiy, overwrite_mode='update')
print(f'Успешно добавлен нового пользователь @{message.from_user.username}') print(f'Успешно добавлен нового пользователь @{message.from_user.username}')
except Exception as e2: except Exception as e2:
@ -23,9 +23,9 @@ def store_new_user(dicks_collection, message, result ):
print(e2) print(e2)
def update_attempts(dicks_collection, message, user ): def update_attempts(message, user ):
try: try:
metadata = dicks_collection.insert( metadata = collections.get_dicks_collection().insert(
{ {
'_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру '_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру
'user_id': user['user_id'] , 'user_id': user['user_id'] ,
@ -43,10 +43,10 @@ def update_attempts(dicks_collection, message, user ):
print(e2) print(e2)
def update_dick_size(dicks_collection, message, user, updatedDick ): def update_dick_size(message, user, updatedDick ):
try: try:
metadata = dicks_collection.insert( metadata = collections.get_dicks_collection().insert(
{ {
'_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру '_key': user['_key'], ### этот нужен чтобы апдейт прилетал тому же юзеру
'user_id': user['user_id'], 'user_id': user['user_id'],
@ -64,10 +64,10 @@ def update_dick_size(dicks_collection, message, user, updatedDick ):
print(e2) print(e2)
def get_user(dicks_collection, message): def get_user(message):
try: try:
#### Чекнуть есть ли юзер в базе #### Чекнуть есть ли юзер в базе
candidate_cursor = dicks_collection.find( candidate_cursor = collections.get_dicks_collection().find(
{ {
'user_id': message.from_user.id, 'user_id': message.from_user.id,
'chat_id': message.chat.id 'chat_id': message.chat.id

View File

@ -20,16 +20,13 @@ async def up_dick(message: types.Message):
if message.from_user.id in admins or message.chat.type != 'private': if message.from_user.id in admins or message.chat.type != 'private':
dicks_collection = collections.get_dicks_collection()
#### TODO уплатить нолог с 100 см для самого нищего #### TODO уплатить нолог с 100 см для самого нищего
# рандомайзер # рандомайзер
result = randint(-9,10) result = randint(-9,10)
#### Чекнуть есть ли юзер в базе #### Чекнуть есть ли юзер в базе
user = user_stuff.get_user(dicks_collection, message) user = user_stuff.get_user(message)
if user: if user:
## Если есть то нарастить и отправить сообщение ## Если есть то нарастить и отправить сообщение
@ -38,7 +35,7 @@ async def up_dick(message: types.Message):
# пришло время крутить!! # пришло время крутить!!
updatedDick = user["dick_size"] + result updatedDick = user["dick_size"] + result
user_stuff.update_dick_size(dicks_collection, message, user, updatedDick) user_stuff.update_dick_size(message, user, updatedDick)
randomdickword = ForReadDict.RandomDick() randomdickword = ForReadDict.RandomDick()
change_phrase = WordsChange.ChangeWord(result) change_phrase = WordsChange.ChangeWord(result)
@ -50,10 +47,10 @@ async def up_dick(message: types.Message):
await bot.send_message( message.chat.id, await bot.send_message( message.chat.id,
f'@{message.from_user.username}, 🚫 вы уже крутили пипису, её размер <b>{user["dick_size"]}</b> см! ' f'@{message.from_user.username}, 🚫 вы уже крутили пипису, её размер <b>{user["dick_size"]}</b> см! '
) )
user_stuff.update_attempts(dicks_collection, message, user) user_stuff.update_attempts( message, user)
else: else:
## если нету, то создать ## если нету, то создать
user_stuff.store_new_user(dicks_collection, message, result) user_stuff.store_new_user(message, result)
if result > 0: if result > 0:
await bot.send_message( message.chat.id, await bot.send_message( message.chat.id,