Update app.py
Browse files
app.py
CHANGED
|
@@ -1,412 +1,105 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
โ
ุชุฎุฒูู ูู
ุฑุฉ ูุงุญุฏุฉ - ู
ุดุงุฑูุฉ ููุฃุจุฏ
|
| 5 |
-
โ
ู
ุญุฑู Playwright ูุชุฌุงูุฒ ุงูุญู
ุงูุงุช
|
| 6 |
-
"""
|
| 7 |
-
|
| 8 |
-
import os, time, threading, zipfile, io, re, json, telebot, requests
|
| 9 |
-
from flask import Flask
|
| 10 |
-
from playwright.sync_api import sync_playwright
|
| 11 |
-
from PIL import Image
|
| 12 |
from telebot import types
|
| 13 |
|
| 14 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 15 |
-
#
|
| 16 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 17 |
-
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN") # ุชููู ุงูุจูุช
|
| 18 |
-
ARCHIVE_CHANNEL = os.getenv("ARCHIVE_CHANNEL_ID") # ู
ุนุฑูู ููุงุฉ ุงูุฃุฑุดูู ู
ุซุงู: -1001234567890
|
| 19 |
-
ADMIN_HANDLE = os.getenv("ADMIN_HANDLE", "@svipfast") # ุญุณุงุจ ุงูู
ุทูุฑ
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
app = Flask(__name__)
|
| 23 |
|
| 24 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 25 |
-
#
|
| 26 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 27 |
|
| 28 |
-
|
| 29 |
-
archive_index: dict = {}
|
| 30 |
-
INDEX_MSG_ID: int | None = None # ู
ุนุฑูู ุฑุณุงูุฉ ุงูููุฑุณ ุงูู
ุซุจูุชุฉ
|
| 31 |
-
|
| 32 |
-
def _index_key(base_url: str, chapter: int) -> str:
|
| 33 |
-
return f"{base_url.rstrip('/')}|{chapter}"
|
| 34 |
-
|
| 35 |
-
# โโ ุชุญู
ูู ุงูููุฑุณ ุนูุฏ ุงูุจุฏุก โโโโโโโโโโโโโโโโโโ
|
| 36 |
-
def load_archive_index():
|
| 37 |
-
"""ูุญู
ูู ููุฑุณ ุงูุฃุฑุดูู ู
ู ุงูุฑุณุงูุฉ ุงูู
ุซุจูุชุฉ ูู ููุงุฉ ุงูุฃุฑุดูู."""
|
| 38 |
-
global archive_index, INDEX_MSG_ID
|
| 39 |
-
if not ARCHIVE_CHANNEL:
|
| 40 |
-
print("โ ๏ธ ARCHIVE_CHANNEL_ID ุบูุฑ ู
ุถุจูุทุ ุงูุฃุฑุดูู ู
ุนุทูู.")
|
| 41 |
-
return
|
| 42 |
-
try:
|
| 43 |
-
chat = bot.get_chat(ARCHIVE_CHANNEL)
|
| 44 |
-
if chat.pinned_message:
|
| 45 |
-
INDEX_MSG_ID = chat.pinned_message.message_id
|
| 46 |
-
# ุงูููุฑุณ ู
ุฎุฒูู ููุต JSON ูู ุงูุฑุณุงูุฉ ุงูู
ุซุจูุชุฉ
|
| 47 |
-
archive_index = json.loads(chat.pinned_message.text)
|
| 48 |
-
print(f"โ
ุชู
ุชุญู
ูู ุงูููุฑุณ: {len(archive_index)} ูุตู ู
ุคุฑุดู.")
|
| 49 |
-
else:
|
| 50 |
-
print("โน๏ธ ูุง ููุฌุฏ ููุฑุณ ู
ุซุจูุช ุจุนุฏุ ุณูููุดุฃ ุนูุฏ ุฃูู ุฃุฑุดูุฉ.")
|
| 51 |
-
except Exception as e:
|
| 52 |
-
print(f"โ ุฎุทุฃ ูู ุชุญู
ูู ุงูููุฑุณ: {e}")
|
| 53 |
-
|
| 54 |
-
# โโ ุญูุธ ุงูููุฑุณ ุจุนุฏ ูู ุฅุถุงูุฉ โโโโโโโโโโโโโโโโ
|
| 55 |
-
def save_archive_index():
|
| 56 |
-
"""ูุญูุธ ุงูููุฑุณ ุงูุญุงูู ูู ุฑุณุงูุฉ ู
ุซุจูุชุฉ ุจููุงุฉ ุงูุฃุฑุดูู."""
|
| 57 |
-
global INDEX_MSG_ID
|
| 58 |
-
if not ARCHIVE_CHANNEL:
|
| 59 |
-
return
|
| 60 |
-
try:
|
| 61 |
-
text = json.dumps(archive_index, ensure_ascii=False)
|
| 62 |
-
# ุญุฏ ุชูููุฌุฑุงู
ูููุต 4096 ุญุฑู - ููุณูู
ุฅุฐุง ุชุฌุงูุฒ ุงูุญุฏ
|
| 63 |
-
if len(text) > 4000:
|
| 64 |
-
# ุงุญุชูุงุท: ููุฑุณู ูู
ูู JSON ุจุฏูุงู ู
ู ูุต
|
| 65 |
-
file_bytes = io.BytesIO(text.encode())
|
| 66 |
-
file_bytes.name = "index.json"
|
| 67 |
-
msg = bot.send_document(ARCHIVE_CHANNEL, file_bytes, caption="#MANGA_INDEX")
|
| 68 |
-
# ูุฎุฒูู ููุท message_id ุงูุฃุฎูุฑ ููู
ูู ูู ุงูุฑุณุงูุฉ ุงูู
ุซุจูุชุฉ
|
| 69 |
-
if INDEX_MSG_ID:
|
| 70 |
-
bot.unpin_chat_message(ARCHIVE_CHANNEL, INDEX_MSG_ID)
|
| 71 |
-
bot.pin_chat_message(ARCHIVE_CHANNEL, msg.message_id)
|
| 72 |
-
INDEX_MSG_ID = msg.message_id
|
| 73 |
-
else:
|
| 74 |
-
if INDEX_MSG_ID:
|
| 75 |
-
bot.edit_message_text(text, ARCHIVE_CHANNEL, INDEX_MSG_ID)
|
| 76 |
-
else:
|
| 77 |
-
msg = bot.send_message(ARCHIVE_CHANNEL, text)
|
| 78 |
-
bot.pin_chat_message(ARCHIVE_CHANNEL, msg.message_id)
|
| 79 |
-
INDEX_MSG_ID = msg.message_id
|
| 80 |
-
except Exception as e:
|
| 81 |
-
print(f"โ ุฎุทุฃ ูู ุญูุธ ุงูููุฑุณ: {e}")
|
| 82 |
-
|
| 83 |
-
# โโ ุงูุจุญุซ ูู ุงูุฃุฑุดูู โโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 84 |
-
def search_archive(base_url: str, chapter: int) -> int | None:
|
| 85 |
-
"""ููุนูุฏ message_id ุงููุตู ุฅุฐุง ูุงู ู
ุคุฑุดูุงูุ ูุฅูุง None."""
|
| 86 |
-
return archive_index.get(_index_key(base_url, chapter))
|
| 87 |
-
|
| 88 |
-
# โโ ุฅุถุงูุฉ ูุตู ููุฃุฑุดูู โโโโโโโโโโโโโโโโโโโโโโโ
|
| 89 |
-
def add_to_archive(base_url: str, chapter: int, zip_bytes: bytes, filename: str) -> int | None:
|
| 90 |
-
"""ูุฑูุน ุงูู
ูู ูููุงุฉ ุงูุฃุฑุดูู ููุญุฏูุซ ุงูููุฑุณ."""
|
| 91 |
-
if not ARCHIVE_CHANNEL:
|
| 92 |
-
return None
|
| 93 |
-
try:
|
| 94 |
-
caption = (
|
| 95 |
-
f"๐ฆ <b>{filename}</b>\n"
|
| 96 |
-
f"๐ <code>{_index_key(base_url, chapter)}</code>\n"
|
| 97 |
-
f"๐
{time.strftime('%Y-%m-%d %H:%M')}"
|
| 98 |
-
)
|
| 99 |
-
file_io = io.BytesIO(zip_bytes)
|
| 100 |
-
file_io.name = filename
|
| 101 |
-
msg = bot.send_document(
|
| 102 |
-
ARCHIVE_CHANNEL, file_io,
|
| 103 |
-
caption=caption, parse_mode="HTML"
|
| 104 |
-
)
|
| 105 |
-
archive_index[_index_key(base_url, chapter)] = msg.message_id
|
| 106 |
-
save_archive_index()
|
| 107 |
-
print(f"โ
ุฃูุฑุดู ุงููุตู {chapter} ุจู message_id={msg.message_id}")
|
| 108 |
-
return msg.message_id
|
| 109 |
-
except Exception as e:
|
| 110 |
-
print(f"โ ุฎุทุฃ ูู ุงูุฃุฑุดูุฉ: {e}")
|
| 111 |
-
return None
|
| 112 |
-
|
| 113 |
-
# โโ ุฅุฑุณุงู ู
ู ุงูุฃุฑุดูู ู
ุจุงุดุฑุฉู โโโโโโโโโโโโโโโโ
|
| 114 |
-
def forward_from_archive(chat_id: int, message_id: int, chapter: int):
|
| 115 |
-
"""ููุนูุฏ ุชูุฌูู ุงูู
ูู ู
ู ุงูุฃุฑุดูู ููู
ุณุชุฎุฏู
."""
|
| 116 |
-
bot.forward_message(chat_id, ARCHIVE_CHANNEL, message_id)
|
| 117 |
|
| 118 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 119 |
-
#
|
| 120 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
browser = p.chromium.launch(headless=True)
|
| 126 |
-
context = browser.new_context(
|
| 127 |
-
user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
|
| 128 |
-
"(KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
| 129 |
-
)
|
| 130 |
-
page = context.new_page()
|
| 131 |
-
try:
|
| 132 |
-
page.goto(url, wait_until="networkidle", timeout=75000)
|
| 133 |
-
# ุงูุชู
ุฑูุฑ ุงูุชุฏุฑูุฌู ูุชุญู
ูู ุงูุตูุฑ ุงููุณููุฉ
|
| 134 |
-
for _ in range(6):
|
| 135 |
-
page.mouse.wheel(0, 1500)
|
| 136 |
-
time.sleep(0.9)
|
| 137 |
-
page.wait_for_timeout(2000)
|
| 138 |
-
|
| 139 |
-
images = page.query_selector_all("img")
|
| 140 |
-
img_list = []
|
| 141 |
-
seen_srcs = set()
|
| 142 |
-
|
| 143 |
-
for img in images:
|
| 144 |
-
src = (
|
| 145 |
-
img.get_attribute("src")
|
| 146 |
-
or img.get_attribute("data-src")
|
| 147 |
-
or img.get_attribute("data-lazy-src")
|
| 148 |
-
or img.get_attribute("data-original")
|
| 149 |
-
)
|
| 150 |
-
if not src or src in seen_srcs:
|
| 151 |
-
continue
|
| 152 |
-
# ุชุตููุฉ ุงูุตูุฑ ุงูุตุบูุฑุฉ ูุงูุดุนุงุฑุงุช
|
| 153 |
-
if not any(ext in src.lower() for ext in ['.jpg', '.jpeg', '.png', '.webp', '.avif']):
|
| 154 |
-
continue
|
| 155 |
-
if any(kw in src.lower() for kw in ['logo', 'banner', 'avatar', 'icon', 'thumb']):
|
| 156 |
-
continue
|
| 157 |
-
seen_srcs.add(src)
|
| 158 |
-
try:
|
| 159 |
-
res = page.request.get(src, timeout=20000)
|
| 160 |
-
if res.status == 200 and len(res.body()) > 20000:
|
| 161 |
-
img_list.append(Image.open(io.BytesIO(res.body())).convert('RGB'))
|
| 162 |
-
except:
|
| 163 |
-
continue
|
| 164 |
-
|
| 165 |
-
browser.close()
|
| 166 |
-
return img_list
|
| 167 |
-
except Exception as e:
|
| 168 |
-
print(f"โ ุฎุทุฃ ูู ุงูุฌูุจ: {e}")
|
| 169 |
-
browser.close()
|
| 170 |
-
return []
|
| 171 |
|
| 172 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 173 |
-
#
|
| 174 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
return
|
| 182 |
-
|
| 183 |
-
def images_to_zip_bytes(imgs: list, chapter: int) -> bytes | None:
|
| 184 |
-
"""ูุญููู ูุงุฆู
ุฉ ุงูุตูุฑ ุฅูู ู
ูู ZIP ูุญุชูู PDF."""
|
| 185 |
-
if not imgs:
|
| 186 |
-
return None
|
| 187 |
-
pdf_buf = io.BytesIO()
|
| 188 |
-
imgs[0].save(pdf_buf, format='PDF', save_all=True, append_images=imgs[1:])
|
| 189 |
-
zip_buf = io.BytesIO()
|
| 190 |
-
with zipfile.ZipFile(zip_buf, 'w', zipfile.ZIP_DEFLATED) as zf:
|
| 191 |
-
zf.writestr(f"Chapter_{chapter}.pdf", pdf_buf.getvalue())
|
| 192 |
-
return zip_buf.getvalue()
|
| 193 |
|
| 194 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 195 |
-
#
|
| 196 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 197 |
|
| 198 |
-
user_states: dict = {}
|
| 199 |
-
|
| 200 |
-
@app.route('/')
|
| 201 |
-
def home():
|
| 202 |
-
return "<h1>๐ Manga Engine Pro is Running</h1><p>Archive-powered manga bot.</p>"
|
| 203 |
-
|
| 204 |
-
# โโ /start โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 205 |
@bot.message_handler(commands=['start'])
|
| 206 |
-
def
|
| 207 |
-
|
| 208 |
-
markup
|
| 209 |
-
|
| 210 |
-
types.InlineKeyboardButton("๐ฅ ุฅุฑุณุงู ุฑุงุจุท ุฌุฏูุฏ", callback_data="new_order"),
|
| 211 |
-
types.InlineKeyboardButton("๐ ุฅุญุตุงุฆูุงุช ุงูุฃุฑุดูู", callback_data="stats"),
|
| 212 |
-
types.InlineKeyboardButton("๐ก ููู ุฃุญุตู ุนูู ุงูุฑุงุจุทุ", callback_data="help_link"),
|
| 213 |
-
types.InlineKeyboardButton("๐จโ๐ป ุงูู
ุทูุฑ", url=f"https://t.me/{ADMIN_HANDLE.replace('@','')}"),
|
| 214 |
-
)
|
| 215 |
bot.send_message(
|
| 216 |
message.chat.id,
|
| 217 |
-
f"
|
| 218 |
-
|
| 219 |
-
f"ุฅุฐุง ุทูุจุช ูุตูุงู ุณุจู ุณุญุจู ู
ู ูุจูุ ุณููุฑุณูู ูู ููุฑุงู โก\n\n"
|
| 220 |
-
f"ุงูู
ุทูุฑ: {ADMIN_HANDLE}",
|
| 221 |
-
parse_mode="HTML", reply_markup=markup
|
| 222 |
)
|
| 223 |
|
| 224 |
-
#
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
chat_id = call.message.chat.id
|
| 228 |
-
|
| 229 |
-
if call.data == "new_order":
|
| 230 |
-
msg = bot.send_message(chat_id, "๐ <b>ุฃุฑุณู ุฑุงุจุท ุงููุตู:</b>", parse_mode="HTML")
|
| 231 |
-
bot.register_next_step_handler(msg, process_url_step)
|
| 232 |
-
|
| 233 |
-
elif call.data == "stats":
|
| 234 |
-
total = len(archive_index)
|
| 235 |
-
bot.send_message(
|
| 236 |
-
chat_id,
|
| 237 |
-
f"๐ <b>ุฅุญุตุงุฆูุงุช ุงูุฃุฑุดูู</b>\n\n"
|
| 238 |
-
f"๐ฆ ุงููุตูู ุงูู
ุคุฑุดูุฉ: <b>{total}</b>\n"
|
| 239 |
-
f"โก ุฌุงูุฒุฉ ููุฅุฑุณุงู ุงูููุฑู",
|
| 240 |
-
parse_mode="HTML"
|
| 241 |
-
)
|
| 242 |
-
|
| 243 |
-
elif call.data == "help_link":
|
| 244 |
-
bot.send_message(
|
| 245 |
-
chat_id,
|
| 246 |
-
"<b>๐ก ุทุฑููุฉ ุฅุฑุณุงู ุงูุฑุงุจุท:</b>\n\n"
|
| 247 |
-
"ุงูุณุฎ ุฑุงุจุท ุฃู ูุตู ู
ู ุงูู
ููุน ู
ุจุงุดุฑุฉ:\n"
|
| 248 |
-
"<code>https://olympustaff.com/series/manga-name/1</code>\n\n"
|
| 249 |
-
"ุงูุจูุช ุณููุชุดู ุชููุงุฆูุงู ูู
ุท ุงูุฑูุงุจุท ููุณุญุจ ุจููุฉ ุงููุตูู ๐ฏ",
|
| 250 |
-
parse_mode="HTML"
|
| 251 |
-
)
|
| 252 |
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
"range": "๐ข ุฃุฑุณู <b>ุงูู
ุฏู</b> (ู
ุซุงู: <code>1-10</code>):",
|
| 259 |
-
"auto10": "๐ข ุฃุฑุณู <b>ุฑูู
ุงููุตู ุงูุฃูู</b> ูุณูุญู
ูู 10 ูุตูู ุชููุงุฆูุงู:",
|
| 260 |
-
}
|
| 261 |
-
msg = bot.send_message(chat_id, prompts.get(mode, "ุฃุฑุณู ุงูุฑูู
:"), parse_mode="HTML")
|
| 262 |
-
bot.register_next_step_handler(msg, final_execution_step)
|
| 263 |
|
| 264 |
-
|
|
|
|
|
|
|
| 265 |
|
| 266 |
-
|
| 267 |
-
def process_url_step(message):
|
| 268 |
url = message.text.strip()
|
| 269 |
-
if not url.startswith("http"):
|
| 270 |
-
bot.send_message(message.chat.id, "โ ุงูุฑุงุจุท ุบูุฑ ุตุญูุญ.")
|
| 271 |
-
return
|
| 272 |
-
user_states[message.chat.id] = {'url': url}
|
| 273 |
-
markup = types.InlineKeyboardMarkup(row_width=2)
|
| 274 |
-
markup.add(
|
| 275 |
-
types.InlineKeyboardButton("๐ฏ ูุตู ูุงุญุฏ", callback_data="mode_single"),
|
| 276 |
-
types.InlineKeyboardButton("๐ฆ ุญุฒู
ุฉ ูุตูู", callback_data="mode_range"),
|
| 277 |
-
types.InlineKeyboardButton("โฉ 10 ูุตูู ุชููุงุฆู", callback_data="mode_auto10"),
|
| 278 |
-
)
|
| 279 |
-
bot.send_message(
|
| 280 |
-
message.chat.id,
|
| 281 |
-
"โ
<b>ุงูุฑุงุจุท ู
ูุจูู! ุงุฎุชุฑ ุทุฑููุฉ ุงูุชุญู
ูู:</b>",
|
| 282 |
-
parse_mode="HTML", reply_markup=markup
|
| 283 |
-
)
|
| 284 |
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
chat_id = message.chat.id
|
| 288 |
-
state = user_states.get(chat_id, {})
|
| 289 |
-
|
| 290 |
-
if 'url' not in state:
|
| 291 |
-
bot.send_message(chat_id, "โ ๏ธ ุงูุชูุช ุงูุฌูุณุฉุ ุงุจุฏุฃ ู
ู /start")
|
| 292 |
-
return
|
| 293 |
-
|
| 294 |
-
text = message.text.strip()
|
| 295 |
-
mode = state['mode']
|
| 296 |
-
url = state['url']
|
| 297 |
-
base_url = re.sub(r'/(?:chapter-)?[\d]+$', '', url.strip().rstrip('/'))
|
| 298 |
-
|
| 299 |
-
try:
|
| 300 |
-
if mode == "single":
|
| 301 |
-
start = end = int(text)
|
| 302 |
-
elif mode == "range":
|
| 303 |
-
start, end = map(int, text.split('-'))
|
| 304 |
-
elif mode == "auto10":
|
| 305 |
-
start = int(text)
|
| 306 |
-
end = start + 9
|
| 307 |
-
else:
|
| 308 |
-
raise ValueError("mode unknown")
|
| 309 |
-
except:
|
| 310 |
-
bot.send_message(chat_id, "โ ๏ธ ุชูุณูู ุฎุงุทุฆ (ู
ุซุงู: 5 ุฃู 1-10)")
|
| 311 |
return
|
| 312 |
|
| 313 |
-
|
| 314 |
-
status_msg = bot.send_message(
|
| 315 |
-
chat_id,
|
| 316 |
-
f"๐ <b>ูุจุญุซ ูู ุงูุฃุฑุดูู...</b>\n๐ ุงููุตูู: {start} โ {end} ({count} ูุตู)",
|
| 317 |
-
parse_mode="HTML"
|
| 318 |
-
)
|
| 319 |
-
|
| 320 |
-
# โโ ุงูุจุญุซ ูู ุงูุฃุฑุดูู ุฃููุงู โโ
|
| 321 |
-
cached, missing = [], []
|
| 322 |
-
for ch in range(start, end + 1):
|
| 323 |
-
mid = search_archive(base_url, ch)
|
| 324 |
-
if mid:
|
| 325 |
-
cached.append((ch, mid))
|
| 326 |
-
else:
|
| 327 |
-
missing.append(ch)
|
| 328 |
-
|
| 329 |
-
# ุฅุฑุณุงู ุงููุตูู ุงูู
ุคุฑุดูุฉ ููุฑุงู
|
| 330 |
-
if cached:
|
| 331 |
-
bot.edit_message_text(
|
| 332 |
-
f"โก <b>ููุฌุฏ ูู ุงูุฃุฑุดูู {len(cached)} ูุตู!</b>\nููุฑุณูู ููุฑุงู...",
|
| 333 |
-
chat_id, status_msg.message_id, parse_mode="HTML"
|
| 334 |
-
)
|
| 335 |
-
for ch, mid in cached:
|
| 336 |
-
try:
|
| 337 |
-
forward_from_archive(chat_id, mid, ch)
|
| 338 |
-
time.sleep(0.4) # ุชูุงุฏู flood
|
| 339 |
-
except Exception as e:
|
| 340 |
-
print(f"Forward error ch{ch}: {e}")
|
| 341 |
-
|
| 342 |
-
# ุณุญุจ ุงููุตูู ุงููุงูุตุฉ
|
| 343 |
-
if missing:
|
| 344 |
-
bot.send_message(
|
| 345 |
-
chat_id,
|
| 346 |
-
f"๐ <b>ูุณุญุจ {len(missing)} ูุตู ุฌุฏูุฏ...</b>\n"
|
| 347 |
-
f"ุงููุตูู: {', '.join(map(str, missing))}",
|
| 348 |
-
parse_mode="HTML"
|
| 349 |
-
)
|
| 350 |
-
for ch in missing:
|
| 351 |
-
ch_url = build_chapter_url(url, ch)
|
| 352 |
-
bot.send_chat_action(chat_id, 'upload_document')
|
| 353 |
-
imgs = fetch_images_engine(ch_url)
|
| 354 |
-
if not imgs:
|
| 355 |
-
bot.send_message(chat_id, f"โ ุงููุตู {ch} ูู
ููุณุญุจ (ุชุญูู ู
ู ุงูุฑุงุจุท)")
|
| 356 |
-
continue
|
| 357 |
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
continue
|
| 361 |
|
| 362 |
-
|
| 363 |
|
| 364 |
-
|
| 365 |
-
archived_mid = add_to_archive(base_url, ch, zip_bytes, filename)
|
| 366 |
-
|
| 367 |
-
# โก ุงูุฅุฑุณุงู ููู
ุณุชุฎุฏู
ู
ู ุงูุฃุฑุดูู ุฃู ู
ุจุงุดุฑุฉ
|
| 368 |
-
if archived_mid:
|
| 369 |
-
forward_from_archive(chat_id, archived_mid, ch)
|
| 370 |
-
else:
|
| 371 |
-
# fallback: ุฅุฑุณุงู ู
ุจุงุดุฑ
|
| 372 |
-
f_io = io.BytesIO(zip_bytes)
|
| 373 |
-
f_io.name = filename
|
| 374 |
-
bot.send_document(
|
| 375 |
-
chat_id, f_io,
|
| 376 |
-
caption=f"๐ฆ ุงููุตู {ch}\n๐จโ๐ป {ADMIN_HANDLE}",
|
| 377 |
-
parse_mode="HTML"
|
| 378 |
-
)
|
| 379 |
-
time.sleep(0.5)
|
| 380 |
-
|
| 381 |
-
# ุฑุณุงูุฉ ุงูุงูุชูุงุก
|
| 382 |
-
summary = (
|
| 383 |
-
f"โ
<b>ุงูุชู
ู ุงูุชุญู
ูู!</b>\n\n"
|
| 384 |
-
f"โก ู
ู ุงูุฃุฑุดูู: {len(cached)}\n"
|
| 385 |
-
f"๐ ู
ุณุญูุจ ุฌุฏูุฏ: {len(missing)}\n"
|
| 386 |
-
f"๐จโ๐ป {ADMIN_HANDLE}"
|
| 387 |
-
)
|
| 388 |
-
bot.send_message(chat_id, summary, parse_mode="HTML")
|
| 389 |
-
try:
|
| 390 |
-
bot.delete_message(chat_id, status_msg.message_id)
|
| 391 |
-
except:
|
| 392 |
-
pass
|
| 393 |
|
| 394 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 395 |
-
#
|
| 396 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 397 |
|
| 398 |
if __name__ == "__main__":
|
| 399 |
-
print("
|
| 400 |
-
os.system("playwright install chromium")
|
| 401 |
|
| 402 |
-
|
| 403 |
-
|
| 404 |
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
| 410 |
|
| 411 |
-
|
| 412 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 1 |
+
import os, time, threading, zipfile, io, re, json
|
| 2 |
+
from flask import Flask, request
|
| 3 |
+
import telebot
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
from telebot import types
|
| 5 |
|
| 6 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 7 |
+
# โ๏ธ ุงูุฅุนุฏุงุฏุงุช
|
| 8 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
BOT_TOKEN = os.getenv("TELEGRAM_BOT_TOKEN")
|
| 11 |
+
ADMIN_HANDLE = os.getenv("ADMIN_HANDLE", "@svipfast")
|
| 12 |
+
|
| 13 |
+
bot = telebot.TeleBot(BOT_TOKEN)
|
| 14 |
app = Flask(__name__)
|
| 15 |
|
| 16 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 17 |
+
# ๐ง ุญุงูุฉ ุงูู
ุณุชุฎุฏู
|
| 18 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 19 |
|
| 20 |
+
user_states = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 23 |
+
# ๐ ุงูุตูุญุฉ ุงูุฑุฆูุณูุฉ
|
| 24 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 25 |
|
| 26 |
+
@app.route('/')
|
| 27 |
+
def home():
|
| 28 |
+
return "โ
Bot is running with Webhook"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 31 |
+
# ๐ Webhook endpoint
|
| 32 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 33 |
|
| 34 |
+
@app.route(f"/{BOT_TOKEN}", methods=["POST"])
|
| 35 |
+
def webhook():
|
| 36 |
+
json_str = request.stream.read().decode("utf-8")
|
| 37 |
+
update = telebot.types.Update.de_json(json_str)
|
| 38 |
+
bot.process_new_updates([update])
|
| 39 |
+
return "OK", 200
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 42 |
+
# ๐ /start
|
| 43 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
@bot.message_handler(commands=['start'])
|
| 46 |
+
def start(message):
|
| 47 |
+
markup = types.InlineKeyboardMarkup()
|
| 48 |
+
markup.add(types.InlineKeyboardButton("๐ฅ ุฅุฑุณุงู ุฑุงุจุท", callback_data="send_link"))
|
| 49 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
bot.send_message(
|
| 51 |
message.chat.id,
|
| 52 |
+
f"๐ ุฃููุงู ุจู!\n\nุฃุฑุณู ุฑุงุจุท ุงูู
ุงูุฌุง ูุณูุชู
ุณุญุจู.\n\n๐จโ๐ป {ADMIN_HANDLE}",
|
| 53 |
+
reply_markup=markup
|
|
|
|
|
|
|
|
|
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 57 |
+
# ๐ ุงูุฃุฒุฑุงุฑ
|
| 58 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
+
@bot.callback_query_handler(func=lambda call: True)
|
| 61 |
+
def handle_buttons(call):
|
| 62 |
+
if call.data == "send_link":
|
| 63 |
+
msg = bot.send_message(call.message.chat.id, "๐ ุฃุฑุณู ุงูุฑุงุจุท ุงูุขู:")
|
| 64 |
+
bot.register_next_step_handler(msg, process_link)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 67 |
+
# ๐ ู
ุนุงูุฌุฉ ุงูุฑุงุจุท
|
| 68 |
+
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 69 |
|
| 70 |
+
def process_link(message):
|
|
|
|
| 71 |
url = message.text.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
+
if not url.startswith("http"):
|
| 74 |
+
bot.send_message(message.chat.id, "โ ุงูุฑุงุจุท ุบูุฑ ุตุงูุญ")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
return
|
| 76 |
|
| 77 |
+
bot.send_message(message.chat.id, f"โ
ุชู
ุงุณุชูุงู
ุงูุฑุงุจุท:\n{url}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
|
| 79 |
+
# (ููุง ุชุถูู ู
ุญุฑู ุงูุณุญุจ ุงูุฎุงุต ุจู)
|
| 80 |
+
bot.send_message(message.chat.id, "โ๏ธ ุฌุงุฑู ุงูู
ุนุงูุฌุฉ...")
|
|
|
|
| 81 |
|
| 82 |
+
time.sleep(2)
|
| 83 |
|
| 84 |
+
bot.send_message(message.chat.id, "โ
ุชู
(ุชุฌุฑุจุฉ ููุท)")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 87 |
+
# ๐ ุงูุชุดุบูู
|
| 88 |
# โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 89 |
|
| 90 |
if __name__ == "__main__":
|
| 91 |
+
print("๐ Starting bot...")
|
|
|
|
| 92 |
|
| 93 |
+
# ุฑุงุจุท Space (ุบูุฑู!)
|
| 94 |
+
SPACE_URL = os.getenv("SPACE_URL")
|
| 95 |
|
| 96 |
+
if SPACE_URL:
|
| 97 |
+
webhook_url = f"{SPACE_URL}/{BOT_TOKEN}"
|
| 98 |
+
bot.remove_webhook()
|
| 99 |
+
time.sleep(1)
|
| 100 |
+
bot.set_webhook(url=webhook_url)
|
| 101 |
+
print(f"โ
Webhook set: {webhook_url}")
|
| 102 |
+
else:
|
| 103 |
+
print("โ ๏ธ ุถุน SPACE_URL ูู Secrets")
|
| 104 |
|
| 105 |
+
app.run(host="0.0.0.0", port=7860)
|
|
|