-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshort.py
More file actions
25 lines (21 loc) · 945 Bytes
/
short.py
File metadata and controls
25 lines (21 loc) · 945 Bytes
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
from pyrogram import Client, filters
from command import fox_command, fox_sudo, who_message
from requirements_installer import install_library
import os
install_library("requests")
import requests
@Client.on_message(fox_command("short", "ShortURL", os.path.basename(__file__), "[Reply/Link]") & fox_sudo())
async def shorten_link_command(client, message):
message = await who_message(client, message)
try:
await message.edit("Shorting...")
if message.reply_to_message:
link = message.reply_to_message.text
else:
link = message.command[1]
full_url = link.replace("https://", "").replace("http://", "")
response = requests.get('https://tinyurl.com/api-create.php?url=' + full_url)
short_url = response.text
await message.edit(f"Short URL: {short_url}")
except Exception as error:
await message.edit(f"Error: {error}")