import os
import json
import asyncio
import re
import subprocess
import time
import requests
import uiautomator2 as u2
from telethon import TelegramClient, events
from [Link] import MessageEntityTextUrl
# ================== COULEURS & STYLES ==================
RED = "\033[91m"
GREEN = "\033[92m"
YELLOW = "\033[93m"
BLUE = "\033[94m"
CYAN = "\033[96m"
MAGENTA = "\033[95m"
WHITE = "\033[97m"
BOLD = "\033[1m"
DIM = "\033[2m"
RESET = "\033[0m"
# ================== PACKAGES ==================
CLONE_CONTAINER_PACKAGE = "[Link]"
TERMUX_PACKAGE = "[Link]/[Link]"
CHROME_PKG_NAME = "[Link]"
CHROME_ACTIVITY = "[Link]/[Link]"
# ================== VALEURS DES GAINS ==================
GAIN_LIKE = 1.1
GAIN_FOLLOW = 3.0
APP_CHOOSER = {
1: "145 1770",
2: "345 1770",
3: "545 1770",
4: "745 1770",
5: "945 1770",
6: "145 1985",
7: "345 1985",
8: "545 1985",
9: "745 1985",
10: "945 1985",
11: "145 2197",
12: "345 2197",
13: "545 2197",
14: "745 2197",
15: "945 2197",
}
API_ID=30544463
API_HASH="1ac05edd668be685f90ea2379751acd0"
TARGET_BOT="@SmmKingdomTasksBot"
# ================== UTILS ==================
def clear_screen():
[Link]("clear")
class TikTokTaskBot:
def __init__(self):
[Link] = self.load_json("[Link]", [])
self.paused_accounts = self.load_json("[Link]", [])
[Link] = self.load_json("[Link]", {"earned": 0.0, "tasks": 0})
[Link] = 0
self.device_id = None
[Link] = "adb shell"
[Link] = TelegramClient("session_bot", API_ID, API_HASH)
self.d = None
self.last_sent_msg = "TikTok"
self.current_user = {"nom": "Local_User", "cashnow": 0, "max": 999999999}
self.dynamic_chooser = APP_CHOOSER.copy()
def load_json(self, file, default):
if [Link](file):
try:
with open(file, "r") as f:
return [Link](f)
except: return default
return default
def save_json(self, file, data):
with open(file, "w") as f:
[Link](data, f, indent=4)
# ---------- ADB & UIAUTOMATOR ----------
def detect_device(self):
try:
out = subprocess.check_output(["adb", "devices"]).decode()
found = False
for line in [Link]():
if "\tdevice" in line:
self.device_id = [Link]("\t")[0]
[Link] = f"adb -s {self.device_id} shell"
found = True
break
if found:
try:
if self.d is None:
print(f"{YELLOW}🔌 Connexion uiautomator2...{RESET}")
self.d = [Link](self.device_id)
self.d.implicitly_wait(10.0)
[Link]['operation_delay'] = (0.2, 0.2)
print(f"{GREEN}✅Uiautomator2 Connecté!{RESET}")
except Exception as e:
print(f"{RED}Erreur connexion U2: {e}{RESET}")
return True
return False
except: return False
def cleanup_apps(self):
[Link](f"{[Link]} am force-stop {CLONE_CONTAINER_PACKAGE} > /dev/null 2>&1")
[Link](f"{[Link]} am kill-all > /dev/null 2>&1")
def focus_termux(self):
[Link](f"{[Link]} am start --activity-brought-to-front {TERMUX_PACKAGE} > /dev/null 2>&1")
def get_next_active_index(self):
if not [Link]: return
start_index = [Link]
while True:
[Link] = ([Link] + 1) % len([Link])
if [Link][[Link]] not in self.paused_accounts:
break
if [Link] == start_index: break
async def send_bot_command(self, cmd):
await [Link].send_message(TARGET_BOT, cmd)
# ---------- ACTIONS ----------
async def do_task(self, account_idx, link, action, specific_text=None):
try:
self.cleanup_apps()
coord_clone = APP_CHOOSER.get(account_idx)
if not coord_clone:
print(f"{RED}❌Coordonnée introuvable pour l'index {account_idx}{RESET}")
return False
# --- OUVERTURE ---
print(f"{CYAN}🔌 ÉTAPE 1 : Appel du menu des clones...{RESET}")
[Link](f'{[Link]} am start -a [Link] -d "{link}" -p
{CLONE_CONTAINER_PACKAGE} > /dev/null 2>&1')
await [Link](4)
print(f"{YELLOW}🔌 ÉTAPE 2 : Sélection du compte {account_idx}...{RESET}")
[Link](f"{[Link]} input swipe {coord_clone} {coord_clone} 100")
await [Link](4)
# --- VÉRIFICATION DU FOCUS (CRUCIAL) ---
current_app = self.d.app_current()['package']
if current_app == CLONE_CONTAINER_PACKAGE:
print(f"{MAGENTA}🔌 Le cloneur bloque encore. Deuxième clic de force...{RESET}")
[Link](f"{[Link]} input swipe {coord_clone} {coord_clone} 150")
await [Link](4)
print(f"{WHITE}🔌 Chargement TikTok (12s)...{RESET}")
await [Link](12)
# --- RÉVEIL DE L'INTERFACE (Pour débloquer le clic) ---
# On simule un clic neutre sur le côté de l'écran pour redonner la main à TikTok
[Link](f"{[Link]} input tap 100 1000")
await [Link](1)
# --- LOGIQUE UIAUTOMATOR ---
FOLLOW_KEYWORDS = ["Suivre", "S'abonner", "Follow", "Seguir"]
action_lower = [Link]()
# --- ACTION : FOLLOW ---
if "follow" in action_lower or "profile" in action_lower:
print(f"{CYAN}🔌 Mode Follow...{RESET}")
# On utilise une méthode ADB brute si l'UIAutomator échoue
clicked = False
for keyword in FOLLOW_KEYWORDS:
btn = self.d(textContains=keyword)
if [Link]:
# On récupère les coordonnées réelles du bouton
x, y = [Link]()
print(f"{GREEN}-> Bouton trouvé à {x},{y}. Clic ADB...{RESET}")
[Link](f"{[Link]} input tap {x} {y}")
clicked = True
break
if not clicked:
# Si le texte n'est pas vu, on tente un clic sur la zone habituelle du bouton suivre
print(f"{YELLOW}🔌 Texte non détecté, clic zone de secours...{RESET}")
[Link](f"{[Link]} input tap 540 850") # Zone moyenne du bouton suivre sur profil
# --- ACTION : LIKE ---
else:
print(f"{CYAN}🔌 Mode Like...{RESET}")
# Sur TikTok, le plus fiable est le double-tap ADB au centre
# Cela contourne tous les problèmes de détection de bouton
[Link](f"{[Link]} input tap 540 1000")
await [Link](0.1)
[Link](f"{[Link]} input tap 540 1000")
print(f"{GREEN}-> Double Tap ADB envoyé !{RESET}")
# --- ACTION : COMMENTAIRE ---
if "comment" in action_lower:
# On force le clic sur l'icône commentaire par ADB
print(f"{MAGENTA}🔌 Mode Commentaire...{RESET}")
[Link](f"{[Link]} input tap 990 1450")
await [Link](3)
if self.d(className="[Link]").exists:
self.d(className="[Link]").click()
await [Link](1)
self.d.send_keys(specific_text if specific_text else "Super vidéo !")
await [Link](1)
[Link](f"{[Link]} input tap 990 1000") # Bouton envoi
await [Link](3)
[Link](f"{[Link]} am force-stop {CLONE_CONTAINER_PACKAGE}")
return True
except Exception as e:
print(f"Erreur Task: {e}")
return False
# --- PRÉPARATION DES ACTIONS ---
FOLLOW_KEYWORDS = ["Suivre", "S'abonner", "Follow", "Seguir"]
LIKE_DESC_REGEX = "(?i)(like|j'aime|love|gostar|aimer)"
action_lower = [Link]()
# --- SÉCURITÉ ANTI-POPUP AVANT ACTION ---
# Si le menu cloneur réapparaît soudainement maintenant
if self.d.app_current()['package'] == CLONE_CONTAINER_PACKAGE:
print(f"{YELLOW}🔌 Menu cloneur détecté ! Clic central pour le chasser...{RESET}")
[Link](f"{[Link]} input tap 500 1200")
await [Link](2)
# --- LOGIQUE ACTION : COMMENTAIRE ---
if "comment" in action_lower:
print(f"{MAGENTA} 🔌 Mode Commentaire...{RESET}", flush=True)
[Link](f"{[Link]} input tap 990 1370") # Icône commentaire
await [Link](3)
if self.d(className="[Link]").exists:
self.d(className="[Link]").click()
await [Link](1)
text_to_send = specific_text if specific_text else "Wow super video 🔌"
print(f"{MAGENTA} -> Écriture : {text_to_send}{RESET}")
self.d.send_keys(text_to_send)
await [Link](1)
# Tentative de clic sur le bouton envoyer (par ID ou coordonnée fixe)
send_btn =
self.d(resourceIdMatches="(?i).*id/(send_btn|publish_button|comment_publish_img)")
if send_btn.exists:
send_btn.click()
else:
[Link](643, 978) # Coordonnée secours bouton envoi
print(f"{GREEN} -> Commentaire envoyé !{RESET}")
await [Link](2)
[Link](f"{[Link]} input tap 500 200") # Fermer le panneau coms
else:
print(f"{RED} ❌Champ texte introuvable !{RESET}")
# --- LOGIQUE ACTION : FOLLOW ---
elif "follow" in action_lower or "profile" in action_lower:
print(f"{CYAN} 🔌 Recherche bouton Follow...{RESET}", flush=True)
clicked = False
for keyword in FOLLOW_KEYWORDS:
if self.d(textContains=keyword).exists:
self.d(textContains=keyword).click()
print(f"{GREEN} -> Clic sur '{keyword}'{RESET}")
clicked = True
break
if not clicked:
if self.d(resourceIdMatches=".*follow_btn.*").exists:
self.d(resourceIdMatches=".*follow_btn.*").click()
print(f"{GREEN} -> Clic sur Follow (via ID){RESET}")
else:
print(f"{RED} ❌Bouton Follow introuvable{RESET}")
# --- LOGIQUE ACTION : LIKE (PAR DÉFAUT) ---
else:
print(f"{CYAN} 🔌 Mode Like...{RESET}", flush=True)
# On commence par un clic au milieu pour être sûr d'avoir le focus
[Link](0.5, 0.5)
await [Link](0.5)
liked_success = False
if self.d(descriptionMatches=LIKE_DESC_REGEX).exists:
self.d(descriptionMatches=LIKE_DESC_REGEX).click()
liked_success = True
# Si le bouton like n'est pas détecté, on utilise le Double Tap universel
if not liked_success:
print(f"{MAGENTA} 🔌 Fallback : DOUBLE TAP central{RESET}")
self.d.double_click(0.5, 0.5, duration=0.1)
liked_success = True
# Fin de tâche
await [Link](3)
[Link](f"{[Link]} am force-stop {CLONE_CONTAINER_PACKAGE}")
self.focus_termux()
return True
except Exception as e:
print(f"Erreur Task: {e}", flush=True)
return False
# ---------- TELEGRAM ----------
async def start_telegram(self):
if not self.detect_device():
print(f"{RED}❌ADB non détecté.{RESET}")
return
await [Link]()
[Link].remove_event_handler(self.on_message)
[Link].add_event_handler(self.on_message, [Link](chats=TARGET_BOT))
if not [Link]: return
current_acc = [Link][[Link]]
print(f"\n{BOLD}{WHITE}🔌 Démarrage sur : {CYAN}{current_acc}{RESET}")
await self.send_bot_command("TikTok")
await [Link].run_until_disconnected()
async def on_message(self, event):
text = [Link] or ""
buttons = [Link]
# 🔌 SECURITY CHECK / CAPTCHA
if "Security check" in text and "verification" in text:
print(f"\n{RED}{BOLD}🔌 SECURITY CHECK DETECTÉ !{RESET}")
full_link = None
if [Link]:
for entity in [Link]:
if isinstance(entity, MessageEntityTextUrl):
if "[Link]" in [Link]: full_link = [Link]; break
if full_link:
[Link](f'{[Link]} am start -n {CHROME_ACTIVITY} -d "{full_link}" > /dev/null 2>&1')
await [Link](20)
try:
if self.d(textContains="Continue").exists(timeout=5):
self.d(textContains="Continue").click()
except: pass
[Link](f'{[Link]} am force-stop {CHROME_PKG_NAME}')
self.focus_termux()
await self.send_bot_command(self.last_sent_msg)
return
# DETECTION DE TÂCHE
if "Link :" in text and "Action :" in text:
full_link = None
if [Link]:
for entity in [Link]:
if isinstance(entity, MessageEntityTextUrl): full_link = [Link]; break
if full_link:
action = [Link](r"Action\s*:\s*(.+)", text).group(1)
print(f"{WHITE}🔌 Task: {BOLD}{action}{RESET}")
success = await self.do_task([Link] + 1, full_link, action)
if success:
local_gain = GAIN_FOLLOW if ("follow" in [Link]() or "profile" in [Link]())
else GAIN_LIKE
[Link]["earned"] += local_gain
self.save_json("[Link]", [Link])
print(f"{GREEN}✅TASK TERMINE (+{local_gain}){RESET}")
if buttons:
for i, row in enumerate(buttons):
for j, btn in enumerate(row):
if "Completed" in [Link] or "✅
" in [Link]:
self.last_sent_msg = [Link]
await [Link](i, j)
return
elif "added" in [Link]() or "credited" in [Link]():
await [Link](2); await self.send_bot_command("TikTok")
elif "Sorry" in text or "No more" in text:
print(f"{YELLOW}🔌 Plus de tâches sur ce compte, passage au suivant...{RESET}")
self.get_next_active_index() # Change l'index
self.focus_termux() # Revenir sur Termux pour voir le log
await [Link](2)
await self.send_bot_command("TikTok")
elif buttons and "Link" not in text:
target = [Link][[Link]]
for i, row in enumerate(buttons):
for j, btn in enumerate(row):
if [Link] == target:
await [Link](i, j); return
async def menu(self):
while True:
clear_screen()
adb_status = f"{GREEN}CONNECTÉ{RESET}" if self.detect_device() else
f"{RED}DÉCONNECTÉ{RESET}"
print(f"""
{BLUE}
███████╗█████╗███╗ ██╗██╗██████╗██╗ ██╗
██╔════╝██╔══██╗████╗ ██║██║██╔══██╗╚██╗██╔╝
█████╗ ███████║██╔██╗ ██║██║██████╔╝╚████╔╝
██╔══╝ ██╔══██║██║╚██╗██║██║██╔══██╗ ╚██╔╝
██║ ██║ ██║██║ ╚████║██║██║ ██║ ██║
╚═╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═╝{RESET}
{DIM}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{RESET}
🔌 BOT AUTOMATIQUE {DIM}|{RESET}
{DIM}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{RESET}
🔌 Status ADB : {adb_status}
🔌 Comptes : {WHITE}{len([Link])}{RESET}
🔌 Session Local : {YELLOW}{[Link]("earned", 0.0):.1f} CC{RESET}
{DIM}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{RESET}
{WHITE}[1]{RESET} 🔌 LANCER LE TASK
{WHITE}[2]{RESET} ➕AJOUTER UN COMPTE
{WHITE}[3]{RESET} 🔌 GÉRER LES COMPTES
{WHITE}[4]{RESET} ❌QUITTER
{DIM}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━{RESET}
""")
choice = input(f"{BOLD}{BLUE}➜CHOIX : {RESET}")
if choice == "1":
if [Link]:
[Link]["earned"] = 0.0
[Link]["tasks"] = 0
self.save_json("[Link]", [Link])
print(f"{GREEN}🔌 Compteur remis à 0 pour cette session.{RESET}")
await [Link](1)
await self.start_telegram()
else:
input(f"{RED}Ajoute un compte d'abord ! [Entrée]{RESET}")
elif choice == "2":
while True:
clear_screen()
print(f"{CYAN}=== ➕AJOUT DE COMPTE ==={RESET}")
name = input(f"Nom du compte n°{len([Link])+1} : ")
if not [Link](): break
if name not in [Link]:
[Link](name)