def ask_scale_value(update, context, ask_percent=True): _ = set_lang(update, context) message = update.effective_message reply_markup = get_back_markup(update, context) if message.text == _(BY_PERCENT) or ask_percent: message.reply_text( _("Send me the scaling factors for the horizontal and vertical axes\n\n" "2 will double the axis and 0.5 will halve the axis\n\n" "*Example: 2 0.5* (this will double the horizontal axis and halve the vertical axis)" ), reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN, ) return WAIT_SCALE_PERCENT else: message.reply_text( _("Send me the width and height\n\n" "*Example: 150 200* (this will set the width to 150 and height to 200)" ), reply_markup=reply_markup, parse_mode=ParseMode.MARKDOWN, ) return WAIT_SCALE_DIMENSION
def ask_split_range(update, context): _ = set_lang(update, context) update.effective_message.reply_text( _( "Send me the range of pages that you'll like to keep\n\n" "<b>General usage</b>\n" "<code>: all pages</code>\n" "<code>22 just the 23rd page</code>\n" "<code>0:3 the first three pages</code>\n" "<code>:3 the first three pages</code>\n" "<code>5: from the 6th page onwards</code>\n" "<code>-1 last page only</code>\n" "<code>:-1 all pages but the last page</code>\n" "<code>-2 second last page only</code>\n" "<code>-2: last two pages</code>\n" "<code>-3:-1 third and second last pages only</code>\n\n" "<b>Advanced usage</b>\n" "<code>::2 pages 0 2 4 ... to the end</code>\n" "<code>1:10:2 pages 1 3 5 7 9</code>\n" "<code>::-1 all pages in reversed order</code>\n" "<code>3:0:-1 pages 3 2 1 but not 0</code>\n" "<code>2::-1 pages 2 1 0</code>" ), parse_mode=ParseMode.HTML, reply_markup=get_back_markup(update, context), ) return WAIT_SPLIT_RANGE
def ask_pdf_new_name(update, context): _ = set_lang(update, context) update.effective_message.reply_text( _("Send me the file name that you'll like to rename your PDF file into"), reply_markup=get_back_markup(update, context), ) return WAIT_FILE_NAME
def ask_encrypt_pw(update, context): _ = set_lang(update, context) update.effective_message.reply_text( _("Send me the password to encrypt your PDF file"), reply_markup=get_back_markup(update, context), ) return WAIT_ENCRYPT_PW
def ask_split_range(update, context): _ = set_lang(update, context) update.effective_message.reply_text( _("Send me the range of pages that you'll like to keep. " "Use ⚡ *INSTANT VIEW* from below or refer to " "[here](http://telegra.ph/Telegram-PDF-Bot-07-16) for some range examples." ), parse_mode=ParseMode.MARKDOWN, reply_markup=get_back_markup(update, context), ) return WAIT_SPLIT_RANGE
def ask_split_range(update: Update, context: CallbackContext) -> int: _ = set_lang(update, context) text = ("{intro}\n\n" "<b>{general}</b>\n" "<code>: {all}</code>\n" "<code>7 {eight_only}</code>\n" "<code>0:3 {first_three}</code>\n" "<code>:3 {first_three}</code>\n" "<code>7: {from_eight}</code>\n" "<code>-1 {last_only}</code>\n" "<code>:-1 {all_except_last}</code>\n" "<code>-2 {second_last}</code>\n" "<code>-2: {last_two}</code>\n" "<code>-3:-1 {third_second}</code>\n\n" "<b>{advanced}</b>\n" "<code>::2 {pages} 0 2 4 ... {to_end}</code>\n" "<code>1:10:2 {pages} 1 3 5 7 9</code>\n" "<code>::-1 {all_reversed}</code>\n" "<code>3:0:-1 {pages} 3 2 1 {except_txt} 0</code>\n" "<code>2::-1 {pages} 2 1 0</code>").format( intro=_("Send me the range of pages that you'll like to keep"), general=_("General usage"), all=_("all pages"), eight_only=_("page 8 only"), first_three=_("first three pages"), from_eight=_("from page 8 onward"), last_only=_("last page only"), all_except_last=_("all pages except the last page"), second_last=_("second last page only"), last_two=_("last two pages"), third_second=_("third and second last pages"), advanced=_("Advanced usage"), pages=_("pages"), to_end=_("to the end"), all_reversed=_("all pages in reversed order"), except_txt=_("except"), ) update.effective_message.reply_text( text, parse_mode=ParseMode.HTML, reply_markup=get_back_markup(update, context), ) return WAIT_SPLIT_RANGE
def split_pdf(update: Update, context: CallbackContext) -> int: result = check_back_user_data(update, context) if result is not None: return result _ = set_lang(update, context) message = update.effective_message split_range = message.text if not PageRange.valid(split_range): message.reply_text( _( "The range is invalid. Try again", reply_markup=get_back_markup(update, context), )) return WAIT_SPLIT_RANGE message.reply_text(_("Splitting your PDF file"), reply_markup=ReplyKeyboardRemove()) with tempfile.NamedTemporaryFile() as tf: user_data = context.user_data file_id, file_name = user_data[PDF_INFO] pdf_reader = open_pdf(update, context, file_id, tf.name) if pdf_reader is not None: merger = PdfFileMerger() merger.append(pdf_reader, pages=PageRange(split_range)) write_send_pdf(update, context, merger, file_name, "split") # Clean up memory if user_data[PDF_INFO] == file_id: del user_data[PDF_INFO] return ConversationHandler.END
def ask_scale_value(update, context, ask_percent=True): _ = set_lang(update, context) message = update.effective_message reply_markup = get_back_markup(update, context) if message.text == _(TO_DIMENSIONS) or not ask_percent: message.reply_text( _("Send me the width and height\n\n<b>Example: 150 200</b> " "(this will set the width to 150 and height to 200)"), reply_markup=reply_markup, parse_mode=ParseMode.HTML, ) return WAIT_SCALE_DIMENSION else: message.reply_text( _("Send me the scaling factors for the horizontal and vertical axes\n\n" "<b>Example: 2 0.5</b> (this will double the horizontal axis and " "halve the vertical axis)"), reply_markup=reply_markup, parse_mode=ParseMode.HTML, ) return WAIT_SCALE_PERCENT