Spaces:
Running
Running
taslim19
commited on
Commit
·
defe576
1
Parent(s):
6763b1e
refactor: simplify ping command and remove instagram downloader
Browse files
DragMusic/plugins/tools/ping.py
CHANGED
@@ -1,84 +1,26 @@
|
|
1 |
from datetime import datetime
|
2 |
-
|
3 |
-
from pyrogram import Client, filters
|
4 |
from pyrogram.types import Message
|
5 |
|
6 |
from DragMusic import app
|
7 |
from DragMusic.core.call import Drag
|
8 |
-
from DragMusic.utils import bot_sys_stats
|
9 |
from DragMusic.utils.decorators.language import language
|
10 |
-
from DragMusic.utils.inline import supp_markup
|
11 |
from config import BANNED_USERS, PING_IMG_URL
|
12 |
|
13 |
-
# Replace with your actual API URL and Bot Token
|
14 |
-
API_URL = "https://karma-api2.vercel.app/instadl"
|
15 |
-
DOWNLOADING_STICKER_ID = (
|
16 |
-
"CAACAgUAAxkBAAEVtNxnbAfkXOWkvCJSkfjJab2fml0AAbkAAhESAAKKWGlXKi6QQO-bOTM2BA"
|
17 |
-
)
|
18 |
|
19 |
@app.on_message(filters.command(["ping", "alive"]) & ~BANNED_USERS)
|
20 |
@language
|
21 |
async def ping_com(client, message: Message, _):
|
22 |
-
|
23 |
response = await message.reply_photo(
|
24 |
photo=PING_IMG_URL,
|
25 |
-
caption=_["ping_1"]
|
26 |
)
|
|
|
|
|
27 |
pytgping = await Drag.ping()
|
28 |
-
|
29 |
-
|
30 |
-
await response.edit_text(
|
31 |
-
_["ping_2"].format(resp, app.mention, UP, RAM, CPU, DISK, pytgping),
|
32 |
-
reply_markup=supp_markup(_),
|
33 |
-
)
|
34 |
-
|
35 |
-
# Instagram download command handler
|
36 |
-
@app.on_message(filters.command(["ig", "instagram", "insta", "instadl"]) & ~BANNED_USERS)
|
37 |
-
@language
|
38 |
-
async def instadl_command_handler(client, message: Message, _):
|
39 |
-
if len(message.command) < 2:
|
40 |
-
await message.reply_text("Usage: /instadl [Instagram URL]")
|
41 |
-
return
|
42 |
-
|
43 |
-
link = message.command[1]
|
44 |
-
downloading_sticker = None # Initialize the variable
|
45 |
-
|
46 |
-
try:
|
47 |
-
# Send the downloading sticker
|
48 |
-
downloading_sticker = await message.reply_sticker(DOWNLOADING_STICKER_ID)
|
49 |
-
|
50 |
-
# Make an asynchronous GET request to the API using httpx
|
51 |
-
async with httpx.AsyncClient() as client:
|
52 |
-
response = await client.get(API_URL, params={"url": link})
|
53 |
-
data = response.json()
|
54 |
-
|
55 |
-
# Check if the API request was successful
|
56 |
-
if "content_url" in data:
|
57 |
-
content_url = data["content_url"]
|
58 |
-
|
59 |
-
# Determine content type from the URL
|
60 |
-
content_type = "video" if "video" in content_url else "photo"
|
61 |
-
|
62 |
-
# Reply with either photo or video
|
63 |
-
if content_type == "photo":
|
64 |
-
await message.reply_photo(content_url)
|
65 |
-
elif content_type == "video":
|
66 |
-
await message.reply_video(content_url)
|
67 |
-
else:
|
68 |
-
await message.reply_text("Unsupported content type.")
|
69 |
-
else:
|
70 |
-
await message.reply_text(
|
71 |
-
"Unable to fetch content. Please check the Instagram URL or try with another Instagram link."
|
72 |
-
)
|
73 |
-
|
74 |
-
except Exception as e:
|
75 |
-
print(e)
|
76 |
-
await message.reply_text("An error occurred while processing the request.")
|
77 |
-
|
78 |
-
finally:
|
79 |
-
# Only delete the sticker if it was successfully sent
|
80 |
-
if downloading_sticker:
|
81 |
-
await downloading_sticker.delete()
|
82 |
|
83 |
# Start the Pyrogram bot
|
84 |
if __name__ == "__main__":
|
|
|
1 |
from datetime import datetime
|
2 |
+
from pyrogram import filters
|
|
|
3 |
from pyrogram.types import Message
|
4 |
|
5 |
from DragMusic import app
|
6 |
from DragMusic.core.call import Drag
|
|
|
7 |
from DragMusic.utils.decorators.language import language
|
|
|
8 |
from config import BANNED_USERS, PING_IMG_URL
|
9 |
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
@app.on_message(filters.command(["ping", "alive"]) & ~BANNED_USERS)
|
12 |
@language
|
13 |
async def ping_com(client, message: Message, _):
|
14 |
+
start_time = datetime.now()
|
15 |
response = await message.reply_photo(
|
16 |
photo=PING_IMG_URL,
|
17 |
+
caption=_["ping_1"],
|
18 |
)
|
19 |
+
end_time = datetime.now()
|
20 |
+
ping_time = (end_time - start_time).microseconds / 1000
|
21 |
pytgping = await Drag.ping()
|
22 |
+
|
23 |
+
await response.edit_text(_["ping_2"].format(app.mention, ping_time, pytgping))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
# Start the Pyrogram bot
|
26 |
if __name__ == "__main__":
|