Ejemplo n.º 1
0
import logging
from aiogram import types
from aiogram.dispatcher.filters import Command
from aiogram.types import CallbackQuery
from keyboards.inline.buy_inline import choice, beer_keyboard
from keyboards.inline.callback_datas import buy_callback
from loader import dp


@dp.message_handler(Command("purchase"))
async def show_items(message: types.Message):
    await message.answer(text="There's what you can buy:", reply_markup=choice)


@dp.callback_query_handler(buy_callback.filter(item_name="Beer"))
async def buying_beer(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    logging.info(f"callback_data = {call.data}")
    logging.info(f"callback_data dict = {callback_data}")
    quantity = callback_data.get("quantity")
    await call.message.answer(f"Your choice is Beer, quantity is {quantity}",reply_markup=beer_keyboard)


@dp.callback_query_handler(buy_callback.filter(item_name="Cola"))
async def buying_cola(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    logging.info(f"callback_data = {call.data}")
    logging.info(f"callback_data dict = {callback_data}")
    quantity = callback_data.get("quantity")
    await call.message.answer(f"Your choice is Cola, quantity is {quantity}")
Ejemplo n.º 2
0
    await call.answer(cache_time=60)

    callback_data = call.data

    # Отобразим что у нас лежит в callback_data
    # logging.info(f"callback_data='{callback_data}'")
    # В питоне 3.8 можно так
    logging.info(f"{callback_data=}")

    await call.message.answer(
        "Вы выбрали купить грушу. Груша всего одна. Спасибо.",
        reply_markup=pear_keyboard)


# Попробуем использовать фильтр от CallbackData
@dp.callback_query_handler(buy_callback.filter(item_name="apple"))
async def buying_apples(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)

    # Выведем callback_data и тут, чтобы сравнить с предыдущим вариантом.
    logging.info(f"{callback_data=}")

    quantity = callback_data.get("quantity")
    await call.message.answer(
        f"Вы выбрали купить яблоки. Яблок всего {quantity}. Спасибо.",
        reply_markup=apples_keyboard)


@dp.callback_query_handler(text="cancel")
async def cancel_buying(call: CallbackQuery):
    # Ответим в окошке с уведомлением!
Ejemplo n.º 3
0
from keyboards.inline.callback_datas import buy_callback
from keyboards.inline.choice_buttons import choice, pear_keyboard_terrain, pear_keyboard_route
from loader import dp


@dp.message_handler(Command("items"))
async def show_items(message: types.Message):
    await message.answer(
        text=f"Мы можем предложить\n1)Карту местности,\n 2)Карту маршрутов.\n"
        "Если ничего не интересует - нажмите отмена",
        # choice - клавиатура
        reply_markup=choice)
    # await bot.send_photo(chat_id=message.chat_id,photo=)


@dp.callback_query_handler(buy_callback.filter(item_name="terrain_map"))
async def buying_terrain_map(call: CallbackQuery, callback_data: dict):
    # не ловит в 60 сек
    await call.answer(cache_time=60)
    # Логирование
    # logging.info(f"callback_data := {call.data}")
    # ScaleMap = callback_data.get("skale")
    await call.message.answer(
        f"Вы выбрали купить карту местности!\n".upper(
        ),  # f"Масштаб 1 к {ScaleMap}",
        reply_markup=pear_keyboard_terrain)
    await call.message.edit_reply_markup(reply_markup=None)


@dp.callback_query_handler(buy_callback.filter(item_name="route_map"))
async def buying_route_map(call: CallbackQuery, callback_data: dict):
Ejemplo n.º 4
0
import requests
from aiogram.dispatcher.filters import Command
from aiogram.types import Message, CallbackQuery
from keyboards.inline.callback_datas import buy_callback, city_callback
from keyboards.inline.choice_buttons import choice, today_keyboard
from loader import dp, bot, api_gis
from .pars import text_with


@dp.message_handler(Command("start"))
async def show_items(message: Message):
    await message.answer(text="Привет, хочешь узнать прогноз погоды?",
                         reply_markup=choice)


@dp.callback_query_handler(buy_callback.filter(date_temp="today"))
async def one_day(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)  # время ожидания

    logging.info(f"{callback_data=}")

    await call.message.answer(text='Выберите город, либо введите свой',
                              reply_markup=today_keyboard)


@dp.message_handler()
async def echo(message: Message):
    logging.info(f'{message}')
    message_lower = message.text
    city_name = message_lower.lower()
    await message.answer(text_with(city_name))
Ejemplo n.º 5
0
from keyboards.inline.study_task_buttons import buttons
from loader import dp, bot


@dp.message_handler(Command('item'))
async def item(message: types.Message):
    await bot.send_photo(
        chat_id=message.from_user.id,
        photo=
        "https://d05c960b-0698-4405-ba5e-353903867a1b.selcdn.net/image/cache/data/"
        "tovary/handgun-wolf-01/Ugears-Handgun-Mechanical-Model-1--Title-530x380.jpg",
        caption=f'Пистолет {emoji.emojize(":thumbs_up:")}',
        reply_markup=(buttons))


@dp.callback_query_handler(buy_callback.filter(item_name="Покупай товар № "))
async def buying_phone(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    logging.info(f'callback_data = {call.data}')
    logging.info(f'callback_data dict = {callback_data}')
    gun = callback_data.get('item_name')
    one = callback_data.get('quantity')
    await call.bot.send_photo(
        chat_id=call.from_user.id,
        photo=
        "https://d05c960b-0698-4405-ba5e-353903867a1b.selcdn.net/image/cache/data/"
        "tovary/handgun-wolf-01/Ugears-Handgun-Mechanical-Model-1--Title-530x380.jpg",
        caption=f'{gun}{one}',
        reply_markup=buttons)

Ejemplo n.º 6
0
    choose_action.insert(like_item)
    dislike_item = InlineKeyboardButton(
        text="👎", callback_data=dislike_callback.new(id=id))
    choose_action.insert(dislike_item)
    # для того, чтобы поделиться используем switch_inline_query
    share = InlineKeyboardButton(
        text="Share it", switch_inline_query=f"Buy {fruit.name} in our shop!")
    choose_action.insert(share)

    await call.message.answer_photo(
        photo=fruit.photo,
        caption=f"This is  {fruit.name}. Buy and eat it",
        reply_markup=choose_action)


@dp.callback_query_handler(buy_callback.filter())
async def buying_apples(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    logging.info(f"{callback_data=}")
    id = callback_data.get('id')
    fruit = fruits[int(id)]
    await call.message.answer_photo(
        photo=fruit.photo,
        caption=f"You bought the fruit with id {fruit.id}",
        reply_markup=None)


@dp.callback_query_handler(like_callback.filter())
async def buying_apples(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    id = callback_data.get('id')
Ejemplo n.º 7
0
from aiogram import types
from aiogram.types import CallbackQuery

from keyboards.inline.callback_datas import buy_callback
from keyboards.inline.small_sliv import small, minimum_keyboard
from loader import dp


@dp.message_handler(text='Небольшие сливы')
async def get_smallSliv(message: types.Message):
    await message.answer('Небольшие сливы', reply_markup=small)


@dp.callback_query_handler(buy_callback.filter(item_name='mP1'))
async def get_pack1(call: CallbackQuery):
    await call.message.answer(text='Пакет минимальный',
                              reply_markup=minimum_keyboard)
    await call.message.delete()


@dp.callback_query_handler(buy_callback.filter(item_name='mP2'))
async def get_pack2(call: CallbackQuery):
    await call.message.answer(text='Пакет стандартный',
                              reply_markup=minimum_keyboard)
    await call.message.delete()


@dp.callback_query_handler(buy_callback.filter(item_name='mP3'))
async def get_pack3(call: CallbackQuery):
    await call.message.answer(text='Пакет полный',
                              reply_markup=minimum_keyboard)
Ejemplo n.º 8
0
from keyboards.inline.callback_datas import buy_callback
from keyboards.inline.choise_buttons import choice, note_keyboard
from loader import dp


@dp.message_handler(Command('items'))
async def show_items(message: types.Message):
    await message.answer(text="На продажу у нас есть 2 товара:\n"
                         "<b>1) 5 телефонов</b>\n"
                         "<b>2) 7 ноутбуков</b>\n"
                         "Если Вам ничего не нужно нажмите <b>ОТМЕНА</b>",
                         reply_markup=choice)


@dp.callback_query_handler(buy_callback.filter(item_name="phone"))
async def buying_phone(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    logging.info(f'callback_data = {call.data}')
    logging.info(f'callback_data dict = {callback_data}')
    quantity = callback_data.get('quantity')
    await call.message.answer(f'You buying {quantity} phones',
                              reply_markup=note_keyboard)


@dp.callback_query_handler(buy_callback.filter(item_name="notebook"))
async def buying_apples(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)

    # Выведем callback_data и тут, чтобы сравнить с предыдущим вариантом.
    logging.info(f"{callback_data=}")
Ejemplo n.º 9
0
    # Обязательно сразу сделать answer, чтобы убрать "часики" после нажатия на кнопку.
    # Укажем cache_time, чтобы бот не получал какое-то время апдейты, тогда нижний код не будет выполняться.
    await call.answer(cache_time=60)

    callback_data = call.data

    # Отобразим что у нас лежит в callback_data
    # logging.info(f"callback_data='{callback_data}'")
    # В Python 3.8 можно так, если у вас ошибка, то сделайте предыдущим способом!
    logging.info(f"{callback_data=}")

    await call.message.answer("Вы выбрали услуги ремонта.Спасибо.",
                              reply_markup=remont_keyboard)


@dp.callback_query_handler(buy_callback.filter(item_name="stroys"))
async def buying_stroys(call: CallbackQuery, callback_data: dict):
    await call.answer(cache_time=60)
    logging.info(f"{callback_data=}")
    quantity = callback_data.get("quantity")
    await call.message.answer(f"Вы выбрали услуги строительства. Услуги строительства наличивают всего {quantity} услуг. Спасибо.",
                              reply_markup=stroys_keyboard)


@dp.callback_query_handler(text="cancel")
async def cancel_buying(call: CallbackQuery):
    # Ответим в окошке с уведомлением!
    await call.answer("Вы отменили эту покупку!", show_alert=True)

    # Вариант 1 - Отправляем пустую клваиатуру изменяя сообщение, для того, чтобы ее убрать из сообщения!
    await call.message.edit_reply_markup(reply_markup=None)
Ejemplo n.º 10
0
from aiogram import types
from aiogram.dispatcher.filters import Command
from aiogram.types import CallbackQuery

from keyboards.inline.callback_datas import buy_callback
from keyboards.inline.choice_button import choice, elephant_keyboard
from loader import dp


@dp.message_handler(Command("items"))
async def show_items(message: types.Message):
    await message.answer(text="Инлайн кнопки", reply_markup=choice)


@dp.callback_query_handler(buy_callback.filter(item_name="elephant"))
async def buyinf_elephant(call: CallbackQuery, callback_data: dict):
    # await bot.answer_callback_query(callback_query_id=call.id)
    await call.answer(cache_time=60)
    logging.info(f"callback_data = {call.data}")
    logging.info(f"callback_data dict = {callback_data}")
    quantity = callback_data.get("quantity")
    await call.message.answer(f"Слонов {quantity}",
                              reply_markup=elephant_keyboard)


@dp.callback_query_handler(text="cancel")
async def cancel(call: CallbackQuery):
    await call.answer("ОТМЕНА", show_alert=True)
    await call.message.edit_reply_markup()
Ejemplo n.º 11
0
async def level_student(message: Message, state: FSMContext):
    student_id = message.text
    users = await quick_commands.select_all_users()
    n = []
    for data in users:
        n.append(data.student_id)
    if student_id in n:
        await state.update_data(answer1=student_id)
        await message.answer(text="You are authorized to continue")
        await message.answer(text="Please select your academic level:",
                             reply_markup=level)

        await Fsm.level.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="PY"),
                               state=Fsm.level)
    async def py_student(call: CallbackQuery, state: FSMContext,
                         callback_data: dict):
        level = callback_data.get('item_name')
        await state.update_data(answer2=level)
        await call.answer(cache_time=60)
        await call.message.edit_text(
            "Please select your Faculty",
            reply_markup=faculty,
        )

        await Fsm.faculty.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="1st"),
                               state=Fsm.level)
    async def st_student(call: CallbackQuery, state: FSMContext,
                         callback_data: dict):
        level = callback_data.get('item_name')
        await state.update_data(answer2=level)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your Faculty",
                                     reply_markup=faculty)
        await Fsm.faculty.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="2nd"),
                               state=Fsm.level)
    async def nd_student(call: CallbackQuery, state: FSMContext,
                         callback_data: dict):
        level = callback_data.get('item_name')
        await state.update_data(answer2=level)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your Faculty",
                                     reply_markup=faculty)
        await Fsm.faculty.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="3rd"),
                               state=Fsm.level)
    async def rd_student(call: CallbackQuery, state: FSMContext,
                         callback_data: dict):
        level = callback_data.get('item_name')
        await state.update_data(answer2=level)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your Faculty",
                                     reply_markup=faculty)
        await Fsm.faculty.set()

    # Faculty of Students
    @dp.callback_query_handler(buy_callback.filter(item_name="ME"),
                               state=Fsm.faculty)
    async def me_student(call: CallbackQuery, state: FSMContext,
                         callback_data: dict):
        faculty = callback_data.get('item_name')
        await state.update_data(answer3=faculty)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your Course",
                                     reply_markup=course_name)
        await Fsm.course_name.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="IT"),
                               state=Fsm.faculty)
    async def it_student(call: CallbackQuery, state: FSMContext,
                         callback_data: dict):
        faculty = callback_data.get('item_name')
        await state.update_data(answer3=faculty)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your Course",
                                     reply_markup=course_name)
        await Fsm.course_name.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="CIVIL"),
                               state=Fsm.faculty)
    async def civil_student(call: CallbackQuery, state: FSMContext,
                            callback_data: dict):
        faculty = callback_data.get('item_name')
        await state.update_data(answer3=faculty)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your Course",
                                     reply_markup=course_name)
        await Fsm.course_name.set()

    # Course of Student
    @dp.callback_query_handler(buy_callback.filter(item_name="APA"),
                               state=Fsm.course_name)
    async def apa_student(call: CallbackQuery, state: FSMContext,
                          callback_data: dict):
        course_name = callback_data.get('item_name')
        await state.update_data(answer4=course_name)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your professors ",
                                     reply_markup=professor)
        await Fsm.professor.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="FMD"),
                               state=Fsm.course_name)
    async def fmd_student(call: CallbackQuery, state: FSMContext,
                          callback_data: dict):
        course_name = callback_data.get('item_name')
        await state.update_data(answer4=course_name)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your professors ",
                                     reply_markup=professor)
        await Fsm.professor.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="TATT"),
                               state=Fsm.course_name)
    async def tatt_student(call: CallbackQuery, state: FSMContext,
                           callback_data: dict):
        course_name = callback_data.get('item_name')
        await state.update_data(answer4=course_name)
        await call.answer(cache_time=60)
        await call.message.edit_text("Please select your professors ",
                                     reply_markup=professor)
        await Fsm.professor.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="Yusupov"),
                               state=Fsm.professor)
    async def professor_1(call: CallbackQuery, state: FSMContext,
                          callback_data: dict):
        professor = callback_data.get('item_name')
        await state.update_data(answer5=professor)
        await call.answer(cache_time=60)
        await call.message.edit_text(
            "Please select number from min(1) to max(5) ", reply_markup=point)
        await Fsm.point.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="Pirnazarov"),
                               state=Fsm.professor)
    async def professor_2(call: CallbackQuery, state: FSMContext,
                          callback_data: dict):
        professor = callback_data.get('item_name')
        await state.update_data(answer5=professor)
        await call.answer(cache_time=60)
        await call.message.edit_text(
            "Please select number from min(1) to max(5) ", reply_markup=point)
        await Fsm.point.set()

    @dp.callback_query_handler(buy_callback.filter(item_name="Djalilov"),
                               state=Fsm.professor)
    async def professor_3(call: CallbackQuery, state: FSMContext,
                          callback_data: dict):
        professor = callback_data.get('item_name')
        await state.update_data(answer5=professor)
        await call.answer(cache_time=60)
        await call.message.edit_text(
            "Please select number from min(1) to max(5) ", reply_markup=point)
        await Fsm.point.set()

    @dp.callback_query_handler(buy_call.filter(item_name="number"),
                               state=Fsm.point)
    async def point_1(call: CallbackQuery, state: FSMContext,
                      callback_data: dict):
        point = callback_data.get("quantity")
        await state.update_data(answer6=point)
        await call.answer(cache_time=60)
        data = await state.get_data()
        answer1 = data.get('answer1')
        answer2 = data.get('answer2')
        answer3 = data.get('answer3')
        answer4 = data.get('answer4')
        answer5 = data.get('answer5')
        answer6 = data.get('answer6')
        try:
            await commands.update_message(student_id=answer1,
                                          level=answer2,
                                          faculty=answer3,
                                          point=int(answer6),
                                          course_name=answer4,
                                          professor=answer5)
        except Exception:
            await commands.add_user(student_id=answer1,
                                    level=answer2,
                                    faculty=answer3,
                                    point=int(answer6),
                                    course_name=answer4,
                                    professor=answer5)
        await call.message.edit_text(f'Thank you!')
        await state.finish()
Ejemplo n.º 12
0
from aiogram.dispatcher.filters import Command
from aiogram.types import CallbackQuery

from keyboards.inline.callback_datas import buy_callback
from keyboards.inline.choice_buttons import choice, btc_keyboard, eth_keyboard
from loader import dp, bot


@dp.message_handler(Command("items"))
async def show_items(message: types.Message):
    await message.answer(text="We have for trade - 2 BTC, 10 ETH, 50 ZEC \n"
                              "If you don't wanna buy - click skip button", reply_markup=choice)


@dp.callback_query_handler(buy_callback.filter(item_name="btc"))
async def buying_btc(call: CallbackQuery, callback_data: dict):
    # await bot.answer_callback_query(callback_query_id=call.id)
    await call.answer(cache_time=60)
    # logging.info(f"callback_data = {call.data}")
    # logging.info(f"callback_data dict= {callback_data}")
    quantity = callback_data.get("quantity")
    await call.message.answer(f"You bought {quantity} BTC", reply_markup=btc_keyboard)


@dp.callback_query_handler(buy_callback.filter(item_name="eth"))
async def buying_eth(call: CallbackQuery, callback_data: dict):
    # await bot.answer_callback_query(callback_query_id=call.id)
    await call.answer(cache_time=60)
    # logging.info(f"callback_data = {call.data}")
    # logging.info(f"callback_data dict= {callback_data}")
Ejemplo n.º 13
0
from aiogram.dispatcher.filters import Command
from aiogram.types import Message, CallbackQuery

from keyboards.inline.callback_datas import buy_callback
from keyboards.inline.item_keyboard import choice
from loader import dp


@dp.message_handler(Command("item"))
async def show_item(message: Message):
    await message.answer_photo(
        photo=
        "https://lh3.googleusercontent.com/proxy/W--coAUEuOnWu4BYRGX6-DIf88XT6RBpYPdK1IxkcibXQuKJq0AAwqw3QukavNkJzarlIe-8ASy6DAE84eATeKorVnVl4KHAqA6PmqrHfZY",
        caption="Мандарин",
        reply_markup=choice)


@dp.callback_query_handler(buy_callback.filter(item_id="1"))
async def buying_mandarin(call: CallbackQuery, callback_data: dict):
    item_id = callback_data.get("item_id")
    await call.message.edit_caption(caption=f"Покупай товар номер {item_id}",
                                    reply_markup=None)