File size: 1,582 Bytes
a8e9b84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
from pyrogram import filters
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from DragMusic import app

def upload_to_catbox(file_path):
    """Uploads a file to Catbox and returns the file URL."""
    url = "https://catbox.moe/user/api.php"
    with open(file_path, "rb") as file:
        response = requests.post(
            url,
            data={"reqtype": "fileupload"},
            files={"fileToUpload": file}
        )
    if response.status_code == 200:
        return response.text.strip()
    else:
        raise Exception(f"Cᴀᴛʙᴏx ᴜᴘʟᴏᴀᴅ ғᴀɪʟᴇᴅ: {response.text}")

@app.on_message(filters.command("tgm"))
def ul(_, message):
    reply = message.reply_to_message
    if not reply or not reply.media:
        return message.reply("Pʟᴇᴀsᴇ ʀᴇᴘʟʏ ᴛᴏ ᴀɴ ɪᴍᴀɢᴇ ᴏʀ ᴍᴇᴅɪᴀ ᴛᴏ ᴜᴘʟᴏᴀᴅ.")

    i = message.reply("Downloading...")
    path = reply.download()

    if not path:
        return i.edit("Fᴀɪʟᴇᴅ ᴛᴏ ᴅᴏᴡɴʟᴏᴀᴅ ᴛʜᴇ ғɪʟᴇ.")

    try:
        # Upload to Catbox
        file_url = upload_to_catbox(path)

        # Create a button with the Catbox link
        button = InlineKeyboardButton("ᴄᴀᴛʙᴏx ʟɪɴᴋ", url=file_url)
        markup = InlineKeyboardMarkup([[button]])

        # Send a reply with the button
        i.edit("Yᴏᴜʀ ғɪʟᴇ ʜᴀs ʙᴇᴇɴ ᴜᴘʟᴏᴀᴅᴇᴅ ᴛᴏ Cᴀᴛʙᴏx:", reply_markup=markup)
    except Exception as e:
        i.edit(f"An error occurred: {str(e)}")