Created At: 2026-11-19T08:22:37Z Completed At: 2026-11-19T08:22:37Z Command exited with code 0. Command output: 51: "force_join": { 52: "id": "force_join", 53- "name": "Force Join Channel Guard", 54- "category": "security", 55- "icon": "shield-check", 56- "version": "1.1.0", 57- "description": "Requires subscribers to join your designated Telegram channel(s) before unlocking bot commands. Verifies via getChatMember.", 58- "permissions": ["channels.read", "messages.send"], 59- "dependencies": [], 60- "config_schema": { 61- "channel_username": {"type": "string", "title": "Required Channel Username (e.g. @astraea_cloud)"}, 62- "channel_id": {"type": "string", "title": "Channel ID (optional)"}, 63- "prompt_text": {"type": "string", "title": "Warning Message Text"}, 64- "button_text": {"type": "string", "title": "Join Button Label"}, 65- }, 66- "default_config": { 67- "channel_username": "@astraea_cloud", 68- "channel_id": "-1002345678901", 69- "prompt_text": "⚠️ Channel Membership Required\n\nYou must join our official Telegram channel to unlock this bot.", 70- "button_text": "📢 Join Official Channel", 71- "check_button_text": "🔄 Check Membership", 72- }, 73- }, 74- "referrals": { 75- "id": "referrals", 76- "name": "Referral & Viral Growth Engine", 77- "category": "growth", 78- "icon": "share-2", 79- "version": "1.3.0", 80- "description": "Generates subscriber deep-link invite links (/start ref_{userId}), tracks successful signups, awards points, and calculates balances.", 81- "permissions": ["messages.send"], 82- "dependencies": [], 83- "command_name": "/referral", 84- "inline_button_text": "🎁 Referral Program", 85- "menu_button_text": "👥 Invite Friends", 86- "config_schema": { 87- "points_per_referral": {"type": "integer", "title": "Points per Invitee", "default": 10}, 88- "welcome_bonus_points": {"type": "integer", "title": "Invited User Bonus", "default": 5}, 89- "min_payout_points": {"type": "integer", "title": "Redeem Threshold", "default": 50}, 90- "invite_message": {"type": "string", "title": "Referral Card Template"}, 91- }, 92- "default_config": { -- 285: "force_join_attempts", 286- "payments", 287- "broadcasts", 288- "errors", 289- ], 290- "bot_is_admin_verified": False, 291- }, 292- }, 293- "captcha_gate": { 294- "id": "captcha_gate", 295- "name": "Anti-Spam Welcome Captcha & Gate", 296- "category": "security", 297- "icon": "shield-check", 298- "version": "1.0.0", 299- "description": "Protects your bot from fake accounts, raid bots, and scrapers with an interactive captcha challenge on /start before unlocking commands.", 300- "permissions": ["messages.send"], 301- "dependencies": [], 302- "command_name": "/verify", 303- "inline_button_text": "🛡️ Verify Human", 304- "menu_button_text": "🛡️ Verify Status", 305- "config_schema": { 306- "captcha_type": {"type": "string", "enum": ["button", "math", "emoji"], "default": "button"}, 307- "timeout_seconds": {"type": "integer", "default": 60}, 308- "welcome_unverified_prompt": {"type": "string"}, 309- }, 310- "default_config": { 311- "captcha_type": "button", 312- "timeout_seconds": 60, 313- "welcome_unverified_prompt": "🛡️ Anti-Bot Verification Required\n\nPlease tap the verification button below to prove you are human and unlock all bot features.", 314- }, 315- }, 316- "file_store": { 317- "id": "file_store", 318- "name": "Digital Products & File Store", 319- "category": "monetization", 320- "icon": "folder-archive", 321- "version": "1.0.0", 322- "description": "Securely deliver digital products, courses, videos, and PDFs upon payment, VIP subscription, or points redemption with deep-link access.", 323- "permissions": ["messages.send", "database.write"], 324- "dependencies": [], 325- "command_name": "/files", -- 927: async def check_force_join( 928- self, 929- bot_id: uuid.UUID, 930- raw_token: str, 931- user_id: int, 932- ) -> tuple[bool, Optional[dict[str, Any]]]: 933- """ 934: Executes Force Join check if force_join module is active. 935- Returns: (is_allowed, prompt_payload_if_blocked) 936- """ 937: if not await self.is_module_active(bot_id, "force_join"): 938- return True, None 939- 940: config = await self.get_module_config(bot_id, "force_join") 941- channel_target = config.get("channel_username") or config.get("channel_id") 942- if not channel_target: 943- return True, None 944- 945- # Verify chat member with Telegram API 946- member_resp = await TelegramApiService.get_chat_member( 947- raw_token=raw_token, 948- chat_id=channel_target, 949- user_id=user_id, 950- ) 951- 952- status = member_resp.get("result", {}).get("status", "") 953- if status in ("creator", "administrator", "member", "restricted"): 954- return True, None 955- 956- # Blocked: construct response prompt 957- channel_clean = channel_target.replace("@", "") 958- channel_url = f"https://t.me/{channel_clean}" 959- prompt_text = config.get( 960- "prompt_text", 961- "⚠️ Channel Membership Required\n\nYou must join our channel to use this bot.", 962- ) 963- button_text = config.get("button_text", "📢 Join Channel") 964- check_button = config.get("check_button_text", "🔄 Check Membership") 965- 966- keyboard = { 967- "inline_keyboard": [ 968- [{"text": button_text, "url": channel_url}], 969: [{"text": check_button, "callback_data": "check_force_join"}], 970- ] 971- } 972- 973- return False, { 974- "text": prompt_text, 975- "reply_markup": keyboard, 976- "parse_mode": "HTML", 977- } 978- 979- async def record_referral( 980- self, 981- bot_id: uuid.UUID, 982- new_user_id: int, 983- referrer_user_id: int, 984- ) -> dict[str, Any]: 985- """ 986- Attributes a new subscriber to their referrer and awards reward points. 987- """ 988- if new_user_id == referrer_user_id: 989- return {"ok": False, "reason": "Self-referrals are prohibited"} 990- 991- if not await self.is_module_active(bot_id, "referrals"): 992- return {"ok": False, "reason": "Referral module is inactive"} 993- 994- config = await self.get_module_config(bot_id, "referrals") 995- points = config.get("points_per_referral", 10) 996- 997- # Check existing referral 998- stmt = select(BotReferralRecord).where( 999- and_( 1000- BotReferralRecord.bot_id == bot_id, 1001- BotReferralRecord.referred_user_id == new_user_id, 1002- ) 1003- ) 1004- res = await self.db.execute(stmt) 1005- if res.scalar_one_or_none(): 1006- return {"ok": False, "reason": "Already referred"} 1007- 1008- ref_record = BotReferralRecord( 1009- id=uuid.uuid4(), -- 1119: modules_to_activate.extend(["force_join", "auto_filter"]) 1120- if "referral" in m_id: 1121- modules_to_activate.append("referrals") 1122- 1123- if manifest.get("category") == "ai_specialist": 1124- modules_to_activate.append("ai_assistant") 1125- 1126- for mod_id in set(modules_to_activate): 1127- if mod_id in CORE_MODULE_DEFINITIONS: 1128- await self.install_module(bot_id, mod_id) 1129- 1130- logger.info( 1131- "template_modules_applied_to_bot", 1132- bot_id=str(bot_id), 1133- template_id=template_id, 1134- active_modules=list(set(modules_to_activate)), 1135- ) 1136- 1137- async def verify_bot_admin( 1138- self, 1139- bot_id: uuid.UUID, 1140- raw_token: str, 1141- chat_id: str | int, 1142- check_topics: bool = False, 1143- test_topic: bool = False, 1144- ) -> dict[str, Any]: 1145- """ 1146- Verifies if the bot is added as an Administrator in the given channel or group. 1147- Detects chat type, Telegram Forum Topics (threads), permissions, and runs live topic checks. 1148- """ 1149- # 1. Fetch Chat Info from Telegram API 1150- chat_resp = await TelegramApiService.get_chat(raw_token=raw_token, chat_id=chat_id) 1151- if not chat_resp.get("ok"): 1152- error_desc = chat_resp.get("error", "Chat not found or bot does not have access") 1153- return { 1154- "is_admin": False, 1155- "chat_id": chat_id, 1156- "error": error_desc, 1157- "message": f"Could not access '{chat_id}'. Ensure the bot is added to the channel/group first.", 1158- } 1159- -- 1371: elif module_id == "force_join": 1372- target_chat = config.get("channel_username") or config.get("channel_id") 1373- if not target_chat: 1374- return { 1375- "ok": False, 1376- "module_id": module_id, 1377- "error": "Mandatory Channel or Group username/ID is required.", 1378- "checks": [{"name": "Channel Specified", "passed": False, "detail": "Missing channel_username"}], 1379- "details": {}, 1380- } 1381- 1382- checks.append({"name": "Channel Specified", "passed": True, "detail": str(target_chat)}) 1383- 1384- admin_data = await self.verify_bot_admin(bot_id=bot_id, raw_token=raw_token, chat_id=target_chat) 1385- details.update(admin_data) 1386- 1387- if not admin_data.get("is_admin"): 1388- checks.append({"name": "Bot Administrator Rights", "passed": False, "detail": admin_data.get("message")}) 1389- is_ok = False 1390- error = admin_data.get("message") 1391- else: 1392- checks.append({ 1393- "name": "Bot Administrator Rights", 1394- "passed": True, 1395- "detail": f"Admin in '{admin_data.get('chat_title')}'" 1396- }) 1397- can_invite = admin_data.get("can_invite_users", True) 1398- checks.append({ 1399- "name": "Invite Users via Link Permission", 1400- "passed": can_invite, 1401- "detail": "Active" if can_invite else "Warning: Bot cannot generate invite links", 1402- }) 1403- if not can_invite: 1404- warning = "Bot is admin, but lacks 'Invite Users via Link' permission." 1405- 1406- elif module_id == "welcome_message": 1407- welcome_text = config.get("welcome_text", "") 1408- if not welcome_text or not welcome_text.strip(): 1409- is_ok = False 1410- error = "Welcome greeting text cannot be empty." 1411- checks.append({"name": "Welcome Text Defined", "passed": False, "detail": "Empty welcome_text"}) -- 1552: "force_join_attempts": "🔒 FORCE JOIN CHECK", 1553- "payments": "💳 PAYMENT RECEIVED", 1554- "broadcasts": "📢 BROADCAST SENT", 1555- "errors": "⚠️ SYSTEM ERROR", 1556- } 1557- event_label = event_emojis.get(event_type, f"📋 {event_type.upper()}") 1558- 1559- text = ( 1560- f"{event_label}\n\n" 1561- f"• User: {first_name} (@{username})\n" 1562- f"• User ID: {user_id}\n" 1563- f"• Details: {details}\n" 1564- f"• Timestamp: {now_str}" 1565- ) 1566- 1567- message_thread_id = None 1568- # Pro Feature: Forum Topics 1569- if config.get("enable_topics") and config.get("log_channel_type") == "supergroup_forum": 1570- topic_name = f"👤 {user_id} - @{username}" 1571- # Create or resolve topic 1572- topic_res = await TelegramApiService.create_forum_topic( 1573- raw_token=raw_token, 1574- chat_id=channel_id, 1575- name=topic_name, 1576- ) 1577- if topic_res.get("ok"): 1578- message_thread_id = topic_res.get("result", {}).get("message_thread_id") 1579- 1580- send_res = await TelegramApiService.send_message_with_retry( 1581- raw_token=raw_token, 1582- chat_id=channel_id, 1583- text=text, 1584- message_thread_id=message_thread_id, 1585- parse_mode="HTML", 1586- ) 1587- return send_res 1588- 1589- # -------------------------------------------------------------------------- 1590- # NEW POWER PLUGINS: CAPTCHA, DAILY REWARDS, FILE STORE, SUPPORT RELAY 1591- # -------------------------------------------------------------------------- 1592-