await message.answer( f'Приветcтвую, дрогой админ {message.from_user.full_name}!', reply_markup=admin_keyboard) if not await redis_commands.is_user(message.from_user.id): user = message.from_user await db_commands.add_user( user_id=user.id, username=user.username, full_name=user.full_name, ) await redis_commands.set_new_user(message.from_user.id) @dp.message_handler(CommandStart(), IsUser()) async def user_bot_start(message: types.Message, state: FSMContext): await message.answer( f"Привет, {message.from_user.full_name}, мы тебя помним.\n" f"Ты можешь пользоваться этим магазиом использовав меню снизу⬇️", reply_markup=user_menu_keyboard) @dp.message_handler(CommandStart()) async def default_bot_start(message: types.Message, state: FSMContext): await message.answer( f"Здравствуйте, вы не можете пользоваться магазином," f"так как вы не являетесь нашим пользователем😔\n\n" f"Попросите вашего друга поделиться с вами реферальной ссылкой " f"или введите реферальный код!", reply_markup=enter_code_keyboard)
from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters import Command, CommandStart from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton from aiogram.utils import deep_linking from filters import IsUser from handlers.users.admin.add_item import get_item_text from keyboards.inline import buy_item_keyboard from loader import dp from utils.db_api import db_commands from utils.misc import logging @dp.message_handler(CommandStart(deep_link=re.compile('.+')), IsUser()) async def show_item(message: types.Message, state: FSMContext): item_id = int(deep_linking.decode_payload(message.get_args())) item = await db_commands.get_item(item_id) await state.update_data(item_id=item_id) logging.info(f"Buy {item}") await message.answer_photo( photo=item.photo_id, caption=get_item_text(item.name, item.description, item.price), reply_markup=buy_item_keyboard )
from loader import dp from aiogram.dispatcher import FSMContext from aiogram.types import Message from filters import IsUser from .menu import balance # test card ==> 1111 1111 1111 1026, 12/22, CVC 000 # shopId 506751 # shopArticleId 538350 @dp.message_handler(IsUser(), text=balance) async def process_balance(message: Message, state: FSMContext): await message.answer('Ваш кошелек пуст! Чтобы его пополнить нужно...')
from aiogram.types import Message from loader import dp, db from .menu import delivery_status from filters import IsUser @dp.message_handler(IsUser(), text=delivery_status) async def process_delivery_status(message: Message): orders = await db.fetchall('SELECT * FROM orders WHERE cid=$1', (message.chat.id,)) if len(orders) == 0: await message.answer('У вас нет активных заказов.') else: await delivery_status_answer(message, orders) async def delivery_status_answer(message, orders): res = '' for order in orders: res += f'Заказ <b>№{order[3]}</b>' answer = [ ' лежит на складе.', ' уже в пути!', ' прибыл и ждет вас на почте!' ] res += answer[0] res += '\n\n' await message.answer(res)
import logging from aiogram.dispatcher import FSMContext from aiogram.types import Message, CallbackQuery, ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardMarkup, InlineKeyboardButton from keyboards.inline.products_from_cart import product_markup, product_cb from aiogram.utils.callback_data import CallbackData from keyboards.default.markups import * from aiogram.types.chat import ChatActions from states import CheckoutState from loader import dp, db, bot from filters import IsUser from .menu import cart @dp.message_handler(IsUser(), text=cart) async def process_cart(message: Message, state: FSMContext): cart_data = db.fetchall('SELECT * FROM cart WHERE cid=?', (message.chat.id, )) if len(cart_data) == 0: await message.answer('Ваша корзина пуста.') else: await bot.send_chat_action(message.chat.id, ChatActions.TYPING) async with state.proxy() as data: data['products'] = {} order_cost = 0
from aiogram import types from aiogram.dispatcher import FSMContext from filters import IsUser from keyboards.default.cancel_keyboard import CANCEL_TASK from keyboards.inline import show_items_keyboard from loader import dp @dp.message_handler(IsUser(), text=CANCEL_TASK, state="*") async def cancel_user_task(message: types.Message, state: FSMContext): await state.finish() await message.answer(text="Отменено❌") await message.answer(text="Ищите другие товары в нашем магазине:", reply_markup=show_items_keyboard)
import logging from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.dispatcher.filters import Command import keyboards from filters import IsUser from loader import dp @dp.message_handler(Command("menu"), IsUser(), state="*") async def get_menu(msg: types.Message, state: FSMContext): user = msg.from_user await state.finish() await msg.answer_sticker( "CAACAgIAAxkBAAEIy_FgWTfQPZZmlrwJ_nL3nhYXD-C7gQACBQADwDZPE_lqX5qCa011HgQ", reply_markup=keyboards.default.get_bot_menu()) logging.info(f"Get menu for @{user.username}-{user.id}")
import logging from aiogram.types import Message, CallbackQuery from keyboards.inline.categories import categories_markup, category_cb from keyboards.inline.products_from_catalog import product_markup, product_cb from aiogram.utils.callback_data import CallbackData from aiogram.types.chat import ChatActions from loader import dp, db, bot from .menu import catalog from filters import IsUser @dp.message_handler(IsUser(), text=catalog) async def process_catalog(message: Message): await message.answer('Выберите раздел, чтобы вывести список товаров:', reply_markup=categories_markup()) @dp.callback_query_handler(IsUser(), category_cb.filter(action='view')) async def category_callback_handler(query: CallbackQuery, callback_data: dict): products = db.fetchall( '''SELECT * FROM products product WHERE product.tag = (SELECT title FROM categories WHERE idx=?) AND product.idx NOT IN (SELECT idx FROM cart WHERE cid = ?)''', (callback_data['id'], query.message.chat.id)) await query.answer('Все доступные товары.') await show_products(query.message, products) @dp.callback_query_handler(IsUser(), product_cb.filter(action='add'))
import logging from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.types import Message, MediaGroup import keyboards from data.config import EXAMPLE_IMGS from filters import IsUser from loader import dp from states.adding_set import AddingSet from utils import clean_previous_menu_msg from utils.db_api import redis_commands @dp.message_handler(IsUser(), text="Добавить✨") async def show_adding_info(msg: Message, state: FSMContext): user = types.User.get_current() help_album = get_help_album( caption="Для того чтобы добавить свой набор слов, нужно:\n" "1) cделать скриншоты слов, которы ты хочешь выучить;\n" "2) перейти в Cherrynglish бота;\n" "3) прикрепить все скриншоты слов, которые будут в твоём наборе.", ) await msg.answer_media_group(media=help_album) await msg.answer("Сначала прикрепи скриншоты:", reply_markup=keyboards.default.read_photo_menu) await clean_previous_menu_msg(msg, state) await state.finish() await redis_commands.clean_all_photo_ids(user.id)
from aiogram import types from filters import IsUser from keyboards.default.get_menu_keyboard import SHOW_GOODS from keyboards.inline.show_items_keyboard import show_items_keyboard from loader import dp @dp.message_handler(IsUser(), text=SHOW_GOODS) async def open_menu(message: types.Message): username = (await dp.bot.get_me()).username await message.answer( text="Вы сможете выбирать товары очень быстро. Для этого " f"нужно ввести @{username} в любом чате телеграм и вы сразу " f"сможете очуществлять поиск по товарам нашего магазина.\n\n" f"Попробуйте этот режим нажав на кнопку:", reply_markup=show_items_keyboard)
from loader import dp from filters import IsAdmin, IsUser catalog = '🛍️ Каталог' balance = '💰 Баланс' cart = '🛒 Корзина' delivery_status = '🚚 Статус заказа' settings = '⚙️ Настройка каталога' orders = '🚚 Заказы' questions = '❓ Вопросы' @dp.message_handler(IsAdmin(), commands='menu') async def admin_menu(message: Message): markup = ReplyKeyboardMarkup(selective=True) markup.add(settings) markup.add(questions, orders) await message.answer('Меню', reply_markup=markup) @dp.message_handler(IsUser(), commands='menu') async def user_menu(message: Message): markup = ReplyKeyboardMarkup(selective=True) markup.add(catalog) markup.add(balance, cart) markup.add(delivery_status) await message.answer('Меню', reply_markup=markup)
import logging from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.types import Message, User import keyboards from filters import IsUser from loader import dp from utils import clean_previous_menu_msg from utils.change_bot_menu import change_bot_menu @dp.message_handler(IsUser(), text="Наборы📚") async def show_sets(msg: Message, state: FSMContext): user = User.get_current() await clean_previous_menu_msg(msg, state) await state.finish() await state.update_data(page=1) sets_msg = await msg.answer( "Доступные наборы слов:", reply_markup=await keyboards.inline.get_sets_menu(user.id) ) await state.update_data(sets_msg_id=sets_msg.message_id) await change_bot_menu(state)
from typing import List from aiogram.types import InlineQuery, InlineQueryResultArticle, \ InputTextMessageContent, InlineKeyboardMarkup, InlineKeyboardButton from aiogram.utils import deep_linking from aiogram.utils.deep_linking import get_start_link from filters import IsUser from loader import dp, bot from utils.db_api import db_commands from utils.db_api.models import Item @dp.inline_handler(IsUser()) async def show_searched_items(query: InlineQuery): query_text = query.query items = await db_commands.search_items(query_text) await query.answer( results=await get_results(items), cache_time=10 ) async def get_results(items: List[Item]): results = [] for item in items: results.append( InlineQueryResultArticle( id=item.id, title=item.name, description=f"Цена: {item.price}грн",
import logging from aiogram.dispatcher import FSMContext from aiogram.types import Message, CallbackQuery import keyboards from filters import IsUser from handlers.users.learn_sets.click_sets import show_sets from keyboards.inline.burn_set_menu import burn_set_menu_callback from loader import dp, db @dp.message_handler(IsUser(), text="🔥Набор🔥") async def ask_delete_set(msg: Message, state: FSMContext): user = msg.from_user set_name = (await state.get_data())["set_name"] await msg.answer( "Хочешь сжечь набор {}?".format(set_name), reply_markup=keyboards.inline.burn_set_menu ) await msg.delete() logging.info(f"@{user.username}-{user.id} want deleted set {set_name}") @dp.callback_query_handler(burn_set_menu_callback.filter(action="burn")) async def delete_set(call: CallbackQuery, state: FSMContext, callback_data: dict): user = call.from_user
import logging from aiogram import types from aiogram.dispatcher import FSMContext from aiogram.types import Message from aiogram.utils.deep_linking import get_start_link import keyboards from filters import IsUser from loader import dp from utils import clean_previous_menu_msg from utils.change_bot_menu import change_bot_menu @dp.message_handler(IsUser(), text="Зацепиться🖇") async def show_connection_link(msg: Message, state: FSMContext): user = types.User.get_current() await clean_previous_menu_msg(msg, state) await state.finish() connect_link = await get_start_link(user.id, encode=True) connecting_msg = await msg.answer( "Для того чтобы зацепиться за своего друга и совместить ваши наборы слов, " "отправь эту ссылку привязки: {}".format(connect_link), reply_markup=await keyboards.inline.get_burn_user_menu(user.id) ) await state.update_data(connecting_msg_id=connecting_msg.message_id)