Beispiel #1
0
async def change_captcha(event, strings, state=None, **kwargs):
    message = event.message
    async with state.proxy() as data:
        data['regen_num'] = 1 if 'regen_num' not in data else data[
            'regen_num'] + 1
        regen_num = data['regen_num']

        if regen_num > 3:
            img, num = generate_captcha(number=data['captcha_num'])
            text = strings['last_chance']
            await message.edit_media(InputMediaPhoto(img, caption=text))
            return

        img, num = generate_captcha()
        data['captcha_num'] = num

    text = strings['ws_captcha_text'].format(
        user=await get_user_link(event.from_user.id))

    buttons = InlineKeyboardMarkup().add(
        InlineKeyboardButton(strings['regen_captcha_btn'],
                             callback_data='regen_captcha'))

    await message.edit_media(InputMediaPhoto(img, caption=text),
                             reply_markup=buttons)
Beispiel #2
0
async def all_msg_handler(message: types.Message):
    """
    Main request for task solutions
    """
    id = message.from_user.id
    add_to_all_time_users(id)
    if id in sem_dict:
        sem = sem_dict[id]
        zad = message.text
        url = f"http://web:8000/phys/?sem={sem}&zad={zad}"
        req = urllib.request.Request(url)
        response = urllib.request.urlopen(req)
        result = json.loads(response.read().decode())
        output = result["search_output"]

        await message.answer(output)

        if result["image_found"] == True:
            base_img_url = "https://mipt.one" + result["image_url"]
            if result["second_file"] == True:
                if result["third_file"] == True:
                    await bot.send_media_group(
                        id,
                        media=[
                            InputMediaPhoto(base_img_url + prefix + ".jpg")
                            for prefix in ["", "-2", "-3"]
                        ],
                    )
                else:
                    await bot.send_media_group(
                        id,
                        media=[
                            InputMediaPhoto(base_img_url + prefix + ".jpg")
                            for prefix in ["", "-2"]
                        ],
                    )
            else:
                await bot.send_photo(id, base_img_url + ".jpg")
        elif result["wrong_input"] == False:
            if id not in blacklist:
                await bot.send_message(
                    id, "Отправь мне свое решение одной фоткой 🤏")
            else:
                pass
        else:
            pass
    else:
        await bot.send_message(
            id,
            "Пожалуйста выберете семестр.\nВыбранный семестр мог сброситься при обновленни бота.",
            reply_markup=change_sem_keyboard(),
        )
Beispiel #3
0
async def send_tg(session, text, disable_wp, images, gifs):
    """
    Sends all gathered data to TG
    """

    # Sends the text portion of the post
    # If it's longer than 4000 characters, sends it in chunks
    while len(text) > 4000:
        await my_bot.send_message(config.mm_chat,
                                  text[:4000],
                                  parse_mode='HTML',
                                  disable_web_page_preview=disable_wp)
        text = text[4000:]
    await my_bot.send_message(config.mm_chat,
                              text,
                              parse_mode='HTML',
                              disable_web_page_preview=disable_wp)

    # Sends all images and GIFs found in the post's attachments
    if len(images) > 0:
        await my_bot.send_media_group(config.mm_chat,
                                      [InputMediaPhoto(url) for url in images])

    for url in gifs:
        async with session.get(url) as response:
            gif = await response.content.read()
        await my_bot.send_document(config.mm_chat, ('File.gif', gif))
 def GroupElement(path):
     return InputMediaPhoto(InputFile(path))