def ans_doc(message): bot.send_message(message.from_user.id, "We're processing your request...") file_id = message.document.file_id file_info = bot.get_file(file_id) file = bot.download_file(file_info.file_path) file_name = message.document.file_name file_path = consts.dir_path + file_name with open(file_path, 'wb') as new_file: new_file.write(file) file_type = get_type(message.document.file_name) if file_type in consts.formats['photo']: def image_processing(msg): nonlocal file_path, file_type convert_to = msg.text convert_img(file_path, file_type, convert_to, msg.from_user.id) msg = bot.send_message(message.from_user.id, consts.file_ans, reply_markup=mp.gen_mrkp(file_type, consts.formats['photo'])) bot.register_next_step_handler(msg, image_processing) elif file_type in consts.formats['video']: pass elif file_type in consts.formats['text_document']: def doc_processing(msg): nonlocal file_path, file_type convert_to = msg.text convert_text_doc(file_path, file_type, convert_to, msg.from_user.id) msg = bot.send_message(message.from_user.id, consts.file_ans, reply_markup=mp.gen_mrkp(file_type, consts.formats['text_document'])) bot.register_next_step_handler(msg, doc_processing)
def send_from_video(user_id, file_type, file_path): file = open(file_path, 'rb') if file_type == 'mp4' or file_type == 'mov': bot.send_video(user_id, file) elif file_type == 'video_note': bot.send_message(user_id, 'Sorry, we cannot do it yet') else: bot.send_document(user_id, file)
def ans_sticker(message): bot.send_message(message.from_user.id, "We're processing your request...") file_id = message.sticker.file_id file_info = bot.get_file(file_id) file = bot.download_file(file_info.file_path) file_name = 'unknown.' msg = None file_type = None def sticker_processing(msg): nonlocal file_type, file flag = 1 file_type = msg.text if msg.text == 'sticker without its pack': file_type = 'png' flag = 0 file_path = consts.dir_path + file_name + file_type with open(file_path, 'wb') as new_file: new_file.write(file) file = open(file_path, 'rb') if flag: bot.send_document(msg.from_user.id, file) else: bot.send_sticker(msg.from_user.id, file) def animated_sticker_processing(msg): nonlocal file_type, file if msg.text == 'sticker without its pack': file_type = 'tgs' file_path = consts.dir_path + file_name + file_type with open(file_path, 'wb') as new_file: new_file.write(file) file = open(file_path, 'rb') bot.send_document(msg.from_user.id, file) if message.sticker.is_animated: msg = bot.send_message(message.from_user.id, consts.file_ans, reply_markup=mp.gen_mrkp( '', consts.formats['animated_sticker'])) bot.register_next_step_handler(msg, animated_sticker_processing) else: msg = bot.send_message(message.from_user.id, consts.file_ans, reply_markup=mp.gen_mrkp( '', consts.formats['sticker'])) bot.register_next_step_handler(msg, sticker_processing)
def ans_video(message): bot.send_message(message.from_user.id, "We're processing your request...") def video_message_processing(msg): file_id = message.video.file_id file_info = bot.get_file(file_id) file = bot.download_file(file_info.file_path) file_name = 'unknown.' file_type = msg.text file_path = file_name + file_type with open(file_path, 'wb') as new_file: new_file.write(file) send_from_video(msg.from_user.id, file_type, file_path) msg = bot.send_message(message.from_user.id, consts.file_ans, reply_markup=mp.gen_mrkp('video', consts.formats['video'])) bot.register_next_step_handler(msg, video_message_processing)
def ans_voice(message): msg1 = bot.send_message(message.from_user.id, consts.file_ans, reply_markup=mp.gen_mrkp('voice', consts.formats['voice'])) def ans_mrkp_voice(to_type): # if to_type.text == 'mp3': file_id = message.voice.file_id file_info = bot.get_file(file_id) file = bot.download_file(file_info.file_path) file_name = 'unknown' file_path = consts.dir_path + file_name + '.' + to_type.text with open(file_path, 'wb') as new_file: new_file.write(file) send_from_voice(to_type.from_user.id, to_type.text, file_path) bot.register_next_step_handler(msg1, ans_mrkp_voice)