import json import re import base64 import time import random import urllib.request import urllib.parse import http.cookiejar # ----------------------------- # CONFIGURATION # ----------------------------- CATALOG_URL = "https://induschan.site/a/catalog.json" POST_URL = "https://induschan.site/forms/board/a/post" CAPTCHA_URL = "https://induschan.site/captcha/" API_URL = "https://api.mistral.ai/v1/chat/completions" MISTRAL_KEY = "CHTDjXRY5kE0odBx7jG064NccPJT3Cik" # Realistic browser headers HEADERS = { "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Connection": "keep-alive", "Upgrade-Insecure-Requests": "1" } # ----------------------------- # HTTP CLIENT SETUP # ----------------------------- cookie_jar = http.cookiejar.CookieJar() opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cookie_jar)) def make_request(url, data=None, extra_headers=None): req_headers = {**HEADERS, **(extra_headers or {})} request = urllib.request.Request(url, data=data, headers=req_headers) with opener.open(request) as response: content_type = response.headers.get("Content-Type", "") if "application/json" in content_type or "text" in content_type: return response.read().decode("utf-8") return response.read() # ----------------------------- # PROCESSING FUNCTIONS # ----------------------------- def clean_text(text): return re.sub(r"\s+", " ", re.sub(r">+", "", text)).strip() def generate_text_reply(text): payload = { "model": "mistral-small-latest", "messages": [{ "role": "user", "content": ( "You are an anonymous imageboard user. Write a short, casual, highly sarcastic reply " "to the following post. Use mostly lowercase, skip formal punctuation, use internet slang " "naturally, and keep it to 1-2 short sentences maximum. Avoid sounding like an assistant.\n\n" f"Post: {clean_text(text)}" ) }] } try: res = make_request( API_URL, data=json.dumps(payload).encode("utf-8"), extra_headers={"Authorization": f"Bearer {MISTRAL_KEY}", "Content-Type": "application/json"} ) return json.loads(res)["choices"][0]["message"]["content"].strip() except Exception as e: print("Text Generation Error:", e) return None def solve_verification_image(raw_image_bytes): image_b64 = base64.b64encode(raw_image_bytes).decode("utf-8") payload = { "model": "mistral-large-latest", "messages": [{ "role": "user", "content": [ {"type": "text", "text": "solve captcha. its a 6 length captcha. return only the solved captcha text"}, {"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b64}"}} ] }], "temperature": 0 } try: res = make_request( API_URL, data=json.dumps(payload).encode("utf-8"), extra_headers={"Authorization": f"Bearer {MISTRAL_KEY}", "Content-Type": "application/json"} ) return json.loads(res)["choices"][0]["message"]["content"].strip() except Exception as e: print("Vision OCR Error:", e) return None # ----------------------------- # MAIN FLOW # ----------------------------- def main(): try: # Step 1: Browse the catalog print("[1/5] Browsing catalog...") catalog_raw = make_request(CATALOG_URL) catalog_data = json.loads(catalog_raw) threads = [] if isinstance(catalog_data, list) and len(catalog_data) > 0 and "threads" in catalog_data[0]: for page in catalog_data: threads.extend(page.get("threads", [])) else: threads = catalog_data latest_thread = max(threads, key=lambda x: x.get("bumped", 0)) thread_id = latest_thread.get("postId") or latest_thread.get("no") op_message = latest_thread.get("nomarkup") or latest_thread.get("message") or latest_thread.get("com") or "" print(f" Selected Thread #{thread_id}") # Step 2: Request the captcha image print("[2/5] Fetching verification element...") image_bytes = make_request(CAPTCHA_URL) if image_bytes[:4] != b"\xff\xd8\xff\xe0" and b">{thread_id}\n{ai_commentary}" # Step 5: Package and send the payload print("[5/5] Transmitting payload to form endpoint...") form_fields = { "thread": thread_id, "message": final_message, "captcha": verification_code, "captchaid": thread_id } encoded_form = urllib.parse.urlencode(form_fields).encode("utf-8") post_response = make_request( POST_URL, data=encoded_form, extra_headers={ "Content-Type": "application/x-www-form-urlencoded", "Origin": "https://induschan.site", "Referer": f"https://induschan.site/b/res/{thread_id}.html" } ) print("\n--- Process Finished ---") print("Posted Output:\n", final_message) print("\nResponse Preview:\n", post_response[:200]) except Exception as e: print("Pipeline interrupted:", e) if __name__ == "__main__": print("Bot service started. Press Ctrl+C to exit.") while True: try: main() except Exception as e: print(f"Loop caught unhandled global error: {e}") # 10 minutes = 600 seconds print("Sleeping for 10 minutes...") time.sleep(600)