Example #1
0
def check_doc_task(update, context):
    _ = set_lang(update, context)
    text = update.effective_message.text

    if text == _(CROP):
        return ask_crop_type(update, context)
    elif text == _(DECRYPT):
        return ask_decrypt_pw(update, context)
    elif text == _(ENCRYPT):
        return ask_encrypt_pw(update, context)
    elif text in [_(EXTRACT_PHOTO), _(TO_PHOTO)]:
        return ask_photo_results_type(update, context)
    elif text == _(PREVIEW):
        return get_pdf_preview(update, context)
    elif text == _(RENAME):
        return ask_pdf_new_name(update, context)
    elif text == _(ROTATE):
        return ask_rotate_degree(update, context)
    elif text in [_(SCALE)]:
        return ask_scale_type(update, context)
    elif text == _(SPLIT):
        return ask_split_range(update, context)
    elif text == _(EXTRACT_TEXT):
        return ask_text_type(update, context)
    elif text == OCR:
        return add_ocr_to_pdf(update, context)
    elif text == COMPRESS:
        return compress_pdf(update, context)
    elif text == _(CANCEL):
        return cancel(update, context)
def check_text(update: Update, context: CallbackContext) -> int:
    update.effective_message.chat.send_action(ChatAction.TYPING)
    _ = set_lang(update, context)
    if update.effective_message.text == _(CANCEL):
        return cancel(update, context)
    else:
        return receive_feedback(update, context)
def check_text(update, context):
    _ = set_lang(update, context)
    text = update.effective_message.text

    if text == _(BACK):
        return ask_first_doc(update, context)
    elif text == _(CANCEL):
        return cancel(update, context)
Example #4
0
def check_photo_task(update, context):
    _ = set_lang(update, context)
    text = update.effective_message.text

    if text in [_(BEAUTIFY), _(TO_PDF)]:
        return process_photo_task(update, context)
    elif text == _(CANCEL):
        return cancel(update, context)
Example #5
0
def check_text(update, context):
    _ = set_lang(update, context)
    text = update.effective_message.text

    if text == _(REMOVE_LAST):
        return remove_photo(update, context)
    if text in [_(BEAUTIFY), _(TO_PDF)]:
        return process_all_photos(update, context)
    elif text == _(CANCEL):
        return cancel(update, context)
Example #6
0
def text_to_pdf(update, context):
    _ = set_lang(update, context)
    message = update.effective_message
    text = message.text

    if text == _(CANCEL):
        return cancel(update, context)

    message.reply_text(_("Creating your PDF file"),
                       reply_markup=ReplyKeyboardRemove())
    html = HTML(string=BASE_HTML.format(text.replace("\n", "<br/>")))

    with tempfile.TemporaryDirectory() as dir_name:
        out_fn = os.path.join(dir_name, "Text.pdf")
        html.write_pdf(out_fn)
        send_result_file(update, context, out_fn, "text")

    return ConversationHandler.END
def check_text(update: Update, context: CallbackContext) -> int:
    message = update.effective_message
    message.chat.send_action(ChatAction.TYPING)
    _ = set_lang(update, context)
    text = message.text

    if text in [_(REMOVE_LAST), _(DONE)]:
        user_id = message.from_user.id
        lock = merge_locks[user_id]

        if not check_user_data(update, context, MERGE_IDS, lock):
            return ConversationHandler.END

        if text == _(REMOVE_LAST):
            return remove_doc(update, context, lock)
        elif text == _(DONE):
            return preprocess_merge_pdf(update, context, lock)
    elif text == _(CANCEL):
        return cancel(update, context)
Example #8
0
def check_text(update: Update, context: CallbackContext):
    message = update.effective_message
    message.reply_chat_action(ChatAction.TYPING)

    _ = set_lang(update, context)
    text = message.text

    if text == _(CANCEL):
        return cancel(update, context)

    font_family: str = None
    font_url: str = None

    if text == _(SKIP):
        font_family = DEFAULT_FONT
    else:
        font_family, font_url = get_font(text)

    if font_family is not None:
        return text_to_pdf(update, context, font_family, font_url)
    else:
        message.reply_text(_("Unknown font, please try again"))
        return WAIT_FONT
Example #9
0
def check_text(update: Update, context: CallbackContext) -> int:
    message = update.effective_message
    message.chat.send_action(ChatAction.TYPING)
    text = update.effective_message.text
    result = ConversationHandler.END
    _ = set_lang(update, context)

    if text in [_(REMOVE_LAST), _(BEAUTIFY), _(TO_PDF)]:
        user_id = message.from_user.id
        photo_locks[user_id].acquire()

        if not check_user_data(update, context, PHOTO_IDS):
            result = ConversationHandler.END
        else:
            if text == _(REMOVE_LAST):
                result = remove_photo(update, context)
            elif text in [_(BEAUTIFY), _(TO_PDF)]:
                result = process_all_photos(update, context)

        photo_locks[user_id].release()
    elif text == _(CANCEL):
        result = cancel(update, context)

    return result
Example #10
0
def ask_font(update: Update, context: CallbackContext):
    message = update.effective_message
    message.reply_chat_action(ChatAction.TYPING)

    _ = set_lang(update, context)
    text = message.text

    if text == _(CANCEL):
        return cancel(update, context)

    context.user_data[TEXT] = text
    reply_markup = ReplyKeyboardMarkup([[_(SKIP)]],
                                       resize_keyboard=True,
                                       one_time_keyboard=True)
    message.reply_text(
        _("Send me the font that you'll like to use for the PDF file or "
          "skip to use the default font\n\nSee here for the list of supported fonts:"
          ) + ' <a href="https://fonts.google.com/">Google Fonts</a>',
        parse_mode=ParseMode.HTML,
        disable_web_page_preview=True,
        reply_markup=reply_markup,
    )

    return WAIT_FONT
Example #11
0
def check_text(update, context):
    _ = set_lang(update, context)
    text = update.effective_message.text

    if text == _(CANCEL):
        return cancel(update, context)