Update: 2026-07-05 23:16:38
This commit is contained in:
@@ -26,22 +26,38 @@ try {
|
||||
case 'get_task':
|
||||
// The bot asks for a task to do
|
||||
$platform = $_GET['platform'] ?? 'facebook';
|
||||
$requestedAccountId = $_GET['account_id'] ?? null;
|
||||
|
||||
// Find a pending task that is scheduled for now or earlier
|
||||
$stmt = $con->prepare("
|
||||
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
|
||||
");
|
||||
$stmt->execute([$platform]);
|
||||
if ($requestedAccountId) {
|
||||
// If the phone is strictly tied to one account, fetch a task specifically for it
|
||||
// Or fetch an unassigned task and assign it to this phone's account
|
||||
$stmt = $con->prepare("
|
||||
SELECT id, account_id, type, target_url, prompt_context, generated_comment
|
||||
FROM social_tasks
|
||||
WHERE status = 'pending'
|
||||
AND platform = ?
|
||||
AND (account_id = ? OR account_id IS NULL)
|
||||
AND (scheduled_at IS NULL OR scheduled_at <= NOW())
|
||||
ORDER BY created_at ASC LIMIT 1
|
||||
");
|
||||
$stmt->execute([$platform, $requestedAccountId]);
|
||||
} else {
|
||||
$stmt = $con->prepare("
|
||||
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
|
||||
");
|
||||
$stmt->execute([$platform]);
|
||||
}
|
||||
$task = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($task) {
|
||||
require_once __DIR__ . '/account_manager.php';
|
||||
$am = new AccountManager();
|
||||
|
||||
$accountId = $task['account_id'];
|
||||
$accountId = $task['account_id'] ?: $requestedAccountId;
|
||||
$account = null;
|
||||
|
||||
if ($accountId) {
|
||||
@@ -52,6 +68,12 @@ try {
|
||||
");
|
||||
$stmtAcc->execute([$accountId]);
|
||||
$account = $stmtAcc->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if ($account && !$task['account_id']) {
|
||||
$updateTask = $con->prepare("UPDATE social_tasks SET account_id = ? WHERE id = ?");
|
||||
$updateTask->execute([$accountId, $task['id']]);
|
||||
$task['account_id'] = $accountId;
|
||||
}
|
||||
} else {
|
||||
// Dynamically get an available account and assign it
|
||||
$account = $am->getAvailableAccount($platform, 15); // 15 min cooldown
|
||||
|
||||
Reference in New Issue
Block a user