forked from 0xStarLabs/StarLabs-Discord
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
166 lines (130 loc) · 5.56 KB
/
process.py
File metadata and controls
166 lines (130 loc) · 5.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import asyncio
import random
from loguru import logger
from src.model import prepare_data
import src.utils
from src.utils.output import show_dev_info, show_logo, show_menu
from src.utils.reader import read_xlsx_accounts
from src.utils.constants import ACCOUNTS_FILE, Account
import src.model
from src.utils.check_github_version import check_version
async def start():
async def launch_wrapper(account):
async with semaphore:
await account_flow(account, config)
show_logo()
show_dev_info()
try:
await check_version("0xStarLabs", "StarLabs-Discord")
except Exception as e:
import traceback
traceback.print_exc()
logger.error(f"Failed to check version: {e}")
logger.info("Continue with current version\n")
print("")
config = src.utils.get_config()
task = show_menu(src.utils.constants.MAIN_MENU_OPTIONS)
if task == "Exit":
return
config.DATA_FOR_TASKS = await prepare_data(config, task)
config.TASK = task
# Читаем аккаунты из XLSX
all_accounts = read_xlsx_accounts(ACCOUNTS_FILE)
# Определяем диапазон аккаунтов
start_index = config.SETTINGS.ACCOUNTS_RANGE[0]
end_index = config.SETTINGS.ACCOUNTS_RANGE[1]
# Если оба 0, проверяем EXACT_ACCOUNTS_TO_USE
if start_index == 0 and end_index == 0:
if config.SETTINGS.EXACT_ACCOUNTS_TO_USE:
# Фильтруем аккаунты по конкретным номерам
accounts_to_process = [
acc
for acc in all_accounts
if acc.index in config.SETTINGS.EXACT_ACCOUNTS_TO_USE
]
logger.info(
f"Using specific accounts: {config.SETTINGS.EXACT_ACCOUNTS_TO_USE}"
)
else:
# Если список пустой, берем все аккаунты
accounts_to_process = all_accounts
else:
# Фильтруем аккаунты по диапазону
accounts_to_process = [
acc for acc in all_accounts if start_index <= acc.index <= end_index
]
if not accounts_to_process:
logger.error("No accounts found in specified range")
return
# Проверяем наличие прокси
if not any(account.proxy for account in accounts_to_process):
logger.error("No proxies found in accounts data")
return
threads = config.SETTINGS.THREADS
# Создаем список аккаунтов и перемешиваем его
if config.SETTINGS.SHUFFLE_ACCOUNTS:
shuffled_accounts = list(accounts_to_process)
random.shuffle(shuffled_accounts)
else:
shuffled_accounts = accounts_to_process
# Создаем строку с порядком аккаунтов
account_order = " ".join(str(acc.index) for acc in shuffled_accounts)
logger.info(
f"Starting with accounts {min(acc.index for acc in accounts_to_process)} "
f"to {max(acc.index for acc in accounts_to_process)}..."
)
logger.info(f"Accounts order: {account_order}")
semaphore = asyncio.Semaphore(value=threads)
tasks = []
# Создаем задачи для каждого аккаунта
for account in shuffled_accounts:
tasks.append(asyncio.create_task(launch_wrapper(account)))
await asyncio.gather(*tasks)
async def account_flow(account: Account, config: src.utils.config.Config):
try:
pause = random.randint(
config.SETTINGS.RANDOM_INITIALIZATION_PAUSE[0],
config.SETTINGS.RANDOM_INITIALIZATION_PAUSE[1],
)
logger.info(f"[{account.index}] Sleeping for {pause} seconds before start...")
await asyncio.sleep(pause)
instance = src.model.Start(account, config)
await wrapper(instance.initialize, config)
await wrapper(instance.flow, config)
pause = random.randint(
config.SETTINGS.RANDOM_PAUSE_BETWEEN_ACCOUNTS[0],
config.SETTINGS.RANDOM_PAUSE_BETWEEN_ACCOUNTS[1],
)
logger.info(f"Sleeping for {pause} seconds before next account...")
await asyncio.sleep(pause)
except Exception as err:
logger.error(f"{account.index} | Account flow failed: {err}")
async def wrapper(function, config: src.utils.config.Config, *args, **kwargs):
attempts = config.SETTINGS.ATTEMPTS
for attempt in range(attempts):
result = await function(*args, **kwargs)
if isinstance(result, tuple) and result and isinstance(result[0], bool):
if result[0]:
return result
elif isinstance(result, bool):
if result:
return True
if attempt < attempts - 1: # Don't sleep after the last attempt
pause = random.randint(
config.SETTINGS.PAUSE_BETWEEN_ATTEMPTS[0],
config.SETTINGS.PAUSE_BETWEEN_ATTEMPTS[1],
)
logger.info(
f"Sleeping for {pause} seconds before next attempt {attempt+1}/{config.SETTINGS.ATTEMPTS}..."
)
await asyncio.sleep(pause)
return result
def task_exists_in_config(task_name: str, tasks_list: list) -> bool:
"""Рекурсивно проверяет наличие задачи в списке задач, включая вложенные списки"""
for task in tasks_list:
if isinstance(task, list):
if task_exists_in_config(task_name, task):
return True
elif task == task_name:
return True
return False