Download app.py from ALIOF213/ALOFTOp2: direct link, hf CLI and curl.
- Browser
- Download file 8.49 kB
-
https://huggingface.co/spaces/ALIOF213/ALOFTOp2/resolve/main/app.py
- Command line
-
hf download hf://spaces/ALIOF213/ALOFTOp2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/ALIOF213/ALOFTOp2/resolve/main/app.py
8.49 kB
| import telebot | |
| import json | |
| import os | |
| import threading | |
| import time | |
| import random | |
| import logging | |
| from flask import Flask | |
| # ุฅุนุฏุงุฏ ุงูุณุฌูุงุช | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | |
| # ============ ุฎุงุฏู ุงูููุจ ูุถู ุงู ุนู ู ุงูุจูุช 24 ุณุงุนุฉ ============ | |
| app = Flask('') | |
| def home(): | |
| return "Bot is running and alive!" | |
| def run_web(): | |
| # Hugging Face Spaces ุชุณุชุฎุฏู ุงูู ููุฐ 7860 ุงูุชุฑุงุถูุงู | |
| app.run(host='0.0.0.0', port=7860) | |
| # ุชุดุบูู ุงูุณูุฑูุฑ ูู ุงูุฎูููุฉ | |
| threading.Thread(target=run_web, daemon=True).start() | |
| # ============ ุงูุฅุนุฏุงุฏุงุช ============ | |
| TOKEN = os.getenv("TOKEN", "8615712682:AAFYFQM7NYxVhAuKdA-4XcK6o_irjX32UzA") | |
| if not TOKEN or TOKEN == "1234567890:ABCdefGHIjklMNOpqrSTUvwxYZ_example": | |
| logging.error("โ ูู ูุชู ุงูุนุซูุฑ ุนูู ุงูุชููู! ุฃุถู TOKEN ูู Environment Variables") | |
| exit(1) | |
| DATA_FILE = "user_data.json" | |
| # ============ ุงูู ุญุชูู ============ | |
| MESSAGES = [ | |
| {"text": "๏ดฟ ุฅูููู ู ูุนู ุงููุนูุณูุฑู ููุณูุฑูุง ๏ดพ\n\n[ุณูุฑุฉ ุงูุดุฑุญ: 6]", "source": "ูุฑุขู ูุฑูู "}, | |
| {"text": "๏ดฟ ููููู ุฑููุจูู ุฒูุฏูููู ุนูููู ูุง ๏ดพ\n\n[ุณูุฑุฉ ุทู: 114]", "source": "ูุฑุขู ูุฑูู "}, | |
| {"text": "๏ดฟ ุฃูููุง ุจูุฐูููุฑู ุงูููููู ุชูุทูู ูุฆูููู ุงูููููููุจู ๏ดพ\n\n[ุณูุฑุฉ ุงูุฑุนุฏ: 28]", "source": "ูุฑุขู ูุฑูู "}, | |
| {"text": "๏ดฟ ููู ูู ููุชูููููููู ุนูููู ุงูููููู ูููููู ุญูุณูุจููู ๏ดพ\n\n[ุณูุฑุฉ ุงูุทูุงู: 3]", "source": "ูุฑุขู ูุฑูู "}, | |
| {"text": "๏ดฟ ููุงุฐูููุฑููููู ุฃูุฐูููุฑูููู ู ููุงุดูููุฑููุง ููู ููููุง ุชูููููุฑูููู ๏ดพ\n\n[ุณูุฑุฉ ุงูุจูุฑุฉ: 152]", "source": "ูุฑุขู ูุฑูู "}, | |
| {"text": "ุงููููููู ูู ุฅููููู ุฃูุณูุฃููููู ุงููููุฏูู ููุงูุชููููู ููุงููุนูููุงูู ููุงููุบูููู", "source": "ุฏุนุงุก"}, | |
| {"text": "ุงููููููู ูู ุฃูุนููููู ุนูููู ุฐูููุฑููู ููุดูููุฑููู ููุญูุณููู ุนูุจูุงุฏูุชููู", "source": "ุฏุนุงุก"}, | |
| {"text": "ุฑูุจููููุง ุขุชูููุง ููู ุงูุฏููููููุง ุญูุณูููุฉู ููููู ุงูุขุฎูุฑูุฉู ุญูุณูููุฉู ููููููุง ุนูุฐูุงุจู ุงููููุงุฑู", "source": "ุฏุนุงุก"}, | |
| {"text": "ุงููููููู ูู ุตูููู ููุณููููู ู ุนูููู ููุจููููููุง ู ูุญูู ููุฏู", "source": "ุตูุงุฉ ุนูู ุงููุจู"}, | |
| {"text": "ุณูุจูุญูุงูู ุงูููููู ููุจูุญูู ูุฏูููุ ุณูุจูุญูุงูู ุงูููููู ุงููุนูุธููู ู", "source": "ุฐูุฑ"}, | |
| {"text": "ููุง ุฅููููู ุฅููููุง ุงูููููู ููุญูุฏููู ููุง ุดูุฑูููู ููููุ ูููู ุงููู ููููู ูููููู ุงููุญูู ูุฏู ูููููู ุนูููู ููููู ุดูููุกู ููุฏููุฑู", "source": "ุฐูุฑ"}, | |
| {"text": "ุฃูุณูุชูุบูููุฑู ุงูููููู ุงููุนูุธููู ู ููุฃูุชููุจู ุฅููููููู", "source": "ุงุณุชุบูุงุฑ"}, | |
| ] | |
| INTERVAL = 900 # 15 ุฏูููุฉ | |
| bot = telebot.TeleBot(TOKEN) | |
| # ============ ุญูุธ/ุชุญู ูู ุงูู ุฌู ูุนุงุช ============ | |
| def load_groups() -> list: | |
| if os.path.exists(DATA_FILE): | |
| try: | |
| with open(DATA_FILE, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| except json.JSONDecodeError: | |
| return [] | |
| return [] | |
| def save_groups(groups: list): | |
| try: | |
| with open(DATA_FILE, "w", encoding="utf-8") as f: | |
| json.dump(groups, f, ensure_ascii=False, indent=4) | |
| except Exception as e: | |
| logging.error(f"ุฎุทุฃ ูู ุญูุธ ุงูุจูุงูุงุช: {e}") | |
| def add_group(chat_id: int, title: str): | |
| groups = load_groups() | |
| for g in groups: | |
| if g["chat_id"] == chat_id: | |
| return | |
| groups.append({"chat_id": chat_id, "title": title}) | |
| save_groups(groups) | |
| logging.info(f"โ ุชู ุช ุฅุถุงูุฉ ุงูู ุฌู ูุนุฉ: {title} ({chat_id})") | |
| def remove_group(chat_id: int): | |
| groups = load_groups() | |
| groups = [g for g in groups if g["chat_id"] != chat_id] | |
| save_groups(groups) | |
| logging.info(f"๐๏ธ ุชู ุช ุฅุฒุงูุฉ ุงูู ุฌู ูุนุฉ: {chat_id}") | |
| # ============ ุงูุฅุฑุณุงู ุงูุชููุงุฆู ูู 15 ุฏูููุฉ ============ | |
| def auto_send_loop(): | |
| time.sleep(10) | |
| while True: | |
| logging.info("โฐ ุจุฏุก ุฏูุฑุฉ ุงูุฅุฑุณุงู ุงูุชููุงุฆู...") | |
| groups = load_groups() | |
| logging.info(f"ุนุฏุฏ ุงูู ุฌู ูุนุงุช: {len(groups)}") | |
| for g in groups: | |
| chat_id = g["chat_id"] | |
| title = g.get("title", "ู ุฌู ูุนุฉ") | |
| msg = random.choice(MESSAGES) | |
| try: | |
| text = f"{msg['text']}\n\nโ {msg['source']} ๐" | |
| bot.send_message(chat_id=chat_id, text=text) | |
| logging.info(f"โ ุชู ุงูุฅุฑุณุงู ุฅูู {title}") | |
| except Exception as e: | |
| logging.error(f"โ ูุดู ุงูุฅุฑุณุงู ุฅูู {title}: {e}") | |
| logging.info(f"๐ด ุงูุงูุชุธุงุฑ {INTERVAL} ุซุงููุฉ (15 ุฏูููุฉ)...") | |
| time.sleep(INTERVAL) | |
| threading.Thread(target=auto_send_loop, daemon=True).start() | |
| # ============ ู ุนุงูุฌุงุช ุชูููุฌุฑุงู ============ | |
| def start(message): | |
| if message.chat.type == "private": | |
| bot.reply_to( | |
| message, | |
| "๐ค ุจูุช ุงูุฃุฏุนูุฉ ูุงููุฑุขู\n\n" | |
| "ุฃุถููู ุฅูู ู ุฌู ูุนุชู ูุณุฃุฑุณู ุขูุฉ ุฃู ุฏุนุงุก ูู 15 ุฏูููุฉ ุชููุงุฆูุงู.\n\n" | |
| "ุดูุฑุงู ูุงุณุชุฎุฏุงู ู ุงูุจูุช." | |
| ) | |
| def on_new_chat_members(message): | |
| """ุนูุฏ ุฅุถุงูุฉ ุงูุจูุช ูู ุฌู ูุนุฉ ุฌุฏูุฏุฉุ ูุณุฌููุง ุชููุงุฆูุงู.""" | |
| for member in message.new_chat_members: | |
| if member.id == bot.get_me().id: | |
| add_group(message.chat.id, message.chat.title or "ู ุฌู ูุนุฉ") | |
| try: | |
| bot.send_message( | |
| message.chat.id, | |
| "๐ค ุฃููุงู ุจูู !\n\nุณุฃุฑุณู ููู ุขูุฉ ุฃู ุฏุนุงุก ูู 15 ุฏูููุฉ ุชููุงุฆูุงู ุจุฅุฐู ุงููู.\n\n" | |
| "โ ุงูุจูุช ุฃุฌุฑ ูู ูููู ๐" | |
| ) | |
| except Exception as e: | |
| logging.error(f"ูุดู ุฅุฑุณุงู ุฑุณุงูุฉ ุงูุชุฑุญูุจ: {e}") | |
| def on_left_chat_member(message): | |
| """ุนูุฏ ุฅุฒุงูุฉ ุงูุจูุช ู ู ุงูู ุฌู ูุนุฉุ ูุญุฐููุง ู ู ุงููุงุฆู ุฉ.""" | |
| if message.left_chat_member.id == bot.get_me().id: | |
| remove_group(message.chat.id) | |
| def stop_cmd(message): | |
| """ุฃู ุฑ /stop ุฏุงุฎู ุงูู ุฌู ูุนุฉ ูุฅููุงู ุงูุฅุฑุณุงู ููุฐู ุงูู ุฌู ูุนุฉ.""" | |
| if message.chat.type in ["group", "supergroup"]: | |
| try: | |
| member = bot.get_chat_member(message.chat.id, message.from_user.id) | |
| if member.status not in ["administrator", "creator"]: | |
| return | |
| remove_group(message.chat.id) | |
| bot.reply_to(message, "๐ ุชู ุฅููุงู ุงูุฅุฑุณุงู ูู ูุฐู ุงูู ุฌู ูุนุฉ.") | |
| except Exception as e: | |
| logging.error(f"ุฎุทุฃ ูู /stop: {e}") | |
| def resume_cmd(message): | |
| """ุฃู ุฑ /resume ุฏุงุฎู ุงูู ุฌู ูุนุฉ ูุงุณุชุฆูุงู ุงูุฅุฑุณุงู.""" | |
| if message.chat.type in ["group", "supergroup"]: | |
| try: | |
| member = bot.get_chat_member(message.chat.id, message.from_user.id) | |
| if member.status not in ["administrator", "creator"]: | |
| return | |
| add_group(message.chat.id, message.chat.title or "ู ุฌู ูุนุฉ") | |
| bot.reply_to(message, "โ ุชู ุชุดุบูู ุงูุฅุฑุณุงู ู ู ุฌุฏูุฏ.") | |
| except Exception as e: | |
| logging.error(f"ุฎุทุฃ ูู /resume: {e}") | |
| if __name__ == "__main__": | |
| if not os.path.exists(DATA_FILE): | |
| save_groups([]) | |
| logging.info("๐ ุจุฏุก ุชุดุบูู ุงูุจูุช...") | |
| while True: | |
| try: | |
| bot.polling(none_stop=True, interval=0, timeout=20) | |
| except Exception as e: | |
| logging.error(f"โ ๏ธ ุฎุทุฃ: {e}") | |
| time.sleep(5) | |
| logging.info("ุฅุนุงุฏุฉ ุชุดุบูู ุงูุจูุช...") | |