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 approveChatJoinRequest($channel_id, $user_id)
{
bot('approveChatJoinRequest', [
'chat_id' => $channel_id,
'user_id' => $user_id,
]);
}
function getChatMember($channel_id, $user_id)
{
$status = bot('getChatMember', [
'chat_id' => $channel_id,
'user_id' => $user_id,
]);
$status = $status->result->status;
return $status;
}
$update = json_decode(file_get_contents('php://input'));
if (isset($update)) {
if (isset($update->message)) {
$message = $update->message;
$text = $message->text;
$cid = $message->chat->id;
$mid = $message->message_id;
} elseif (isset($update->callback_query)) {
$data = $update->callback_query->data;
$mid = $update->callback_query->message->message_id;
$cid = $update->callback_query->message->chat->id;
} elseif (isset($update->chat_join_request)) {
$chname = $update->chat_join_request->chat->title;
$chuid = $update->chat_join_request->from->id;
$chid = $update->chat_join_request->chat->id;
$join = $update->chat_join_request;
}
}
if (isset($join)) {
$select = $db->query("SELECT * FROM channels WHERE main_channel=$chid AND secondary_channel IS NOT NULL");
if ($select->num_rows == 1) {
$f = $select->fetch_assoc();
$s_channel = $f['secondary_channel'];
if (in_array(getChatMember($s_channel, $chuid), ['member', 'administrator', 'creator'])) {
approveChatJoinRequest($chid, $chuid);
bot('sendMessage', [
'chat_id' => $chuid,
'text' => "Sizning so'rovingiz tasdiqlandi",
'parse_mode' => "html"
]);
} else {
file_put_contents("cache/" . $chuid . ".txt", $f['id']);
bot('sendMessage', [
'chat_id' => $chuid,
'text' => "Sizning so'rovingiz tasdiqlanishi uchun $s_channel ga obuna bo'ling, siznign so'rovingiz keyin tasdiqlanadi",
'parse_mode' => "html",
'reply_markup' => json_encode([
'inline_keyboard' => [
[['text' => "✅ Obuna bo'ldim", 'callback_data' => "ok"]]
]
])
]);
}
} else {
approveChatJoinRequest($chid, $chuid);
bot('sendMessage', [
'chat_id' => $chuid,
'text' => "Sizning so'rovingiz tasdiqlandi",
'parse_mode' => "html"
]);
}
}
if ($data == "ok") {
$id = file_get_contents("cache/" . $cid . ".txt");
$select = $db->query("SELECT * FROM channels WHERE id=$id");
$f = $select->fetch_assoc();
$s_channel = $f['secondary_channel'];
if (in_array(getChatMember($s_channel, $cid), ['member', 'administrator', 'creator'])) {
$channel_id = $f['main_channel'];
approveChatJoinRequest($channel_id, $cid);
bot('sendMessage', [
'chat_id' => $cid,
'text' => "Sizning so'rovingiz tasdiqlandi",
'parse_mode' => "html"
]);
}
}