<?php
/*

دیباگ شده : @Camaeal

*/
error_reporting(0);
set_time_limit(60);
$ne=new mysqli('localhost','mehranff_digi2','HDzzNWRKZ&i_M(bQ','mehranff_digi2');//اطلاعات دیتابیس وارد کنید
$ne->set_charset('utf8mb4');

$token= '8474228880:AAEDKqFeHKgTbTN0udZrX2DmeQT_6qdgTIU';//توکن ربات
define('API_KEY',$token);

function Neman($method,$data=[],$token=API_KEY) {
	$ch=curl_init('https://api.telegram.org/bot'.$token.'/'.$method);
	curl_setopt_array($ch,[CURLOPT_RETURNTRANSFER=>1,CURLOPT_POSTFIELDS=>$data]);
	return json_decode(curl_exec($ch));
}
$i=0;
while($i<=60) {
$q=$ne->query("select id,del from groups where `del` IS NOT NULL");
	while($r=$q->fetch_assoc()) {
		$del=json_decode($r['del'],true);
		if(!is_array($del)) continue;
		$changed=false;
		foreach($del as $msgid=>$time){
			if($time<=time()){
				Neman('deletemessage',[
					'chat_id'=>$r['id'],
					'message_id'=>$msgid
				]);
				unset($del[$msgid]);
				$changed=true;
			}
		}
		if($changed){
			if(empty($del)) {
				$ne->query("update `groups` set `del`=NULL where `id`='".$ne->real_escape_string($r['id'])."'");
			} else {
				$new=json_encode($del,JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
				$ne->query("update `groups` set `del`='".$ne->real_escape_string($new)."' where `id`='".$ne->real_escape_string($r['id'])."'");
			}
		}
	}
sleep(1);
$i++;
}
/*

دیباگ شده : @Camaeal

*/