<?php
/* * * * * * * * * * * 
In The Name of God 
* * * * * * * * * *
Telegram : @t000c
https://t.me/bomb_Source
https://t.me/my_oj
* * * * * * * * * * */
error_reporting(false);
function bomb_Source($method, $post = [])
{
    $cp = curl_init('https://api.telegram.org/bot' . $GLOBALS['config']['token'] . '/' . $method);
    curl_setopt_array($cp, [
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => $post,
        CURLOPT_RETURNTRANSFER => true
    ]);
    return json_decode(curl_exec($cp), true);
    curl_close($cp);
}
$update = json_decode(file_get_contents('php://input'), true);
if (!is_null($update['message'])) {
    $message = $update['message'];
    $reply = $message['reply_to_message'];
    $text = $message['text'];
    $chatid = $message['chat']['id'];
    $chattype = $message['chat']['type'];
    $messageid = $message['id'];
}
$url_pattern = '/(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w]([-\d\w]{0,253}[\d\w])?\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.,\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.,\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.,\/\d\w]|%[a-fA-f\d]{2,2})*)?$/';
//مقادیر خواسته شده رو پر کنید
$config = [
    'token' => '1227988820:AAHu53j9Tnb6nRlZzINuzOtxIIlQFixpLuk', //توکن ربات
    'channel' => '@ZZ_Squad', //یوزرنیم کانال در صورت فعال بودن قفل عضویت
    'channel_id' => '-1001230459005', //شناسه کانال
    'invite_link' => 'https://t.me/ZZ_Squad' //لینک کانال
];

if ( preg_match("/@[\w\-]+/", $message['caption']))
{$pattern = '/@[\w\-]+/';
$replacement = '🆔@ZZ_Squad';
$message2 = preg_replace($pattern, $replacement, $message['caption']);}
//
if (preg_match($url_pattern, $message['caption'])) {
$replacement=' ';    
$message2 = preg_replace($url_pattern, $replacement, $message['caption']);}
//
if ($chattype != 'private') bomb_Source('leaveChat', ['chat_id' => $chatid]);
/*if (!in_array(bomb_Source('getChatMember', ['chat_id' => $config['channel_id'], 'user_id' => $chatid])['result']['status'], ['creator', 'administrator', 'member'])) {
    bomb_Source('sendMessage', [
        'chat_id' => $chatid,
        'text' => 'برای استفاده از ربات و حمایت از ما باید در کانال ما *عضو* شوید!' . PHP_EOL . $config['channel'],
        'parse_mode' => 'Markdown',
        'reply_markup' => json_encode([
            'inline_keyboard' => [
                [['text' => 'عضویت', 'url' => $config['invite_link']]]
            ]
        ])
    ]);
    return false;
}*/
//اگه میخواین قفل کانال فعال باشه لاین 38 تا 50 رو از کامنت خارج کنین
elseif (preg_match('/^\/start/i', $text)) {
    bomb_Source('sendMessage', [
        'chat_id' => $chatid,
        'text' => 'سلام به ربات خیلی خوش آمدید!' . PHP_EOL . 'شما میتوانید متن یا هر گونه رسانه(عکس،فیلم،...) برای ربات ما ارسال کنید تا ربات آن را بلافاصله برای شما ارسال کند تا با خیال راحت آن را به دیگران ارسال کنید' . PHP_EOL . 'همچنین میتواند بعد از ارسال کپشن رسانه ارسالی خود را نیز عوض کنید!' . PHP_EOL . $config['channel']
    ]);
} else {
    if (isset($text)) {
        if (isset($reply) && is_null($reply['text'])) {
            $media = ['photo', 'video', 'document', 'audio', 'voice', 'video_note', 'sticker'];
            $mediatype = array_intersect(array_keys($reply), $media);
            bomb_Source('send' . str_replace('_', null, end($mediatype)), [
                'chat_id' => $chatid,
                end($mediatype) => $reply[end($mediatype)]['file_id'] ?: end($reply[end($mediatype)])['file_id'],
                'caption' => $text
            ]);
        } else {
            bomb_Source('sendMessage', [
                'chat_id' => $chatid,
                'text' => $text,
                'reply_to_message_id' => $messageid,
                'disable_web_page_preview' => true
            ]);
        }
    } else {
        $media = ['photo', 'video', 'document', 'audio', 'voice', 'video_note', 'sticker'];
        $mediatype = array_intersect(array_keys($message), $media);
        bomb_Source('send' . str_replace('_', null, end($mediatype)), [
            'chat_id' => $chatid,
            end($mediatype) => $message[end($mediatype)]['file_id'] ?: end($message[end($mediatype)])['file_id'],
            'caption' => $message2,
            'reply_markup' => json_encode(['force_reply' => true, 'selective' => true])
        ]);
    }
}
/* * * * * * * * * * * 
In The Name of God 
* * * * * * * * * *
Telegram : @t000c
https://t.me/bomb_Source
https://t.me/my_oj
* * * * * * * * * * */