-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
main.py
137 lines (116 loc) · 3.74 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
import os
import requests
from dotenv import load_dotenv
from gofile import uploadFile
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
load_dotenv()
Bot = Client(
"GoFile-Bot",
bot_token=os.environ.get("BOT_TOKEN"),
api_id=int(os.environ.get("API_ID")),
api_hash=os.environ.get("API_HASH")
)
INSTRUCTIONS = """
I am a gofile uploader telegram bot. \
You can upload files to gofile.io with command.
With media:
Normal:
`/upload`
With token:
`/upload token`
With folder id:
`/upload token folderid`
Using Link:
Normal:
`/upload url`
With token:
`/upload url token`
With folder id:
`/upload url token folderid`
"""
@Bot.on_message(filters.private & filters.command("start"))
async def start(bot, update):
await update.reply_text(
text=f"Hello {update.from_user.mention}," + INSTRUCTIONS,
disable_web_page_preview=True,
quote=True
)
@Bot.on_message(filters.private & filters.command("upload"))
async def filter(bot, update):
message = await update.reply_text(
text="`Processing...`",
quote=True,
disable_web_page_preview=True
)
text = update.text.replace("\n", " ")
url = None
token = None
folderId = None
if " " in text:
text = text.split(" ", 1)[1]
if update.reply_to_message:
if " " in text:
token, folderId = text.split(" ", 1)
else:
token = text
else:
if " " in text:
if len(text.split()) > 2:
url, token, folderId = text.split(" ", 2)
else:
url, token = text.split()
else:
url = text
if not (url.startswith("http://") or url.startswith("https://")):
await message.edit_text("Error :- `url is wrong`")
return
elif not update.reply_to_message:
await message.edit_text("Error :- `downloadable media or url not found`")
return
try:
await message.edit_text("`Downloading...`")
if url:
response = requests.get(url)
media = response.url.split("/", -1)[-1]
with open(media, "wb") as file:
file.write(response.content)
else:
media = await update.reply_to_message.download()
await message.edit_text("`Downloaded Successfully`")
await message.edit_text("`Uploading...`")
response = uploadFile(file=media, token=token, folderId=folderId)
await message.edit_text("`Uploading Successfully`")
try:
os.remove(file)
except Exception as error:
print(error)
except Exception as error:
await message.edit_text(f"Error :- `{error}`")
return
text = f"**File Name:** `{response['fileName']}`" + "\n"
text += f"**File ID:** `{response['fileId']}`" + "\n"
text += f"**Code:** `{response['code']}`" + "\n"
text += f"**md5:** `{response['md5']}`" + "\n"
text += f"**Download Page:** `{response['downloadPage']}`"
link = response['downloadPage']
reply_markup = InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="Open Link", url=link),
InlineKeyboardButton(
text="Share Link", url=f"https://telegram.me/share/url?url={link}")
],
[
InlineKeyboardButton(
text="Feedback", url="https://telegram.me/FayasNoushad")
]
]
)
await message.edit_text(
text=text,
reply_markup=reply_markup,
disable_web_page_preview=True
)
Bot.run()