-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbot.py
More file actions
42 lines (32 loc) · 1.1 KB
/
bot.py
File metadata and controls
42 lines (32 loc) · 1.1 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
from config import bot, SEND_TEXT
from BitlyAPI import shorten_urls
from BitlyAPI.exceptions import BitlyException, BitlyApiNotWorking
from pyrogram import filters
from pyrogram.types import Message
@bot.on_message(filters.private & filters.command("start"))
async def start_(_, msg: Message):
await msg.reply(
SEND_TEXT.format(msg.from_user.mention),
disable_web_page_preview=True
)
@bot.on_message(filters.private & filters.command("help"))
async def help_(_, msg: Message):
await msg.reply(
SEND_TEXT.format(msg.from_user.mention),
disable_web_page_preview=True
)
@bot.on_message(filters.private & filters.text)
async def reply_bitly_link(_, msg: Message):
try:
url = [msg.text]
response = shorten_urls(url)
await msg.reply(
f"**Shortened Url:**\n`{response[0].short_url}`",
disable_web_page_preview=True
)
except BitlyException as err:
await msg.reply(f"**ERROR:** `{str(err)}`")
except BitlyApiNotWorking:
await msg.reply("Bitly API is Down!")
if __name__ == "__main__":
bot.run()