<?php
/*
dev: https://factweb.ir
channel telegram : @factwebir
*/
// این فایل ادیت نشود
//روی یک دقیقه کرون جاب شود
// JOIN-> @factweb 
include "config.php"; // @factweb
//------------------------------------------------------//
error_reporting(0);
date_default_timezone_set('Asia/Tehran');
define('API_KEY',$API_KC); 
#================به روز رسانی قیمت دلار و bnb=======
$exchange_rate_data = file_get_contents('https://one-api.ir/price/?token='.$oneapi.'&action=tgju');
$exchange_rate_json = json_decode($exchange_rate_data, true);
// Remove commas and convert to integer
$dolar = str_replace(',', '', $exchange_rate_json['result']['currencies']['dollar']['p']); 
// Convert to Toman by dividing by 10
$dolar = floor($dolar / 10);

// Get crypto prices
$crypto_api_url = "https://one-api.ir/DigitalCurrency/?token=$oneapi";
$crypto_data = json_decode(file_get_contents($crypto_api_url), true);
$trx_price_usd = 0;
foreach ($crypto_data['result'] as $crypto) {
    if ($crypto['key'] == 'TRX') {
        $trx_price_usd = $crypto['price'];
        break;
    }
}

$ton_price_usd = 0;
foreach ($crypto_data['result'] as $crypto) {
    if ($crypto['key'] == 'TON') {
        $ton_price_usd = $crypto['price'];
        break;
    }
}

$connect->query("UPDATE settings SET pdolar = '$dolar', ptron='$trx_price_usd', pton='$ton_price_usd' WHERE botid = '$botid' LIMIT 1");


$current_time = time();
// Delete expired transactions
mysqli_query($connect, "DELETE FROM transactions WHERE timeexpire <= '$current_time'");
?>