예제 #1
0
async def ask_to_connect(msg: Message):
    user = msg.from_user
    friend_id = int(decode_payload(msg.get_args()))

    if not (await redis_commands.is_user(user.id)):
        await bot_start(msg)

    if user.id == friend_id:
        return
    elif not (await redis_commands.is_user(friend_id)):
        await msg.answer("Такого пользователя не существует...",
                         reply_markup=keyboards.default.get_bot_menu())
        await msg.answer_sticker(
            "CAACAgIAAxkBAAIDXGBRMulMsWISnPXOc16gVBC-09MmAAIYAAPANk8T1vonv5xqGPgeBA"
        )
        return
    elif await db.is_users_connected(user.id, friend_id):
        await msg.answer("Ты уже закреплен за этого пользователя...",
                         reply_markup=keyboards.default.get_bot_menu())
        await msg.answer_sticker(
            "CAACAgIAAxkBAAIEu2BTYZvJKYkVXcleRsmhI8V4q4A9AAINAAPANk8TpPnh9NR4jVMeBA"
        )
        return

    friend = (await msg.bot.get_chat_member(friend_id, friend_id)).user

    await msg.answer(
        "Хочешь зацепится за @{}?".format(friend.username),
        reply_markup=keyboards.inline.get_connect_user_menu(friend_id))

    logging.info(
        f"Ask @{user.username}-{user.id} to connect by connection_link to @{friend.username}-{friend_id}"
    )
예제 #2
0
async def bot_start_deeplink(message: types.Message, user: User):
    """Переход по реф. ссылке"""

    if user:
        await already_registered(message)
    else:
        deep_link_args = message.get_args()
        decoded_link = int(decode_payload(deep_link_args))
        await registration(message, decoded_link)
예제 #3
0
async def start_handler(message: types.Message, state: FSMContext):
    if state:
        await state.finish()
    text = message.text.split(' ')
    if len(text) > 1:
        payload = decode_payload(text[1])
        vacancy_id = int(payload)
        if not message.from_user.username:
            await CheckUsername.payload.set()
            await state.update_data(payload=vacancy_id)
            await state.update_data(user_id=message.from_user.id)
            await set_username(message.chat.id)
            return
        user = User.get_or_none(User.chat_id == message.chat.id)
        if not user:
            user = User(username=message.from_user.username,
                        first_name=message.from_user.first_name,
                        second_name=message.from_user.last_name,
                        chat_id=message.chat.id)
            user.save()
        # await FindVacancy.name.set()
        await show_vacancy_pure(message.chat.id, vacancy_id)
    else:
        user = User.get_or_none(User.chat_id == message.chat.id)
        if not user:
            user = User(username=message.from_user.username,
                        first_name=message.from_user.first_name,
                        second_name=message.from_user.last_name,
                        chat_id=message.chat.id)
            user.save()
            await message.answer(messages.start_message)

        keyboard = InlineKeyboardMarkup()
        keyboard.add(
            InlineKeyboardButton(buttons.create_vacancy,
                                 callback_data='create_vacancy'),
            # InlineKeyboardButton(buttons.find_vacancies, callback_data='find_vacancies')
        )
        vacancies = Vacancy.select().where(Vacancy.creator == User.get(
            User.chat_id == message.chat.id))
        if vacancies:
            keyboard.add(
                InlineKeyboardButton(buttons.placed_vacancies,
                                     callback_data='placed_vacancies'))

        candidate = Candidate.select().where(Candidate.user == User.get(
            User.chat_id == message.chat.id))
        for i in candidate:
            if i.status == 'Отправлено тестовое задание':
                keyboard.add(
                    InlineKeyboardButton(
                        buttons.test_task.format(i.vacancy.name),
                        callback_data=f'send_test_task_solution_{i.vacancy.id}'
                    ))

        await message.answer(messages.menu, reply_markup=keyboard)
예제 #4
0
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
    )
예제 #5
0
    async def check(self, message: Message) -> bool:
        from aiogram.utils.deep_linking import decode_payload
        check = await super().check(message)
        group_ids = [
            str(d['tg_id']) for d in await Group.all().values("tg_id")
        ]

        if check:
            payload = str(decode_payload(message.get_args()))
            return False if not (payload in group_ids) else {
                'group_id': payload
            }
        return check
예제 #6
0
async def bot_start(message: types.Message):
	"""Referral's operation"""
	args = message.get_args()
	print('args = {}'.format(args))
	referral = None
	if args and args != 'not_user':
		referral = decode_payload(args)
		print('referral = {}'.format(referral))
	
	if not referral or args == 'not_user':
		text = ['Чтобы использовать этого бота введите код приглашения, либо пройдите по реферальной ссылке.',
		        'Введите команду /invite для ввода кода приглашения:']
		# \nРеферальная ссылка https://t.me/{bot_username}?start={chat_id}
		await message.answer('\n'.join(text))
	# await message.answer(text = 'Введите команду /invite для ввода кода приглашения:')
	else:
		user_id = message.from_user.id
		if int(referral) != user_id:
			await message.answer(f'Привет, {message.from_user.full_name}!')
			await message.answer('Занесён по реферальной ссылке')
			await message.answer('/help - помощь')
			await comm.add_user(user_id = user_id, username = message.from_user.username,
			                    name = message.from_user.full_name)
			await comm.update_bonus(int(referral))
예제 #7
0
 async def test_filter_encode_and_decode(self, payload):
     _payload = filter_payload(payload)
     encoded = encode_payload(_payload)
     decoded = decode_payload(encoded)
     assert decoded == str(payload)