From 1f4e9ba5421438905c914e97d65a80c9c37da2d4 Mon Sep 17 00:00:00 2001 From: goldenkernel <124398859+adoubt@users.noreply.github.com> Date: Sun, 5 May 2024 11:48:58 +0000 Subject: [PATCH] file \ product manager Fixes #3 --- src/databases/carts.db | Bin 8192 -> 8192 bytes src/databases/licenses.db | Bin 12288 -> 12288 bytes src/databases/products.db | Bin 12288 -> 12288 bytes src/databases/users.db | Bin 8192 -> 8192 bytes .../__pycache__/user_handler.cpython-310.pyc | Bin 9482 -> 11407 bytes src/handlers/user_handler.py | 113 +++++++++++++----- .../user_keyboards.cpython-310.pyc | Bin 4140 -> 4321 bytes src/keyboards/user_keyboards.py | 35 ++++-- src/logs/logs.log | 3 + 9 files changed, 107 insertions(+), 44 deletions(-) diff --git a/src/databases/carts.db b/src/databases/carts.db index 6052b0bac405081b3ac90083c0c7410437ee620a..ab52e16acb779a671c2f020a61e14e157c00e249 100644 GIT binary patch delta 43 zcmZp0XmFSy%_uxk#+gxgW5N=CHb(w$4E*0V3ktm8pBTWx#WH=-JonIAU+29wbrFSFAgED-?;|9lrL delta 51 zcmZojXh@hK&B!}Z#+i|KW5N=CK32ZV4E*Q$r}KyMi|}3EEU0jhkI9~O@(Njp&7$(J H1Q=NXgT@Y& diff --git a/src/databases/products.db b/src/databases/products.db index bb38bc15cb2b3e31fc3a241775de8c7e27ac4c4e..04dc824a60e39d16e89da7a3c14e0c1fe438487a 100644 GIT binary patch delta 304 zcmZojXh@hKEhxaiz`zW|Fu*xc$Cy!IW5P0i78VA6md%0!zxe7KD;dQYSY*W?0I|n*CJEn&^I#y&mIXZeehZ;p1C;L14XM2X1yP5d} z8f9g>8wW-t73Fz5J39JQxs*FP=T-zbg@u{97W;aJCTF{p`UM7J7*kK4IZkNK2@3}~ zCnT^W(8n+>F{3cuti;R1BHuMVK-UB4TwNES`dr`40-(BzQcIVdf_&W!pmTT`HZv*w G;|Bl@=T-0k delta 152 zcmZojXh@hKEy%;bz`zW|Fu*=h$C#04W5P0im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hCfctlm0^*guBt+OWm?P@*se+5dGX~>zyh1jKaG9@dzeM_Zt8a=-@sE6Q@;T2h zY#`TiE`cFE>k__4Tka)XL$h%SFA6K|f+jBEI_4s{nF}}7Cwd`i-E4aD|1$C;3Q->R zuWrYTFx-45BLqh?TrFySEg@Jnni&!@lUK^)MK$FZpYQ-+QoO_qDRGfd5>2_oDiAu|(xUY2KWYQ|7pd1ykmEIRz~!F0m@A%*(UNiYcXng%n7uMq8S< zq@-~(RZ}KtIi@GdtYyWTvY^7MLd{#v%Vq;s}lAkUKSFFP{fvJ@jRK-TDs)snBJ*eX6lXnw#3sdah zOtED$IgBg3_OLn5L;OGRV-&Q%a+UCwKu51gFg|UAP@STCC1IkOSO+qj5%wY6Lckq> z>l}`^I-Ou9`4@ree3aj;Cch|&zNxMt zJ^Z)oO5)^sp+d66wa^2ZE$|nia<^}5b?7zA{I5{26ZfeRb`*6Mc%QbjtQc2J7%FSWp g)wPw44u_Zo1gc&z%OtQtF~MBf@VKmA;!=F%KfixsRR910 diff --git a/src/handlers/user_handler.py b/src/handlers/user_handler.py index ffc88021..3310606b 100644 --- a/src/handlers/user_handler.py +++ b/src/handlers/user_handler.py @@ -77,40 +77,21 @@ async def start_handler(message: Message, is_clb=False, product_id:int| None=Non # else: # await message.answer_photo(photo =start_photo,caption=text,parse_mode="HTML" ) -@router.message(F.audio) -#proverka etogo bita v magaze -@new_user_handler -@new_seller_handler -async def new_product(msg: Message, is_clb=False, **kwargs): - user_id = msg.from_user.id - performer = msg.audio.performer - title = msg.audio.title - name = msg.audio.file_name - file_id = msg.audio.file_id - - await msg.answer(text = 'Poehali', parse_mode="HTML") - #proverka etogo bita v magaze - await ProductsDatabase.create_table() - await ProductsDatabase.create_product(user_id = user_id,name = name,mp3_link=file_id) - - logger.success(f"New product {name} by {user_id}") -@router.message(Command("homepage")) + +@router.message(F.text == "🏠 Home") @new_user_handler async def homepage_handler(message: Message, is_clb=False, **kwargs): - # if is_clb: - # # await bot.delete_message(chat_id=message.chat.id,message_id=message.message_id) - # else: - # await message.delete() + user_id = message.from_user.id await CartsDatabase.create_table() cart_count = await CartsDatabase.get_cart_count(user_id) await message.answer(text = f'Лучший маркетплейс музыки.\n Подписывайтесь на наш канал (линк).',reply_markup = user_keyboards.get_homepage_kb(user_id,cart_count)) -@router.message(Command("settings")) +@router.message(F.text == "⚙️ Settings") @new_user_handler async def settings_handler(message: Message, is_clb=False, **kwargs): # if is_clb: @@ -119,7 +100,7 @@ async def settings_handler(message: Message, is_clb=False, **kwargs): # await message.delete() user_id = message.from_user.id - await message.edit_text(text = f'Settings',reply_markup = user_keyboards.get_settings_kb()) + await message.answer(text = f'Settings',reply_markup = user_keyboards.get_settings_kb()) @router.callback_query(lambda clb: clb.data == 'start') @new_user_handler @@ -183,7 +164,7 @@ async def addToCart_clb_handler(clb: CallbackQuery, is_clb=False, **kwargs): channel = await UsersDatabase.get_value(seller,'channel') await clb.message.edit_caption(caption = 'Added To Cart ✔', reply_markup = user_keyboards.get_showcase_kb(product_id=product_id,is_sold=is_sold,channel=channel,already_in_cart=1)) -@router.message(Command("Cart")) +@router.message(F.text.startswith("🛒 Cart")) @new_user_handler async def cart_handler(message: Message, is_clb=False, **kwargs): if is_clb: @@ -230,7 +211,7 @@ async def delItemFromCart_clb_handler(clb: CallbackQuery, is_clb=False, **kwargs await clb.message.edit_caption(text = "Your Cart is Empty", reply_markup= user_keyboards.get_homepage_kb(user_id,0)) -@router.message(Command("Mybeats")) +@router.message(F.text == "📼 My beats") @new_user_handler async def mybeats_handler(message: Message, is_clb=False,current_page:int|None = 0,**kwargs): if is_clb: @@ -240,6 +221,9 @@ async def mybeats_handler(message: Message, is_clb=False,current_page:int|None = # await message.delete() user_id = message.from_user.id total_beats = await ProductsDatabase.get_count_by_user(user_id) + if total_beats == 0: + await message.answer('Nothing uploaded yet, go to ➕ New Beat') + return total_pages = (total_beats //10) + 1 if current_page >= total_pages: current_page = total_pages @@ -247,7 +231,7 @@ async def mybeats_handler(message: Message, is_clb=False,current_page:int|None = current_page = 0 beats = await ProductsDatabase.get_all_by_user(user_id, current_page*10) - await message.edit_text(text=f'My Beats ({total_beats}):', reply_markup=user_keyboards.get_my_beats_kb(beats, current_page,total_pages)) + await message.answer(text=f'My Beats ({total_beats}):', reply_markup=user_keyboards.get_my_beats_kb(beats, current_page,total_pages)) @router.callback_query(lambda clb: clb.data.startswith('mybeats')) @new_user_handler @@ -259,11 +243,76 @@ async def mybeats_clb_handler(clb: CallbackQuery, is_clb=False, **kwargs): @router.callback_query(lambda clb: clb.data == 'current_page') async def current_page_handler(clb: CallbackQuery, is_clb=False, **kwargs): await clb.answer() - -@router.message(Command("Newbeat")) + +class NewBeatState(StatesGroup): + mp3_ask = State() + wav_ask = State() + stems_ask = State() + preview_ask = State() + +@router.message(F.text =="➕ New Beat") @new_user_handler -async def newbeat_handler(message: Message, is_clb=False,**kwargs): - pass +async def newbeat_handler(message: Message,state: FSMContext, is_clb=False,**kwargs): + await state.set_state(NewBeatState.mp3_ask) + await message.answer(text= f'MP3 File\nUpload or forward .MP3') + +@router.message(NewBeatState.mp3_ask) +async def mp3_ask_callback_handler(message: types.Message, state: FSMContext, **kwargs): + user_id = message.from_user.id + performer = message.audio.performer + title = message.audio.title + name = message.audio.file_name + mp3_link = message.audio.file_id + + #proverka etogo bita v magaze + + + await state.set_state(NewBeatState.wav_ask) + await state.set_data([user_id,performer,title,name,mp3_link]) + await message.answer(text= f'WAV File\nUpload or forward .WAV') + +@router.message(NewBeatState.wav_ask) +async def wav_ask_callback_handler(message: types.Message, state: FSMContext, **kwargs): + + data = await state.get_data() + user_id = data[0] + performer = data[1] + title = data[2] + name = data[3] + mp3_link = data[4] + wav_link = message.document.file_id + + await state.set_state(NewBeatState.stems_ask) + await state.set_data([user_id,performer,title,name,mp3_link,wav_link]) + await message.answer(text= f'Stems Archive\nUpload or forward .ZIP',reply_markup = user_keyboards.get_newbeat_kb()) + +@router.callback_query(lambda clb: clb.data == 'skip_stems') +async def current_page_handler(clb: CallbackQuery, state : FSMContext, is_clb=False, **kwargs): + await state.set_state(NewBeatState.stems_ask) + await stems_ask_callback_handler(message = clb.message,state= state, is_skip=True,is_clb=True) + await clb.answer() +@router.message(NewBeatState.stems_ask) +async def stems_ask_callback_handler(message: types.Message, state: FSMContext,is_clb=False, is_skip= False,**kwargs): + + data = await state.get_data() + user_id = data[0] + performer = data[1] + title = data[2] + name = data[3] + mp3_link = data[4] + wav_link = data[5] + await state.clear() + await ProductsDatabase.create_table() + if is_skip: + await ProductsDatabase.create_product(user_id = user_id,name = name,mp3_link=mp3_link,wav_link=wav_link, preview_link=mp3_link) + + else: + stems_link = message.document.file_id + await ProductsDatabase.create_product(user_id = user_id,name = name,mp3_link=mp3_link,wav_link=wav_link,stems_link=stems_link, preview_link=mp3_link) + + + logger.success(f"New product {name} by {user_id}") + await message.answer(text= f'Created, go to 📼 My Beats') @router.callback_query(lambda clb: clb.data.startswith('beat')) @@ -282,3 +331,5 @@ async def seller_handler(message: Message, is_clb=False, **kwargs): @router.message(F.text == "🌏 Buy Beats") async def buyer_handler(message: Message, is_clb=False, **kwargs): await start_handler(message) + + diff --git a/src/keyboards/__pycache__/user_keyboards.cpython-310.pyc b/src/keyboards/__pycache__/user_keyboards.cpython-310.pyc index 44728c31a2e6c8d553fcbdd47945697c1d8879e4..189c1daaf2f360232ce5301d16e4001a5566d7cf 100644 GIT binary patch delta 828 zcmYjPO=}ZT6rFqLBa_K|m=a5A8=Gi}jiDf-6&q{;oiu#iE?k1__JdcW+A^{MHuzFo@)!n4QJS5j=u9^nVi}5(OkY&;=l6b<4BQ1V zW%P?$EDK}%Td^F#`2Hue0Pt6QkNYqo3f2c>f~xTw;+wSvMKNWi#Cqb(&@Gy*f)vty zR2mKXJdtM&W*R2a7OXf-N7;nR>Y zJyh63oP$WwoVaOUCDpn3-82X~+4$R=TP?AX(EGt1P5;vXLw(9(zxV!V8^+QCN9%siON-!88Hcs2Cu8{J;G)eg6M+dBdflNv`ev`me>^AB+el>Gnz diff --git a/src/keyboards/user_keyboards.py b/src/keyboards/user_keyboards.py index 50267a3f..f4d3f2fb 100644 --- a/src/keyboards/user_keyboards.py +++ b/src/keyboards/user_keyboards.py @@ -102,24 +102,33 @@ def get_main_buyer_kb(cart) -> ReplyKeyboardMarkup: cart_view = 'Cart' if cart > 0:cart_view = f'Cart({cart})' rkb = ReplyKeyboardMarkup(keyboard=[ - [KeyboardButton(text='🏠 Home',callback_data='homepage')], - [KeyboardButton(text=f'🛒 {cart_view}', callback_data='cart')], - [KeyboardButton(text='🛍 Purchases', callback_data='purchases')], - [KeyboardButton(text='♟ Negotiations', callback_data='negotiation_0')], - [KeyboardButton(text='⚙️ Settings', callback_data='settings')], - [KeyboardButton(text='🌏 Sell Beats', callback_data='seller')]], resize_keyboard=True + [KeyboardButton(text='🏠 Home',callback_data='homepage'), + KeyboardButton(text='⚙️ Settings', callback_data='settings')], + [KeyboardButton(text='🌏 Sell Beats', callback_data='seller')]],resize_keyboard=True ) return rkb +def get_newbeat_kb()-> InlineKeyboardMarkup: + ikb = InlineKeyboardMarkup(inline_keyboard=[ + [InlineKeyboardButton(text=f"Skip", callback_data=f'skip_stems')] + ]) + return ikb def get_main_seller_kb() -> ReplyKeyboardMarkup: rkb = ReplyKeyboardMarkup(keyboard=[ - [KeyboardButton(text='🏠 Home',callback_data='homepage')], - [KeyboardButton(text='📼 My Beats', callback_data='mybeats_0')], - [KeyboardButton(text='♟ Negotiations', callback_data='negotiations_1')], - [KeyboardButton(text='🍞 Sales', callback_data='sales')], - [KeyboardButton(text='📊 Stats', callback_data='stats')], - [KeyboardButton(text='⚙️ Settings', callback_data='settings_1')], - [KeyboardButton(text='🌏 Buy Beats', callback_data='buyer')]], resize_keyboard=True + [KeyboardButton(text='🏠 Home',callback_data='homepage'), + KeyboardButton(text='➕ New Beat')], + [KeyboardButton(text='📼 My Beats', callback_data='mybeats_0'), + KeyboardButton(text='⚙️ Settings', callback_data='settings_1')], + [KeyboardButton(text='🌏 Buy Beats', callback_data='buyer')]],resize_keyboard=True + ) + return rkb + +def get_cart_buyer_kb(total) -> ReplyKeyboardMarkup: + + rkb = ReplyKeyboardMarkup(keyboard=[ + [KeyboardButton(text=f' Pay ${total}'), + KeyboardButton(text='🔙 Back')], + [KeyboardButton(text='🔙 Back', )]],resize_keyboard=True ) return rkb \ No newline at end of file diff --git a/src/logs/logs.log b/src/logs/logs.log index 1e47e590..408374d6 100644 --- a/src/logs/logs.log +++ b/src/logs/logs.log @@ -20,3 +20,6 @@ 2024-04-30T14:58:20.915723+0000 SUCCESS Новый пользователь (ID: 439064730) 2024-04-30T16:42:09.405238+0000 SUCCESS Новый пользователь (ID: 6279510886) 2024-04-30T16:42:30.773938+0000 SUCCESS Новый пользователь (ID: 7167825365) +2024-05-03T17:18:57.599594+0000 SUCCESS Новый пользователь (ID: 439064730) +2024-05-05T10:36:35.022151+0000 SUCCESS New product 1007.mp3 by 6279510886 +2024-05-05T11:43:35.633014+0000 SUCCESS New product 1007.mp3 by 6279510886