Esempio n. 1
0
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)
Esempio n. 2
0
 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)
Esempio n. 3
0
def convert_img(file_path, file_type, convert_to, user_id):
    im = Image.open(file_path)
    new_file_path = file_path.replace(file_type, convert_to)
    # print(file_path, new_file_path)
    if file_type == 'png' and convert_to == 'jpg':
        rgb_im = im.convert('RGB')
        rgb_im.save(new_file_path, "JPEG", quality=100)

    if file_type == 'jpg' and convert_to == 'png':
        rgba_im = im.convert('RGBA')
        rgba_im.save(new_file_path, "PNG", quality=100)

    if file_type == 'jpg' and convert_to == 'ico':
        rgba_im = im.convert('RGBA')
        rgba_im.save(new_file_path, "ICO", quality=100)

    if file_type == 'png' and convert_to == 'ico':
        im.save(new_file_path, "ICO", quality=100)

    if file_type == 'ico' and convert_to == 'png':
        try:
            im.save(new_file_path, "PNG", quality=100)
        except:
            pass

    if file_type == 'ico' and convert_to == 'jpg':
        try:
            rgb_im = im.convert('RGB')
            rgb_im.save(new_file_path, "JPEG", quality=100)
        except:
            pass

    if file_type == 'jpg' and convert_to == 'bmp':
        im.save(new_file_path, "BMP", quality=100)

    if file_type == 'bmp' and convert_to == 'jpg':
        rgb_im = im.convert('RGB')
        rgb_im.save(new_file_path, "JPEG", quality=100)

    if file_type == 'png' and convert_to == 'bmp':
        im.save(new_file_path, "BMP", quality=100)

    if file_type == 'bmp' and convert_to == 'png':
        im.save(new_file_path, "PNG", quality=100)

    if file_type == 'ico' and convert_to == 'bmp':
        try:
            im.save(new_file_path, "BMP", quality=100)
        except:
            pass

    if file_type == 'bmp' and convert_to == 'ico':
        im.save(new_file_path, "ICO", quality=100)
    file = open(new_file_path, 'rb')
    bot.send_document(user_id, file)
Esempio n. 4
0
 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)
Esempio n. 5
0
def convert_text_doc(file_path, file_type, convert_to, user_id):
    file = None
    new_file_path = file_path.replace(file_type, convert_to)
    if file_type == 'docx' and convert_to == 'pdf':
        docx2pdf.convert(file_path, new_file_path)
        file = open(new_file_path, 'rb')

    if file_type == 'docx' and convert_to == 'txt':
        text = docx2txt.process(file_path)
        with open(new_file_path, 'w') as new_file:
            new_file.write(text)
        file = open(new_file_path, 'r')

    if file_type == 'txt' and (convert_to == 'docx' or convert_to == 'doc'):
        file = open(file_path, 'r')
        text = file.read()
        doc = docx.Document()
        doc.add_paragraph(text)
        doc.save(new_file_path)
        file = open(new_file_path, 'rb')

    bot.send_document(user_id, file)
Esempio n. 6
0
def send_from_voice(user_id, file_type, file_path):
    file = open(file_path, 'rb')
    if file_type == 'mp3':
        bot.send_audio(user_id, file)
    else:
        bot.send_document(user_id, file)