prepare($query); $stmt->execute([$chat_id, $otp]); } function selectUser($chat_id) { global $db; $query = "SELECT * FROM `users` WHERE `chat_id` = ? LIMIT 1"; $stmt = $db->prepare($query); $stmt->execute([$chat_id]); return $stmt->fetch(); } function setStep($chat_id, $step) { global $db; $query = "UPDATE `users` SET `step` = ? WHERE `chat_id` = ?"; $stmt = $db->prepare($query); $stmt->execute([$step, $chat_id]); } function getSettingsBot($key) { global $db; $query = "SELECT * FROM `settings` WHERE `key_` = ? LIMIT 1"; $stmt = $db->prepare($query); $stmt->execute([$key]); return $stmt->fetch(); } function changeSettings($rowName, $newValue) { global $db; $query = "UPDATE `settings` SET `value_` = ? WHERE `key_` = ?"; $stmt = $db->prepare($query); $stmt->execute([$newValue, $rowName]); } function getUsdtIrtPrice() { $url = 'https://api.bitpin.org/v4/mkt/prices/'; $context = stream_context_create([ 'http' => [ 'timeout' => 10, 'method' => 'GET' ] ]); $response = @file_get_contents($url, false, $context); if ($response === false) { return null; } $data = json_decode($response, true); if (!is_array($data) || json_last_error() !== JSON_ERROR_NONE) { return null; } foreach ($data as $item) { if (isset($item['code']) && $item['code'] === 'USDT_IRT' && isset($item['price'])) { return (float) $item['price']; } } return null; }