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