<?php

if(!file_exists('madeline.php') or !filesize('madeline.php'))
	copy('https://phar.madelineproto.xyz/madeline.php', 'madeline.php');

require_once 'madeline.php';

$ne = new \danog\MadelineProto\API('session.madeline');
$ne->start();

error_reporting(0);
$m=$ne->messages;
$ac=$ne->account;
$a=$ne->auth;
$ch=$ne->channels;
function delete_logged_in(){
	global $a;
	return $a->resetAuthorizations();
}
function getviews($chat,$id){
	global $m;
	return $m->getMessagesViews(['increment'=>true,'peer'=>$chat,'id'=>(is_array($id)?$id:explode(',',$id))]);
}
function getmessages($channel,$id){
	global $ch;
	return $ch->getMessages(['channel'=>$channel,'id'=>(is_array($id)?$id:explode(',',$id))]);
}
function getbuttons($channel,$id){
	$a=-1;
	$i=0;
	$reply_markup=json_decode(json_encode(getmessages($channel,$id)),1)['messages'][0]['reply_markup']['rows'];
	if($reply_markup){
foreach($reply_markup as $rows){
		++$a;
		foreach($rows['buttons'] as $row){
			$key['inline_keyboard'][$a][]=['text'=>($row['_']=='keyboardButtonCallback'?$row['text']:'قابل انتخاب نیست !'),'callback_data'=>($row['data']['bytes']?"bu_".$a."_0_".$i++:'null')];
		}
	}
			return $key;
	}
	else
		return ['error'=>'reply markup not found'];
}
function js($js){
	header('content-type:application/json;charset=utf8');
	return json_encode($js,448);
}