diff --git a/shop.py b/shop.py new file mode 100644 index 0000000..620866e --- /dev/null +++ b/shop.py @@ -0,0 +1,119 @@ +import os +from config import dp, db, bot, supp_group_id, oper_group_id, notification_group_id, use_chats +from aiogram import types +from aiogram.dispatcher import FSMContext +from functions import get_categories_user, get_subcategories_user, send_good +from markups import menu_mkp, promo_mkp +from states import NewBuy +from personnel import * + +@dp.callback_query_handler(text='shop') +@dp.callback_query_handler(text='toshop') +async def toshopcall(call: types.CallbackQuery): + if db.check_ban(call.from_user.id): + await call.message.delete() + await call.message.answer('Выберите категорию:', reply_markup=get_categories_user()) + +@dp.callback_query_handler(text_contains='usercat_') +async def usercatcall(call: types.CallbackQuery): + if db.check_ban(call.from_user.id): + catid = call.data.split('_')[1] + await call.message.delete() + await call.message.answer('Выберите подкатегорию:', reply_markup=get_subcategories_user(int(catid))) + +@dp.callback_query_handler(text_contains='usersubcat_', state=NewBuy.Paying) +@dp.callback_query_handler(text_contains='usersubcat_', state=NewBuy.Promo) +@dp.callback_query_handler(text_contains='usersubcat_') +async def usersubcatcall(call: types.CallbackQuery, state: FSMContext): + if db.check_ban(call.from_user.id): + try: + await state.finish() + except: + pass + subcatid = call.data.split('_')[1] + if len(db.check_goods(int(subcatid))) == 0: + await call.answer('К сожалению тут пусто', show_alert=True) + else: + await call.message.delete() + await send_good(0, int(subcatid), call.from_user.id) + +@dp.callback_query_handler(text_contains='catback_') +async def catbackcall(call: types.CallbackQuery): + if db.check_ban(call.from_user.id): + await call.message.delete() + subcatid = call.data.split('_')[1] + step = call.data.split('_')[2] + await send_good(int(step), int(subcatid), call.from_user.id) + +@dp.callback_query_handler(text_contains='catnext_') +async def catnextcall(call: types.CallbackQuery): + if db.check_ban(call.from_user.id): + await call.message.delete() + subcatid = call.data.split('_')[1] + step = call.data.split('_')[2] + await send_good(int(step), int(subcatid), call.from_user.id) + +@dp.callback_query_handler(text_contains='buyGood_') +async def buyGood(call: types.CallbackQuery, state: FSMContext): + if db.check_ban(call.from_user.id): + await call.message.delete() + goodId = call.data.split('_')[1] + subCatId = call.data.split('_')[2] + goodInfo = db.get_goodinfo(goodId) + await NewBuy.Promo.set() + async with state.proxy() as data: + data['GoodId'] = {"goodId": goodId, "subCatId": subCatId} + await call.message.answer(f'⌛ Покупка {goodInfo[0]}\nЦена: {goodInfo[2]}₽ \n\nВведите промокод (если есть) :', reply_markup=promo_mkp(subCatId)) + +@dp.message_handler(state=NewBuy.Promo) +async def newBuyPromo(message: types.Message, state: FSMContext): + promocode = message.text + promoInfo = db.get_promo_info(promocode) + async with state.proxy() as data: + goodId = data['GoodId']["goodId"] + subCatId = data['GoodId']["subCatId"] + + if promoInfo != None: + async with state.proxy() as data: + data['Promo'] = promocode + + promoPercent = promoInfo[1] + goodInfo = db.get_goodinfo(goodId) + mkp = types.InlineKeyboardMarkup() + btn1 = types.InlineKeyboardButton('✅ Оформить заказ', callback_data='buyOrder') + btn2 = types.InlineKeyboardButton('❌ Отменить покупку', callback_data=f'usersubcat_{subCatId}') + mkp.add(btn1).add(btn2) + newPrice = float(goodInfo[2]) * ((100 - int(promoPercent))/100) + await message.answer(f'📦 Применен промокод {promocode}\nЗаказ:\n\nТовар: {goodInfo[0]}\nЦена: {goodInfo[2]}₽ \nС учетом скидок: {newPrice}₽\n\nХотите оформить заказ?', reply_markup=mkp) + await NewBuy.next() + + else: + await message.answer(f'⏳ Промокод {promocode} введен неверно или он не существует! Введите промокод повторно (если есть :', reply_markup=promo_mkp(subCatId)) + +@dp.callback_query_handler(text='buyOrder', state=NewBuy.Paying) +@dp.callback_query_handler(text='skipPromo', state=NewBuy.Promo) +async def buyOrder(call: types.CallbackQuery, state: FSMContext): + if db.check_ban(call.from_user.id): + async with state.proxy() as data: + goodId = data['GoodId']["goodId"] + subCatId = data['GoodId']["subCatId"] + goodInfo = db.get_goodinfo(goodId) + if call.data == "buyOrder": + promocode = data['Promo'] + promoInfo = db.get_promo_info(promocode) + promoPercent = promoInfo[1] + newPrice = float(goodInfo[2]) * ((100 - int(promoPercent))/100) + else: + promocode = None + newPrice = float(goodInfo[2]) + await call.message.delete() + orderId = db.add_order(call.from_user.id, goodId, promocode, newPrice) + mkp = types.InlineKeyboardMarkup(row_width=4) + userId = call.from_user.id + client = db.get_usernamerev(int(userId)) + if use_chats == True: + await bot.send_message(oper_group_id, f"💡 Новый заказ! \n\nПользователь {client}\nНомер заказа: {orderId} \nТовар: {goodInfo[0]} \nЦена: {goodInfo[2]}₽ \nС учетом скидок: {newPrice}₽") + else: + await bot.send_message(operators, f"💡 Новый заказ! \n\nПользователь:{client}\nНомер заказа: {orderId} \nТовар: {goodInfo[0]}\nЦена: {goodInfo[2]}₽ \nС учетом скидок: {newPrice}₽") + await call.message.answer(f"Спасибо {client} за обращение! \n\nЗаказ передан операторам, ожидайте дальнейших инструкций, во избежание мошенничества, спросите у оператора номер вашего заказа.\n\nНомер заказа: {orderId} \nТовар: {goodInfo[0]} \nЦена: {goodInfo[2]}₽ \nС учетом скидок: {newPrice}₽") + await state.finish() diff --git a/start.py b/start.py new file mode 100644 index 0000000..0e77c55 --- /dev/null +++ b/start.py @@ -0,0 +1,51 @@ +from config import dp, db, shop_desc +from aiogram import types +from captcha import Captcha +from markups import rules_mkp, menu_mkp +from functions import anti_flood + +@dp.message_handler(commands='start') +@dp.throttled(anti_flood,rate=1) +async def startcmd(message: types.Message): + stat = db.check_userstat(message.from_user.id) + db.add_user(message.from_user.id, message.from_user.mention) + if stat == 'rules': + await message.answer(f'Правила использования бота:\n\n{db.get_rules()}', reply_markup=rules_mkp()) + elif stat == 'ban': + await message.answer('Вы заблокированы') + elif stat == 'ok': + await message.answer(shop_desc, reply_markup=menu_mkp()) + else: + captcha = Captcha() + captcha.register_handlers(dp) + await message.answer( + captcha.get_caption(), + reply_markup=captcha.get_captcha_keyboard() + ) + +@dp.message_handler(commands='id') +@dp.throttled(anti_flood,rate=1) +async def idcmd(message: types.Message): + await message.answer(f'Ваш ID: {message.from_user.id}') + +@dp.message_handler(commands=['chat_id']) +async def chatidcmd(message: types.Message): + await message.answer(f'Чат ID: {message.chat.id}') + +@dp.callback_query_handler(text='rulesok') +async def rulesokcall(call: types.CallbackQuery): + await call.message.delete() + db.change_status(call.from_user.id, 'ok') + await call.message.answer(shop_desc, reply_markup=menu_mkp()) + +@dp.callback_query_handler(text='rulesno') +async def rulesnocall(call: types.CallbackQuery): + db.change_status(call.from_user.id, 'ban') + await call.message.delete() + await call.message.answer('Вы заблокированы') + + +@dp.callback_query_handler(text='menu') +async def menuCall(call: types.CallbackQuery): + await call.message.delete() + await call.message.answer(shop_desc, reply_markup=menu_mkp()) diff --git a/states.py b/states.py new file mode 100644 index 0000000..319c8b5 --- /dev/null +++ b/states.py @@ -0,0 +1,110 @@ +from aiogram.dispatcher.filters.state import State, StatesGroup + + +class NewBuy(StatesGroup): + GoogId = State() + Promo = State() + Paying = State() + +class SuppUser(StatesGroup): + UserId = State() + +class AddPromo(StatesGroup): + Promo = State() + +class SuppAdmin(StatesGroup): + UserId = State() + QuestId = State() + Text = State() + +class NewFaq(StatesGroup): + Name = State() + Text = State() + Photo = State() + +class FaqName(StatesGroup): + FaqId = State() + Name = State() + +class FaqText(StatesGroup): + FaqId = State() + Text = State() + +class AddCatRus(StatesGroup): + CatName = State() + +class ChangeNamecatRus(StatesGroup): + CatId = State() + CatName = State() + +class AddSubcatRus(StatesGroup): + CatId = State() + SubcatName = State() + +class ChangeNamesubcatRus(StatesGroup): + SubcatId = State() + SubcatName = State() + +class AddGood(StatesGroup): + SubcatId = State() + CatId = State() + Name = State() + Description = State() + Photo = State() + Price = State() + +class AddInstance(StatesGroup): + GoodId = State() + FileName = State() + +class ChangeNameGoodRus(StatesGroup): + GoodId = State() + GoodName = State() + +class ChangeDescGoodRus(StatesGroup): + GoodId = State() + GoodDesc = State() + +class ChangePriceGood(StatesGroup): + GoodId = State() + +class NewOrder(StatesGroup): + Delivery = State() + Adress = State() + Comment = State() + Promo = State() + +class OrderEnd(StatesGroup): + OrderId = State() + +class RassilkaAll(StatesGroup): + Text = State() + +class ChangeToken(StatesGroup): + Paym = State() + Token = State() + +class ChangeStatus(StatesGroup): + UserId = State() + +class ChangeRules(StatesGroup): + Rules = State() + +class ReviewTake(StatesGroup): + OrderId = State() + Stars = State() + Review = State() + +class QuestAddQuest(StatesGroup): + CountMsg = State() + QuestId = State() + +class ChangeReviewPay(StatesGroup): + Pay = State() + +class NewUsername(StatesGroup): + Username = State() + +class ChageNicknameAdm(StatesGroup): + UserId = State() + Nickname = State() \ No newline at end of file diff --git a/support.py b/support.py new file mode 100644 index 0000000..1dec821 --- /dev/null +++ b/support.py @@ -0,0 +1,47 @@ +from config import db, dp, oper_group_id, supp_group_id, use_chats, bot +from aiogram import types +from aiogram.dispatcher import FSMContext +from aiogram.types import ParseMode, Message +from essentials import * +from personnel import * + +call_oper = False +call_supp = False + +@dp.callback_query_handler(text='askpers') +async def permsg(call: types.CallbackQuery): + await call.message.answer('☎ Связь с персоналом.') + mkp = types.InlineKeyboardMarkup() + btn1 = types.InlineKeyboardButton('Написать оператору', call_oper = True) + btn2 = types.InlineKeyboardButton('Написать в поддержку', call_supp = True) + btn2 = types.InlineKeyboardButton('В меню', callback_data='menu') + mkp.add(btn1, btn2, btn3).add(btn3) + return mkp + +if call_oper == True: + + @dp.message_handler() + async def opermsg(message): + await bot.send_message(f'Вызван оператор, ожидайте.') + call_oper = False + if use_chats == True: + await bot.send_message(oper_group_id, f'Запрос оператора для: {client}') + await bot.forward_message(oper_group_id, message.chat.id, message.message_id) + else: + await bot.send_message(operators, f'Запрос оператора для: {client}') + await bot.forward_message(operators, message.chat.id, message.message_id) + await state.finish() + +if call_supp == True: + + @dp.message_handler() + async def suppmsg(message): + await bot.send_message(f'Ваш тикет передан, ожидайте.') + call_supp = False + if use_chats == True: + await bot.send_message(supp_group_id, f'Запрос оператора для: {client}') + await bot.forward_message(supp_group_id, message.chat.id, message.message_id) + else: + await bot.send_message(supporters, f'Запрос оператора для: {client}') + await bot.forward_message(supporters, message.chat.id, message.message_id) + await state.finish() diff --git a/usermenu.py b/usermenu.py new file mode 100644 index 0000000..ae00f2d --- /dev/null +++ b/usermenu.py @@ -0,0 +1,15 @@ +import os +from config import dp, bot, db +from aiogram import types + +from markups import menu_back_mkp + +@dp.callback_query_handler(text='myPurchs') +async def myPurchases (call: types.CallbackQuery): + await call.message.delete_reply_markup() + db.remove_old_orders() + user_info = db.get_user_info(call.from_user.id) + pay_count = user_info[1] + if pay_count == None: + pay_count = 0 + await call.message.answer(f'Ваш ID: {call.from_user.id} \n\nНа данный момент это всё что тут есть. TODO: Возможность добавить данные для доставки.', reply_markup=menu_back_mkp())