Update: 2026-07-05 22:59:19
This commit is contained in:
@@ -29,7 +29,7 @@ try {
|
||||
|
||||
// Find a pending task that is scheduled for now or earlier
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, type, target_url, prompt_context, generated_comment
|
||||
SELECT id, account_id, type, target_url, prompt_context, generated_comment
|
||||
FROM social_tasks
|
||||
WHERE status = 'pending' AND platform = ? AND (scheduled_at IS NULL OR scheduled_at <= NOW())
|
||||
ORDER BY created_at ASC LIMIT 1
|
||||
@@ -38,11 +38,55 @@ try {
|
||||
$task = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($task) {
|
||||
// Mark as in progress
|
||||
require_once __DIR__ . '/account_manager.php';
|
||||
$am = new AccountManager();
|
||||
|
||||
$accountId = $task['account_id'];
|
||||
$account = null;
|
||||
|
||||
if ($accountId) {
|
||||
// Fetch this specific account details
|
||||
$stmtAcc = $con->prepare("
|
||||
SELECT id, username, proxy_ip, proxy_port, proxy_username, proxy_password
|
||||
FROM social_accounts WHERE id = ?
|
||||
");
|
||||
$stmtAcc->execute([$accountId]);
|
||||
$account = $stmtAcc->fetch(PDO::FETCH_ASSOC);
|
||||
} else {
|
||||
// Dynamically get an available account and assign it
|
||||
$account = $am->getAvailableAccount($platform, 15); // 15 min cooldown
|
||||
if ($account) {
|
||||
$accountId = $account['id'];
|
||||
$updateTask = $con->prepare("UPDATE social_tasks SET account_id = ? WHERE id = ?");
|
||||
$updateTask->execute([$accountId, $task['id']]);
|
||||
$task['account_id'] = $accountId;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$account) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'No active social account available or in cooldown']);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($account) {
|
||||
$task['bot_username'] = $account['username'];
|
||||
$task['proxy_ip'] = $account['proxy_ip'];
|
||||
$task['proxy_port'] = $account['proxy_port'];
|
||||
$task['proxy_username'] = $account['proxy_username'];
|
||||
$task['proxy_password'] = $account['proxy_password'];
|
||||
}
|
||||
|
||||
// Mark as in progress and update last active
|
||||
$update = $con->prepare("UPDATE social_tasks SET status = 'in_progress' WHERE id = ?");
|
||||
$update->execute([$task['id']]);
|
||||
|
||||
echo json_encode(['status' => 'success', 'data' => $task]);
|
||||
$am->markAccountActive($accountId);
|
||||
|
||||
// Return task directly in 'data' to preserve compatibility with existing Android bots
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'data' => $task
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['status' => 'success', 'message' => 'No tasks available', 'data' => null]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user