forked from teletips/FileToLink
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.py
41 lines (33 loc) · 1.39 KB
/
bot.py
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
import telebot
import time
import pyshorteners
import os
bot = telebot.TeleBot(token=os.getenv('TG_BOT_TOKEN'))
def short(url):
return pyshorteners.Shortener().tinyurl.short(url)
@bot.message_handler(commands=['start'])
def send_welcome(message):
bot.reply_to(message, 'Hello bro😁! I am a File To Link Bot created by @SCProjectsLK.Send me any file (Video, Audio, Photo, Document)🏻🤗')
@bot.message_handler(commands=['help'])
def send_welcome(message):
bot.reply_to(message, '🤗Send me any type of a file & I will send you the shorten link of it😉')
@bot.message_handler(content_types=['photo', 'video', 'audio', 'document'])
def file_sent(message):
try:
bot.send_message(message.chat.id, short(bot.get_file_url(message.document.file_id)))
except AttributeError:
try:
bot.send_message(message.chat.id, short(bot.get_file_url(message.photo[0].file_id)))
except AttributeError:
try:
bot.send_message(message.chat.id, short(bot.get_file_url(message.audio.file_id)))
except AttributeError:
try:
bot.send_message(message.chat.id, short(bot.get_file_url(message.video.file_id)))
except AttributeError:
pass
while True:
try:
bot.polling()
except Exception:
time.sleep(15)