0% found this document useful (0 votes)
15 views4 pages

Tttask Bot

This document outlines a Telegram bot implemented using the Aiogram library, which allows users to manage accounts and bind phone numbers. It includes functionalities for user registration, adding accounts, binding phone numbers, and checking status, with specific limits on the number of binds and points required for switching accounts. The bot interacts with an external API for login and device linking, while maintaining user data in a JSON file.

Uploaded by

fawazkwtq401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Tttask Bot

This document outlines a Telegram bot implemented using the Aiogram library, which allows users to manage accounts and bind phone numbers. It includes functionalities for user registration, adding accounts, binding phone numbers, and checking status, with specific limits on the number of binds and points required for switching accounts. The bot interacts with an external API for login and device linking, while maintaining user data in a JSON file.

Uploaded by

fawazkwtq401
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

import asyncio

import logging
import json
import os
import time
import requests
from aiogram import Bot, Dispatcher, types
from aiogram.filters import Command

# --- Configuration ---


BOT_TOKEN = "8141843617:AAEdnwpfWC377JBmkhxmftGCLCt9NSNIbFU"
OWNER_ID = 1840241995 # Your Telegram ID
DATA_FILE = "data.json"
WAIT_TIME_SECONDS = 120
MAX_BINDS_PER_ACCOUNT = 30
MIN_POINTS_TO_SWITCH = 300

# --- Setup Logging ---


logging.basicConfig(level=logging.INFO)

# --- Telegram Bot Setup ---


bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()

# --- Storage ---


def load_data():
if not os.path.exists(DATA_FILE):
return {}
with open(DATA_FILE, "r") as f:
return json.load(f)

def save_data(data):
with open(DATA_FILE, "w") as f:
json.dump(data, f, indent=4)

data = load_data()

# --- API Functions ---


def api_request(url, method="GET", token=None, json_data=None):
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": "Mozilla/5.0",
}
if token:
headers["x-token"] = token
headers["x-token-timestamp"] = str(int(time.time() * 1000))

try:
if method == "GET":
response = requests.get(url, headers=headers, verify=False)
else:
response = requests.post(url, headers=headers, json=json_data,
verify=False)
response.raise_for_status()
resp_json = response.json()
if resp_json.get("code") == 0:
return resp_json.get("data")
else:
return None
except:
return None

def login(email, password):


url = "https://api.ttask.vip/h5/taskBase/login"
payload = {"email": email, "password": password}
try:
response = requests.post(url, json=payload, verify=False)
response.raise_for_status()
resp_json = response.json()
if resp_json.get("code") == 0:
return resp_json["data"]["token"]
else:
return None
except:
return None

def send_device_link(token, phone):


url = "https://api.ttask.vip/h5/taskUser/phoneCode"
payload = {"phone": phone, "country_code": "1"}
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"x-token": token,
"x-token-timestamp": str(int(time.time() * 1000))
}
try:
response = requests.post(url, json=payload, headers=headers, verify=False)
response.raise_for_status()
resp_json = response.json()
if resp_json.get("code") == 0:
return True
else:
return False
except:
return False

def get_points(token):
url = "https://api.ttask.vip/h5/taskUser/pointsInfo"
result = api_request(url, method="GET", token=token)
if result:
return result.get("points", 0)
return 0

# --- Command Handlers ---

@dp.message(Command("start"))
async def start(message: types.Message):
user_id = str(message.from_user.id)
if user_id not in data:
data[user_id] = {
"email_password_list": [],
"current_index": 0,
"bind_count": 0,
"binded_numbers": []
}
save_data(data)
await message.answer("Welcome! You are registered.")
else:
await message.answer("Welcome back!")

@dp.message(Command("add_account"))
async def add_account(message: types.Message):
if message.from_user.id != OWNER_ID:
return
try:
_, user_id, email, password = message.text.strip().split()
if user_id not in data:
data[user_id] = {
"email_password_list": [],
"current_index": 0,
"bind_count": 0,
"binded_numbers": []
}
data[user_id]["email_password_list"].append({"email": email, "password":
password})
save_data(data)
await message.answer(f"Account added for user {user_id}.")
except:
await message.answer("Format error. Use: /add_account USERID EMAIL
PASSWORD")

@dp.message(Command("bind"))
async def bind_command(message: types.Message):
user_id = str(message.from_user.id)
if user_id not in data:
await message.answer("You are not registered. Send /start first.")
return

await message.answer("Send the phone number to bind:")

@dp.message()
async def get_number(msg: types.Message):
phone = msg.text.strip()
if phone in data[user_id]["binded_numbers"]:
await msg.answer("This number already binded!")
return

# Get current credentials


if data[user_id]["current_index"] >= len(data[user_id]
["email_password_list"]):
await msg.answer("No accounts assigned by admin. Contact owner.")
return

creds = data[user_id]["email_password_list"][data[user_id]
["current_index"]]
token = login(creds["email"], creds["password"])
if not token:
await msg.answer("Failed to login. Contact admin.")
return

points = get_points(token)
if points >= MIN_POINTS_TO_SWITCH or data[user_id]["bind_count"] >=
MAX_BINDS_PER_ACCOUNT:
data[user_id]["current_index"] += 1
data[user_id]["bind_count"] = 0
data[user_id]["binded_numbers"] = []
save_data(data)
await msg.answer("Account switched due to limits reached. Please send
again.")
return

success = send_device_link(token, phone)


if not success:
await msg.answer("Failed to send device link. Try another number.")
return

await msg.answer("✅ Device link request sent. Please approve in WhatsApp.\


nWaiting 2 minutes...")
await asyncio.sleep(WAIT_TIME_SECONDS)

data[user_id]["bind_count"] += 1
data[user_id]["binded_numbers"].append(phone)
save_data(data)

await msg.answer(f"✅ Number binded. Total binds: {data[user_id]


['bind_count']}")

# --- Owner Commands ---

@dp.message(Command("status"))
async def status(message: types.Message):
if message.from_user.id != OWNER_ID:
return
text = ""
for uid, info in data.items():
text += f"User {uid}:\n"
text += f" Current Index:
{info['current_index']+1}/{len(info['email_password_list'])}\n"
text += f" Bind Count: {info['bind_count']}\n"
text += f" Numbers: {len(info['binded_numbers'])}\n"
await message.answer(text or "No data yet.")

# --- Main Run ---


async def main():
await dp.start_polling(bot)

if __name__ == "__main__":
asyncio.run(main())

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy