Files changed (4) hide show
  1. Dockerfile +0 -21
  2. README.md +0 -1
  3. main.py +0 -330
  4. requirements.txt +0 -5
Dockerfile DELETED
@@ -1,21 +0,0 @@
1
- FROM python:3.9
2
-
3
- # Video Rendering ke liye FFmpeg install kar rahe hain
4
- RUN apt-get update && \
5
- apt-get install -y ffmpeg git && \
6
- rm -rf /var/lib/apt/lists/*
7
-
8
- WORKDIR /app
9
-
10
- # Permissions set kar rahe hain taaki downloading/uploading mein error na aaye
11
- RUN chmod 777 /app
12
-
13
- COPY requirements.txt .
14
- RUN pip install --no-cache-dir -r requirements.txt
15
-
16
- COPY . .
17
-
18
- # Hugging Face ke liye port 7860 khol rahe hain
19
- EXPOSE 7860
20
-
21
- CMD ["python", "main.py"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md CHANGED
@@ -6,6 +6,5 @@ colorTo: yellow
6
  sdk: docker
7
  pinned: false
8
  ---
9
- p
10
 
11
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
6
  sdk: docker
7
  pinned: false
8
  ---
 
9
 
10
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
main.py DELETED
@@ -1,330 +0,0 @@
1
- import os
2
- import time
3
- import uuid
4
- import asyncio
5
- import threading
6
- import logging
7
- from flask import Flask, redirect, request, jsonify
8
- from flask_cors import CORS
9
- from pyrogram import Client, filters, idle
10
- from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton
11
- from huggingface_hub import HfApi
12
-
13
- # --- LOGGING ---
14
- logging.basicConfig(level=logging.INFO)
15
- logger = logging.getLogger("Rajasthan_Bot")
16
-
17
- # --- ENV VARIABLES ---
18
- def get_clean_var(name):
19
- val = os.environ.get(name, "")
20
- return val.strip() if val else ""
21
-
22
- API_ID = get_clean_var("API_ID")
23
- API_HASH = get_clean_var("API_HASH")
24
- BOT_TOKEN = get_clean_var("BOT_TOKEN")
25
- SESSION_STRING = get_clean_var("SESSION_STRING")
26
- HF_TOKEN = get_clean_var("HF_TOKEN")
27
- HF_REPO = get_clean_var("HF_REPO")
28
- ACCESS_PASSWORD = get_clean_var("PASSWORD") or "Maharaja Jaswant Singh"
29
-
30
- SPACE_HOST = os.environ.get("SPACE_HOST", "localhost:7860")
31
- BASE_URL = f"https://{SPACE_HOST}"
32
-
33
- # --- FLASK SERVER ---
34
- app = Flask(__name__)
35
- CORS(app)
36
-
37
- @app.route('/')
38
- def home():
39
- return "Rajasthan Bot System Online 🟢"
40
-
41
- @app.route('/rajasthan/<path:filename>')
42
- def serve_file(filename):
43
- real_link = f"https://huggingface.co/datasets/{HF_REPO}/resolve/main/{filename}?download=true"
44
- return redirect(real_link, code=302)
45
-
46
- # --- NEW UPLOAD API FOR ADMIN PANEL ---
47
- @app.route('/api/upload', methods=['POST'])
48
- def api_upload():
49
- if 'file' not in request.files:
50
- return jsonify({"error": "No file uploaded"}), 400
51
-
52
- file = request.files['file']
53
- if file.filename == '':
54
- return jsonify({"error": "Empty file"}), 400
55
-
56
- unique_id = uuid.uuid4().hex[:5]
57
- ext = file.filename.split('.')[-1] if '.' in file.filename else 'pdf'
58
- filename = f"Rajasthan_Admin_{unique_id}.{ext}"
59
- save_path = f"./{filename}"
60
-
61
- try:
62
- file.save(save_path)
63
- api = HfApi(token=HF_TOKEN)
64
- api.upload_file(
65
- path_or_fileobj=save_path,
66
- path_in_repo=filename,
67
- repo_id=HF_REPO,
68
- repo_type="dataset"
69
- )
70
- # JITENDRA BOT LINK: सीधा डाउनलोड होने वाली लिंक (Bot वाली)
71
- final_link = f"{BASE_URL}/rajasthan/{filename}"
72
-
73
- if os.path.exists(save_path): os.remove(save_path)
74
- return jsonify({"success": True, "file_url": final_link})
75
- except Exception as e:
76
- if os.path.exists(save_path): os.remove(save_path)
77
- return jsonify({"error": str(e)}), 500
78
-
79
- def run_web_server():
80
- app.run(host="0.0.0.0", port=7860)
81
-
82
- # --- HELPERS ---
83
- def humanbytes(size):
84
- if not size: return "0 B"
85
- power = 2**10
86
- n = 0
87
- power_labels = {0 : '', 1: 'KB', 2: 'MB', 3: 'GB', 4: 'TB'}
88
- while size > power:
89
- size /= power
90
- n += 1
91
- return f"{size:.2f} {power_labels[n]}"
92
-
93
- # --- GLOBAL VARS ---
94
- process_lock = asyncio.Lock()
95
- AUTH_USERS = set()
96
- USERBOT_ALIVE = False
97
-
98
- # --- CLIENTS ---
99
- if not API_ID or not BOT_TOKEN:
100
- print("❌ ERROR: API_ID ya BOT_TOKEN missing hai!")
101
- exit(1)
102
-
103
- try:
104
- API_ID = int(API_ID)
105
- except:
106
- print("❌ ERROR: API_ID number hona chahiye.")
107
- exit(1)
108
-
109
- bot = Client("main_bot", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN)
110
-
111
- userbot = None
112
- if SESSION_STRING:
113
- userbot = Client("user_bot", api_id=API_ID, api_hash=API_HASH, session_string=SESSION_STRING)
114
-
115
- # --- PROGRESS ---
116
- async def progress(current, total, message, start_time, status_text):
117
- now = time.time()
118
- diff = now - start_time
119
- if round(diff % 5.00) == 0 or current == total:
120
- percentage = current * 100 / total
121
- speed = current / diff if diff > 0 else 0
122
- try:
123
- await message.edit(
124
- f"{status_text}\n"
125
- f"━━━━━━━━━━━━━━━━━━\n"
126
- f"📊 **Progress:** {percentage:.1f}%\n"
127
- f"💾 **Done:** {humanbytes(current)} / {humanbytes(total)}\n"
128
- f"⚡ **Speed:** {humanbytes(speed)}/s"
129
- )
130
- except:
131
- pass
132
-
133
- # --- PROCESS LOGIC ---
134
- async def process_media(client, media_msg, status_msg, user_request_msg):
135
- unique_id = uuid.uuid4().hex[:5]
136
-
137
- media = media_msg.video or media_msg.audio or media_msg.photo or media_msg.document
138
- file_size_bytes = getattr(media, "file_size", 0)
139
- readable_size = humanbytes(file_size_bytes)
140
-
141
- if media_msg.video:
142
- ext = "mp4"
143
- name_type = "Video"
144
- elif media_msg.audio:
145
- ext = "mp3"
146
- name_type = "Music"
147
- elif media_msg.photo:
148
- ext = "jpg"
149
- name_type = "Image"
150
- elif media_msg.document:
151
- try: ext = media_msg.document.file_name.split(".")[-1]
152
- except: ext = "pdf"
153
- name_type = "File"
154
- else:
155
- ext = "file"
156
- name_type = "File"
157
-
158
- filename = f"Rajasthan_{name_type}_{unique_id}.{ext}"
159
- save_path = f"./{filename}"
160
-
161
- try:
162
- start = time.time()
163
- await status_msg.edit(f"⬇️ **Downloading...**\n`{filename}`")
164
-
165
- await client.download_media(
166
- message=media_msg,
167
- file_name=save_path,
168
- progress=progress,
169
- progress_args=(status_msg, start, "⬇️ **Downloading (Userbot)...**")
170
- )
171
-
172
- await status_msg.edit("☁️ **Uploading to Cloud...**")
173
- api = HfApi(token=HF_TOKEN)
174
- await asyncio.to_thread(
175
- api.upload_file,
176
- path_or_fileobj=save_path,
177
- path_in_repo=filename,
178
- repo_id=HF_REPO,
179
- repo_type="dataset"
180
- )
181
-
182
- # JITENDRA BOT LINK: सीधा डाउनलोड होने वाली लिंक (Bot वाली)
183
- final_link = f"{BASE_URL}/rajasthan/{filename}"
184
-
185
- await status_msg.delete()
186
-
187
- hyperlink_text = f"[{filename}]({final_link})"
188
-
189
- await user_request_msg.reply_text(
190
- f"⚡ **GENERATED SUCCESSFULLY**\n"
191
- f"━━━━━━━━━━━━━━━━━━\n"
192
- f"📂 **File:** {hyperlink_text}\n"
193
- f"💾 **Size:** `{readable_size}`\n"
194
- f"━━━━━━━━━━━━━━━━━━\n"
195
- f"🔗 **Link:** `{final_link}`",
196
- disable_web_page_preview=True,
197
- reply_markup=InlineKeyboardMarkup([
198
- [InlineKeyboardButton("🚀 One Click Download", url=final_link)]
199
- ])
200
- )
201
-
202
- except Exception as e:
203
- logger.error(f"Error: {e}")
204
- await status_msg.edit(f"❌ **Error:** {str(e)}")
205
-
206
- finally:
207
- if os.path.exists(save_path): os.remove(save_path)
208
-
209
- # --- HANDLERS ---
210
- @bot.on_message(filters.command("start"))
211
- async def start(c, m):
212
- if m.from_user.id in AUTH_USERS:
213
- await m.reply_text("👋 **Welcome Back!**")
214
- else:
215
- await m.reply_text("🔒 **Access Denied!** Enter Password.")
216
-
217
- @bot.on_message(filters.private & filters.text)
218
- async def text_handler(c, m):
219
- if m.from_user.id not in AUTH_USERS:
220
- if m.text == ACCESS_PASSWORD:
221
- AUTH_USERS.add(m.from_user.id)
222
- await m.reply_text("🔓 **Access Granted!**")
223
- else:
224
- await m.reply_text("❌ **Wrong Password!**")
225
- return
226
-
227
- if "t.me/" in m.text:
228
- if not userbot or not USERBOT_ALIVE: return await m.reply_text("⚠️ **Userbot Error.**")
229
- if process_lock.locked(): return await m.reply_text("⚠️ **Queue Full.**")
230
-
231
- async with process_lock:
232
- status = await m.reply_text("🔎 **Deep Scanning (Range: 100)...**")
233
- try:
234
- # 1. Clean Link
235
- link = m.text.strip().replace("https://", "").replace("http://", "")
236
- if "t.me/" in link: link = link.split("t.me/")[1]
237
-
238
- parts = link.split("/")
239
-
240
- if parts[0] == "c":
241
- chat_id = int("-100" + parts[1]) # Private
242
- else:
243
- chat_id = parts[0] # Public Username
244
-
245
- start_msg_id = int(parts[-1].split("?")[0])
246
-
247
- print(f"DEBUG: Chat: {chat_id}, Start ID: {start_msg_id}")
248
-
249
- # 2. DEEP SCAN: Check Start ID + Next 100 messages
250
- # Topic ID gaps can be huge in busy groups
251
-
252
- target_msg = None
253
- found_at_id = 0
254
- check_limit = 100 # Increased from 10 to 100
255
-
256
- try:
257
- messages = await userbot.get_messages(chat_id, range(start_msg_id, start_msg_id + check_limit))
258
- except Exception as e:
259
- return await status.edit(f"❌ **Scan Error:** {e}")
260
-
261
- if not isinstance(messages, list):
262
- messages = [messages]
263
-
264
- for msg in messages:
265
- if msg:
266
- # Check 1: Direct Media
267
- if msg.media and not msg.web_page:
268
- target_msg = msg
269
- found_at_id = msg.id
270
- break
271
-
272
- # Check 2: If message is a Reply to a file
273
- if msg.reply_to_message and msg.reply_to_message.media:
274
- target_msg = msg.reply_to_message
275
- found_at_id = msg.reply_to_message.id
276
- break
277
-
278
- if not target_msg:
279
- return await status.edit(
280
- f"❌ **No Media Found in Range!**\n"
281
- f"Bot scanned from ID `{start_msg_id}` to `{start_msg_id + check_limit}`.\n\n"
282
- f"**Reason:** In Topic groups, Message IDs are shared across all topics. The file might be very far down.\n"
283
- f"👉 **Try:** Copy the link of the File itself, NOT the heading."
284
- )
285
-
286
- if found_at_id != start_msg_id:
287
- await status.edit(f"✅ **Found File at ID:** `{found_at_id}`\n(Scanned forward due to Topic gaps)\n\n⬇️ **Processing...**")
288
-
289
- await process_media(userbot, target_msg, status, m)
290
-
291
- except Exception as e:
292
- await status.edit(f"❌ **Error:** {e}")
293
-
294
- @bot.on_message(filters.private & (filters.document | filters.video | filters.audio | filters.photo))
295
- async def file_handler(c, m):
296
- if m.from_user.id not in AUTH_USERS: return await m.reply_text("🔒 **Password Required.**")
297
- if process_lock.locked(): return await m.reply_text("⚠️ **Queue Full.**")
298
-
299
- async with process_lock:
300
- status = await m.reply_text("⏳ **Added to Queue...**")
301
- await process_media(bot, m, status, m)
302
-
303
- # --- STARTUP ---
304
- async def main():
305
- threading.Thread(target=run_web_server, daemon=True).start()
306
-
307
- print("🚀 Bot Starting...")
308
- try:
309
- await bot.start()
310
- print("✅ Main Bot Connected Successfully!")
311
- except Exception as e:
312
- print(f"❌ Main Bot Start Error: {e}")
313
- return
314
-
315
- global USERBOT_ALIVE
316
- if userbot:
317
- try:
318
- await userbot.start()
319
- USERBOT_ALIVE = True
320
- print("✅ Userbot Connected!")
321
- except Exception as e:
322
- print(f"⚠️ Userbot Failed: {e}")
323
- USERBOT_ALIVE = False
324
-
325
- await idle()
326
- await bot.stop()
327
-
328
- if __name__ == "__main__":
329
- loop = asyncio.get_event_loop()
330
- loop.run_until_complete(main())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt DELETED
@@ -1,5 +0,0 @@
1
- pyrogram
2
- tgcrypto
3
- flask
4
- huggingface_hub
5
- flask-cors