-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbot.py
More file actions
210 lines (186 loc) Β· 7.75 KB
/
bot.py
File metadata and controls
210 lines (186 loc) Β· 7.75 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import os
from dotenv import load_dotenv
from pyrogram import Client, filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
import random
import aiohttp
import asyncio
import logging
from flask import Flask
from threading import Thread
import time
load_dotenv()
# ===== WOODcraft ==== SudoR2spr ====
API_ID = int(os.getenv("API_ID"))
API_HASH = os.getenv("API_HASH")
BOT_TOKEN = os.getenv("BOT_TOKEN")
if not API_ID or not API_HASH or not BOT_TOKEN:
raise ValueError("API_ID, API_HASH, and BOT_TOKEN must be set.")
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
bot = Client("gofile_uploader_bot", api_id=int(API_ID), api_hash=API_HASH, bot_token=BOT_TOKEN)
def human_readable_size(size, decimal_places=2):
for unit in ['B', 'KB', 'MB', 'GB', 'TB']:
if size < 1024.0:
return f"{size:.{decimal_places}f} {unit}"
size /= 1024.0
return f"{size:.{decimal_places}f} PB"
async def progress(current, total, message, status_message, start_time, file_name):
now = time.time()
diff = now - start_time or 1
percentage = current * 100 / total
speed = current / diff
eta = (total - current) / speed
progress_str = "β«·{0}{1}β«Έ".format(
''.join(["β" for _ in range(int(percentage // 10))]),
''.join(["β" for _ in range(10 - int(percentage // 10))])
)
text = (
f"**π File:** `{file_name}`\n"
f"**π¦ Size:** `{human_readable_size(total)}`\n\n"
f"**β¬οΈ Downloading...**\n"
f"{progress_str} `{percentage:.2f}%`\n"
f"**β‘ Speed:** `{human_readable_size(speed)}/s`\n"
f"**β±οΈ ETA:** `{int(eta)}s`"
)
try:
await status_message.edit(text)
except:
pass
async def get_random_server():
try:
async with aiohttp.ClientSession() as session:
async with session.get("https://api.gofile.io/servers") as response:
data = await response.json()
servers = data['data']['servers']
return random.choice(servers)['name']
except Exception as e:
logger.error(f"Error getting server: {e}")
raise
async def upload_to_gofile(file_path):
try:
server = await get_random_server()
upload_url = f"https://{server}.gofile.io/uploadFile"
async with aiohttp.ClientSession() as session:
with open(file_path, 'rb') as f:
data = aiohttp.FormData()
data.add_field('file', f, filename=os.path.basename(file_path))
async with session.post(upload_url, data=data) as response:
result = await response.json()
return result["data"]["downloadPage"]
except Exception as e:
logger.error(f"Upload error: {e}")
raise
@bot.on_message(filters.document | filters.video | filters.audio)
async def handle_file(client, message):
file = message.document or message.video or message.audio
file_name = file.file_name
file_size = file.file_size
status = await message.reply(f"π₯ **Processing File**\n\n"
f"π **Name:** `{file_name}`\n"
f"π¦ **Size:** `{human_readable_size(file_size)}`\n\n"
"βοΈ Starting download...")
if file_size > 4 * 1024 * 1024 * 1024:
await status.edit("β File too large. Limit is 4GB.")
return
start_time = time.time()
file_path = await message.download(progress=progress, progress_args=(message, status, start_time, file_name))
await status.edit(f"π€ **Uploading to GoFile**\n\n"
f"π **File:** `{file_name}`\n"
f"π¦ **Size:** `{human_readable_size(file_size)}`\n\n"
"β³ Please wait...")
try:
link = await upload_to_gofile(file_path)
await status.edit(
f"β
**Upload Complete!**\n\n"
f"π **File:** `{file_name}`\n"
f"π¦ **Size:** `{human_readable_size(file_size)}`\n\n"
f"π **Download Link:** [Click Here]({link})\n\n"
"π Powered by @Opleech_WD",
disable_web_page_preview=True,
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("π₯ Download Now", url=link)],
[InlineKeyboardButton("π’ Updates Channel", url="https://t.me/Opleech_WD")]
])
)
except Exception as e:
await status.edit(f"β Upload failed: `{e}`")
finally:
os.remove(file_path)
# START COMMAND WITH IMAGE AND BUTTON
@bot.on_message(filters.command("start"))
async def start(client, message):
image_url = "https://graph.org/file/4e8a1172e8ba4b7a0bdfa.jpg" # Customize your own image
caption = (
"**Welcome to GoFile Uploader Bot!**\n\n"
"Just send me any file (video, audio, or document) and I'll upload it to GoFile.\n\n"
"β‘ Max file size: 4GB\n"
"β
Fast & Free\n\n"
"__Powered by @Opleech_WD__"
)
keyboard = InlineKeyboardMarkup([
[InlineKeyboardButton("π’ Updates Channel", url="https://t.me/Opleech_WD")],
[InlineKeyboardButton("π€ How to Use", callback_data="help")]
])
await message.reply_photo(photo=image_url, caption=caption, reply_markup=keyboard)
# HELP CALLBACK HANDLER
@bot.on_callback_query(filters.regex("^help$"))
async def help_callback(client, callback_query):
help_text = (
"**π GoFile Uploader Bot Help**\n\n"
"1. **Upload Files:**\n"
" - Maximum file size: 4GB\n"
" - Supported file types: Videos, Audios, Documents\n\n"
"2. **Process:**\n"
" - File download progress will be shown with progress bar\n"
" - You'll get download link after upload completes\n\n"
"3. **Privacy:**\n"
" - Uploaded files are private (only accessible via the link you share)\n\n"
"4. **Features:**\n"
" - Real-time upload/download progress\n"
" - File size and name displayed\n"
" - Fast download links\n\n"
"β οΈ **Important Notes:**\n"
" - Large files may take longer to upload\n"
" - Keep stable internet connection during upload\n"
" - Files are automatically deleted after 10 days of inactivity (GoFile policy)\n\n"
"For support contact: @Opleech_WD\n\n"
"π **Powered by @Opleech_WD**"
)
await callback_query.message.edit(
text=help_text,
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("π Back", callback_data="back_to_start")],
[InlineKeyboardButton("π’ Updates Channel", url="https://t.me/Opleech_WD")]
]),
disable_web_page_preview=True
)
# BACK TO START CALLBACK HANDLER
@bot.on_callback_query(filters.regex("^back_to_start$"))
async def back_to_start(client, callback_query):
image_url = "https://graph.org/file/4e8a1172e8ba4b7a0bdfa.jpg"
caption = (
"**Welcome to GoFile Uploader Bot!**\n\n"
"Just send me any file (video, audio, or document) and I'll upload it to GoFile.\n\n"
"β‘ Max file size: 4GB\n"
"β
Fast & Free\n\n"
"__Powered by @Opleech_WD__"
)
await callback_query.message.delete()
await callback_query.message.reply_photo(
photo=image_url,
caption=caption,
reply_markup=InlineKeyboardMarkup([
[InlineKeyboardButton("π’ Updates Channel", url="https://t.me/Opleech_WD")],
[InlineKeyboardButton("π€ How to Use", callback_data="help")]
])
)
# FLASK SERVER TO KEEP ALIVE
def run():
app = Flask(__name__)
@app.route('/')
def home():
return 'Bot is alive!'
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
Thread(target=run).start()
bot.run()