forked from FayasNoushad/Telegraph-Uploader-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
163 lines (134 loc) · 4.44 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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import os
from telegraph import upload_file
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
Bot = Client(
"Telegraph Uploader Bot",
bot_token=os.environ.get("BOT_TOKEN"),
api_id=int(os.environ.get("API_ID")),
api_hash=os.environ.get("API_HASH")
)
DOWNLOAD_LOCATION = os.environ.get("DOWNLOAD_LOCATION", "./DOWNLOADS/")
START_TEXT = """Hello {},
I am an under 5MB media or file to telegra.ph link uploader bot.
Made by @FayasNoushad"""
HELP_TEXT = """**About Me**
- Just give me a media under 5MB
- Then I will download it
- I will then upload it to the telegra.ph link
"""
ABOUT_TEXT = """**About Me**
- **Bot :** `Telegraph Uploader`
- **Developer :**
• [GitHub](https://github.com/FayasNoushad)
• [Telegram](https://telegram.me/FayasNoushad)
- **Source :** [Click here](https://github.com/FayasNoushad/Telegraph-Uploader-Bot)
- **Language :** [Python3](https://python.org)
- **Library :** [Pyrogram](https://pyrogram.org)"""
START_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Feedback', url='https://telegram.me/FayasNoushad')
],
[
InlineKeyboardButton('Help', callback_data='help'),
InlineKeyboardButton('About', callback_data='about'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
HELP_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Home', callback_data='home'),
InlineKeyboardButton('About', callback_data='about'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
ABOUT_BUTTONS = InlineKeyboardMarkup(
[
[
InlineKeyboardButton('Home', callback_data='home'),
InlineKeyboardButton('Help', callback_data='help'),
InlineKeyboardButton('Close', callback_data='close')
]
]
)
@Bot.on_callback_query()
async def cb_data(bot, update):
if update.data == "home":
await update.message.edit_text(
text=START_TEXT.format(update.from_user.mention),
disable_web_page_preview=True,
reply_markup=START_BUTTONS
)
elif update.data == "help":
await update.message.edit_text(
text=HELP_TEXT,
disable_web_page_preview=True,
reply_markup=HELP_BUTTONS
)
elif update.data == "about":
await update.message.edit_text(
text=ABOUT_TEXT,
disable_web_page_preview=True,
reply_markup=ABOUT_BUTTONS
)
else:
await update.message.delete()
@Bot.on_message(filters.private & filters.command(["start"]))
async def start(bot, update):
await update.reply_text(
text=START_TEXT.format(update.from_user.mention),
disable_web_page_preview=True,
quote=True,
reply_markup=START_BUTTONS
)
@Bot.on_message(filters.private & filters.media)
async def getmedia(bot, update):
medianame = DOWNLOAD_LOCATION + str(update.from_user.id)
try:
message = await update.reply_text(
text="`Processing...`",
quote=True,
disable_web_page_preview=True
)
await bot.download_media(
message=update,
file_name=medianame
)
response = upload_file(medianame)
try:
os.remove(medianame)
except:
pass
except Exception as error:
text=f"Error :- <code>{error}</code>"
reply_markup=InlineKeyboardMarkup(
[[InlineKeyboardButton('More Help', callback_data='help')]]
)
await message.edit_text(
text=text,
disable_web_page_preview=True,
reply_markup=reply_markup
)
return
text=f"**Link :-** `https://telegra.ph{response[0]}`\n\n**Join :-** @FayasNoushad"
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(text="Open Link", url=f"https://telegra.ph{response[0]}"),
InlineKeyboardButton(text="Share Link", url=f"https://telegram.me/share/url?url=https://telegra.ph{response[0]}")
],
[
InlineKeyboardButton(text="Join Updates Channel", url="https://telegram.me/FayasNoushad")
]
]
)
await message.edit_text(
text=text,
disable_web_page_preview=True,
reply_markup=reply_markup
)
Bot.run()