<?php
/*
کانال سورس خونه ! پر از سورس هاي ربات هاي تلگرامي !
لطفا در کانال ما عضو شويد 
@source_home
https://t.me/source_home
*/
set_time_limit(0);
error_reporting(0);
ob_start();
define('API_KEY','680191601:AAGidmLqGH_TYxZT2hbb_kgrDt7-AEy5nQ4');
function bot($method,$datas=[]){
    $url = 'https://api.telegram.org/bot'.API_KEY.'/'.$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
function save($filename,$TXTdata){
	$myfile = fopen($filename, "a") or die("Unable to open file!");
	fwrite($myfile, "$TXTdata");
	fclose($myfile);
	}
function SendMessage($chat_id, $text, $mode = null, $keu = null){
	bot('SendMessage',[
	'chat_id'=>$chat_id,
	'text'=>$text,
	'parse_mode'=>$mode,
	'reply_markup'=>$keu
	]);
}

$update = json_decode(file_get_contents('php://input'));
$message = $update->message;
$chat_id = $message->chat->id;
$text = $message->text;
$name = $update->message->from->first_name;
$from_id = $update->message->from->id;
$data = $update->callback_query->data;
$message_id = $update->message->message_id;
$chatid = $update->callback_query->message->chat->id;
$msg = $update->callback_query->message->message_id;
$photo = $update->message->photo;
$type = $message->chat->type;
$bot = "on";
$lock = file_get_contents("data/$chat_id/lock.txt");
$unlock = file_get_contents("data/$chat_id/unlock.txt");
mkdir("data");
mkdir("data/$chat_id");
$Dev = array("362107527");//آیدی عددی ادمین
$token = "680191601:AAGidmLqGH_TYxZT2hbb_kgrDt7-AEy5nQ4";
$stat = file_get_contents("https://api.telegram.org/bot'.API_KEY.'/getChatMember?chat_id=$chat_id&user_id=" .$from_id);
$statjson = json_decode($stat, true);
$status = $statjson['result']['status'];
/// start bot
if($text == '/start'){
bot('sendMessage',[
'chat_id'=>$chat_id,
'text'=>"ربات قفل کردن گروه به صورت ساعتی

ربات را در گروه ادمین کنید",
]);
}

elseif($text == "پنل"){
bot('sendmessage',[
'chat_id'=>$chat_id,
'text'=>"panel mute listtt",
'reply_markup'=>json_encode([
'inline_keyboard'=>[
[
['text'=>"زمان شروع",'callback_data'=>'start'],['text'=>"$lock",'callback_data'=>'sst']
],
[
['text'=>" زمان اتمام",'callback_data'=>'end'],['text'=>"$unlock",'callback_data'=>'ennd']
],
],
])
]);
}
if ($bot == "on"){
date_default_timezone_set('Asia/Tehran');
$date1 = date("H:i");
if($unlock > $date1 && $date1 > $lock){
if ($type == 'group' | $type == 'supergroup'){
if ( $status != 'creator' && $status != 'administrator' && !in_array($from_id,$Dev) ) {
if($date1 < $lock){
 bot('deletemessage',[
    'chat_id'=>$chat_id,
    'message_id'=>$message->message_id
    ]);
}else
{
	 bot('deletemessage',[
    'chat_id'=>$chat_id,
    'message_id'=>$message->message_id
    ]);

}
}
}
}
}
if(strpos ($text,"/set") !== false && !in_array($from_id,$Dev) ) {
$text = explode(" ",$text);
if ($text[1] !=" " && $text[2] !=""){
file_put_contents("data/$chat_id/lock.txt","$text[1]");
file_put_contents("data/$chat_id/unlock.txt","$text[2]");
sendmessage($chat_id,"قفل گروه تنظیم شد.", null ,null);
}
}
unlink("error_log");
?>