forked from arunpt/Image-UploadBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
57 lines (48 loc) · 1.73 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import os
import logging
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
from creds import Credentials
from telegraph import upload_file
logging.basicConfig(level=logging.WARNING)
tgraph = Client(
"Image upload bot",
bot_token=Credentials.BOT_TOKEN,
api_id=Credentials.API_ID,
api_hash=Credentials.API_HASH
)
@tgraph.on_message(filters.command("start"))
async def start(client, message):
await message.reply_text(
text=f"Hello {message.from_user.mention},\nI'm a telegram to telegra.ph image uploader bot by @W4RR10R",
disable_web_page_preview=True
)
@tgraph.on_message(filters.photo)
async def getimage(client, message):
dwn = await message.reply_text("Downloading to my server...", True)
img_path = await message.download()
await dwn.edit_text("Uploading as telegra.ph link...")
try:
url_path = upload_file(img_path)[0]
except Exception as error:
await dwn.edit_text(f"Oops something went wrong\n{error}")
return
await dwn.edit_text(
text=f"<b>Link :-</b> <code>https://telegra.ph{url_path}</code>",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="Open Link", url=f"https://telegra.ph{url_path}"
),
InlineKeyboardButton(
text="Share Link",
url=f"https://telegram.me/share/url?url=https://telegra.ph{url_path}",
)
]
]
)
)
os.remove(img_path)
tgraph.run()