forked from Mrvishal2k2/TG-ShortLinkBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
58 lines (46 loc) · 2.02 KB
/
bot.py
File metadata and controls
58 lines (46 loc) · 2.02 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# © All rights reserved by Mrvishal2k2
# Kangers dont f*ckin kang this !!!
# Should have to give credits 😏 else f***off
# This is only for personal use Dont use this for ur bot channel business 😂
# Thanks to Mahesh Malekar for his Gplinks Bot !!
from os import environ
# Moved Back to asyncio-dev branch of pyrogram
from pyrogram import Client, Filters, InlineKeyboardButton, InlineKeyboardMarkup
import pyshorteners
API_ID = environ.get('API_ID')
API_HASH = environ.get('API_HASH')
BOT_TOKEN = environ.get('BOT_TOKEN')
API_KEY = environ.get('API_KEY')
bot = Client('Shortlink bot',
api_id=API_ID,
api_hash=API_HASH,
bot_token=BOT_TOKEN,
workers=50,
sleep_threshold=10)
@bot.on_message(Filters.command('start') & Filters.private)
async def start(bot, update):
await update.reply(
f"**Hi {update.chat.first_name}!**\n\n"
"I'm shortlink bot. Just send me link and get adsless short link. This Bot Is Made By : @ExploitzBots")
@bot.on_message(Filters.regex(r'https?://[^\s]+') & Filters.private)
async def link_handler(bot, update):
link = update.matches[0].group(0)
if API_KEY:
try:
s = pyshorteners.Shortener(api_key=API_KEY)
shortened_url = s.cuttly.short(link)
button = [[InlineKeyboardButton("Link 🔗", url=shortened_url)]]
markup = InlineKeyboardMarkup(button)
await update.reply_text(text=f'Here is your shortlink \n`{shortened_url}`', reply_markup=markup, quote=True)
except Exception as e:
await update.reply(f'Error: {e}', quote=True)
else:
try:
s = pyshorteners.Shortener()
shortened_url = s.dagd.short(link)
button = [[InlineKeyboardButton("Link 🔗", url=shortened_url)]]
markup = InlineKeyboardMarkup(button)
await update.reply_text(text=f'Here is your shortlink \n`{shortened_url}`', reply_markup=markup, quote=True)
except Exception as e:
await update.reply(f'Error: {e}', quote=True)
bot.run()