-
Notifications
You must be signed in to change notification settings - Fork 3
/
DTbot.py
147 lines (138 loc) · 5.81 KB
/
DTbot.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
import os
import logging
from pyrogram import Client, filters
from telegraph import upload_file
from config import Config
from pyrogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
DTbot = Client(
"Telegraph Uploader",
api_id=Config.APP_ID,
api_hash=Config.API_HASH,
bot_token=Config.TG_BOT_TOKEN,
)
@DTbot.on_message(filters.command("start"))
async def start(client, message):
if message.chat.type == 'private':
await DTbot.send_message(
chat_id=message.chat.id,
text="""<b>Hey There, I'm Telegraph Bot
I can upload photos or videos to telegraph. Made by @Damantha_Jasinghe 🇱🇰
Hit help button to find out more about how to use me</b>""",
reply_markup=InlineKeyboardMarkup(
[[
InlineKeyboardButton(
"Help", callback_data="help"),
InlineKeyboardButton(
"Suppor Group", url="https://t.me/AnkiSupport_Official")
],[
InlineKeyboardButton(
"Updates", url="https://t.me/ankivectorUpdates")
]]
),
disable_web_page_preview=True,
parse_mode="html")
@DTbot.on_message(filters.command("help"))
async def help(client, message):
if message.chat.type == 'private':
await DTbot.send_message(
chat_id=message.chat.id,
text="""<b>Telegraph Bot Help!
Just send a photo or video less than 5mb file size, I'll upload it to telegraph.
~ @ankivectorUpdates</b>""",
reply_markup=InlineKeyboardMarkup(
[[
InlineKeyboardButton(
"Back", callback_data="start"),
InlineKeyboardButton(
"About", callback_data="about"),
],[
InlineKeyboardButton(
"Updates", url="https://t.me/ankivectorUpdates")
]]
),
disable_web_page_preview=True,
parse_mode="html")
@DTbot.on_message(filters.command("about"))
async def about(client, message):
if message.chat.type == 'private':
await DTbot.send_message(
chat_id=message.chat.id,
text="""<b>About Telegraph Bot!</b>
<b>♞ Developer:</b> <a href="https://t.me/Damantha_Jasinghe">Damantha 🇱🇰</a>
<b>♞ Support:</b> <a href="https://t.me/AnkiSupport_Official">Anki Vector Support</a>
<b>♞ Library:</b> <a href="https://github.com/pyrogram/pyrogram">Pyrogram</a>
<b>~ @ankivectorUpdates</b>""",
reply_markup=InlineKeyboardMarkup(
[[
InlineKeyboardButton(
"Back", callback_data="help"),
InlineKeyboardButton(
"Support Group", url="https://t.me/AnkiSupport_Official")
]]
),
disable_web_page_preview=True,
parse_mode="html")
@DTbot.on_message(filters.photo)
async def telegraphphoto(client, message):
msg = await message.reply_text("Uploading To Telegraph...")
download_location = await client.download_media(
message=message, file_name='root/jetg')
try:
response = upload_file(download_location)
except:
await msg.edit_text("Photo size should be less than 5mb!")
else:
await msg.edit_text(f'**Uploaded To Telegraph!\n\n👉 https://telegra.ph{response[0]}\n\nJoin @ankivectorUpdates**',
disable_web_page_preview=True,
)
finally:
os.remove(download_location)
@DTbot.on_message(filters.video)
async def telegraphvid(client, message):
msg = await message.reply_text("Uploading To Telegraph...")
download_location = await client.download_media(
message=message, file_name='root/jetg')
try:
response = upload_file(download_location)
except:
await msg.edit_text("Video size should be less than 5mb!")
else:
await msg.edit_text(f'**Uploaded To Telegraph!\n\n👉 https://telegra.ph{response[0]}\n\nJoin @ankivectorUpdates**',
disable_web_page_preview=True,
)
finally:
os.remove(download_location)
@DTbot.on_message(filters.animation)
async def telegraphgif(client, message):
msg = await message.reply_text("Uploading To Telegraph...")
download_location = await client.download_media(
message=message, file_name='root/jetg')
try:
response = upload_file(download_location)
except:
await msg.edit_text("Gif size should be less than 5mb!")
else:
await msg.edit_text(f'**Uploaded To Telegraph!\n\n👉 https://telegra.ph{response[0]}\n\nJoin @ankivectorUpdates**',
disable_web_page_preview=True,
)
finally:
os.remove(download_location)
@DTbot.on_callback_query()
async def button(bot, update):
cb_data = update.data
if "help" in cb_data:
await update.message.delete()
await help(bot, update.message)
elif "about" in cb_data:
await update.message.delete()
await about(bot, update.message)
elif "start" in cb_data:
await update.message.delete()
await start(bot, update.message)
print(
"""
Bot Started!
Join @ankivectorUpdates 🆗
"""
)
DTbot.run()