<?php
error_reporting(0);
include_once '../config.php';
define('API_TOKEN', $token);
$db = mysqli_connect('localhost', $databaseUser, $databasePass, $databaseName);
function BoFile($method, $datas = [])
{
    $url = "https://api.telegram.org/bot" . API_TOKEN . "/" . $method;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $datas);
    $res = curl_exec($ch);
    if (curl_error($ch)) {
        var_dump(curl_error($ch));
    } else {
        return json_decode($res);
    }
}
mkdir('../res');
$usernamebot = BoFile('getMe')->result->username;
$url = str_replace('install/install.php', '', 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
file_get_contents('https://api.telegram.org/bot' . API_TOKEN . '/setWebHook?url=' . $url . 'bot.php');
file_get_contents($url . 'install/table.php');
$usernamebot = BoFile('getMe')->result->username;

if (!$db) {
    die("Connection db failed: " . mysqli_connect_error());
} else {
    echo "<h1 style='text-alighn:center; margin-top:100px;'>ربات شما ران شد ...<br><a href='https://t.me/$usernamebot'>برای ورود کلیک کنید</a><h1>";
    BoFile('sendMessage', ['chat_id' => $admin, 'text' => "<b>ربات شما ران شد ...\nلطفا استارت کنید : /start</b>", 'parse_mode' => 'html']);
}
