forked from Ns-AnoNymouS/Telegraph-Uploader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_to_telegraph.py
More file actions
103 lines (87 loc) · 3.13 KB
/
Copy pathupload_to_telegraph.py
File metadata and controls
103 lines (87 loc) · 3.13 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import logging
import logging.config
# Get logging configurations
logging.config.fileConfig('logging.conf')
logging.getLogger().setLevel(logging.ERROR)
logging.getLogger("pyrogram").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
import os
import time
from config import Config
from helpers import progress
from telegraph import upload_file, Telegraph
from pyrogram import Client, filters
telegraphbot = Client("TELEGRAPH",
bot_token=Config.BOT_TOKEN,
api_id=Config.API_ID,
api_hash=Config.API_HASH,
parse_mode="markdown",
workers=100)
@telegraphbot.on_message(filters.command('start') & filters.incoming)
async def start_handlers(c, m):
await m.reply_text(
"Hello **Dear!**\n\n"
"I am a telegra.ph uploader.\n\n"
"⍟ I can upload photos to telegra.ph and gives you the link.\n"
"⍟ I can create a instant view link for your text.\n"
"⍟ I can create post in telegra.ph if you send any text.\n"
"(You can send text in format `post content|TITLE`)\n\n"
"Create your own [𝗙𝗼𝗿𝗸 𝗡𝗼𝘄](https://github.com/Ns-AnoNymouS/Telegraph-Uploader)",
disable_web_page_preview=True,
quote=True
)
@telegraphbot.on_message(filters.photo & filters.incoming)
async def telegraph(c, m):
"""Uploading to photo to telegra.ph
and sending photo link to user"""
try:
send_message = await m.reply_text(
"Processing....⏳",
quote=True
)
location = f'./{m.from_user.id}{time.time()}/'
start_time = time.time()
file = await m.download(
location,
progress=progress,
progress_args=(send_message, start_time)
)
try:
media_upload = upload_file(file)
except Exception as e:
print('An Error occurred', e)
await send_message.edit(f'**Error:**\n{e}')
telegraph_link = f'https://telegra.ph{media_upload[0]}'
await send_message.edit(
telegraph_link
)
except:
pass
@telegraphbot.on_message(filters.text & filters.incoming)
async def text_handler(c, m):
"""Creating instant view link
by creating post in telegra.ph
and sending photo link to user"""
try:
short_name = "Ns Bots"
new_user = Telegraph().create_account(short_name=short_name)
auth_url = new_user["auth_url"]
title = m.from_user.first_name
content = m.text
if '|' in m.text:
content, title = m.text.split('|')
content = content.replace("\n", "<br>")
author_url = f'https://telegram.dog/{m.from_user.username}' if m.from_user.id else None
try:
response = Telegraph().create_page(
title=title,
html_content=content,
author_name=str(m.from_user.first_name),
author_url=author_url
)
except Exception as e:
print(e)
await m.reply_text("https://telegra.ph/{}".format(response["path"]))
except:
pass
telegraphbot.run()