Skip to content

Commit

Permalink
Update update.php
Browse files Browse the repository at this point in the history
  • Loading branch information
wizwizdev authored Nov 3, 2023
1 parent ff0d7b5 commit 9a282f1
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions install/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,50 @@ function updateBot(){
}
}
}

$stmt = $connection->prepare("SELECT * FROM `setting` WHERE `type` = 'BOT_STATES'");
$stmt->execute();
$isExists = $stmt->get_result();
$stmt->close();
if($isExists->num_rows>0){

$botState = $isExists->fetch_assoc()['value'];
if(!is_null($botState)) $botState = json_decode($botState,true);
else $botState = array();

if(!isset($botState['USDRate']) && !isset($botState['TRXRate'])){
$query = "UPDATE `setting` SET `value` = ? WHERE `type` = 'BOT_STATES'";

$rate = json_decode(file_get_contents("https://api.changeto.technology/api/rate"),true)['result'];
if(!empty($rate['USD'])) $botState['USDRate'] = $rate['USD'];
if(!empty($rate['TRX'])) $botState['TRXRate'] = $rate['TRX'];

$newData = json_encode($botState);

$stmt = $connection->prepare($query);
$stmt->bind_param("s", $newData);
$stmt->execute();
$stmt->close();
}
}
else{
$query = "INSERT INTO `setting` (`type`, `value`) VALUES ('BOT_STATES', ?)";

$botState = array();

$rate = json_decode(file_get_contents("https://api.changeto.technology/api/rate"),true)['result'];
if(!empty($rate['USD'])) $botState['USDRate'] = $rate['USD'];
if(!empty($rate['TRX'])) $botState['TRXRate'] = $rate['TRX'];

$newData = json_encode($botState);

$stmt = $connection->prepare($query);
$stmt->bind_param("s", $newData);
$stmt->execute();
$stmt->close();
}



}
?>

0 comments on commit 9a282f1

Please sign in to comment.