Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('/home/webgonit/id/bot/Emoji.php');
- try{
- $db = new PDO ("mysql:host=localhost;dbname=bottelegram;","gonit","b0bc1b62");
- }catch(PDOException $e){
- echo $e->getmessage();
- }
- $bot_user = $db->prepare("SELECT * FROM bot_user");
- $bot_user->execute();
- while($data = $bot_user->fetch(PDO::FETCH_ASSOC)){
- $usernamebot = $data['bot_username'];
- $botToken = $data['token_bot'];
- $bot_message = $db->prepare("SELECT * FROM bot_message");
- $bot_message->execute();
- while($data2 = $bot_message->fetch(PDO::FETCH_ASSOC)){
- $debug = false;
- function request_url($method)
- {
- global $botToken;
- return "https://api.telegram.org/bot" . $botToken . "/". $method;
- }
- function send_reply($chatid, $msgid, $text)
- {
- global $debug;
- $send = array(
- 'chat_id' => $chatid,
- 'text' => $text,
- 'parse_mode' => 'html',
- 'disable_web_page_preview' => true,
- );
- // use key 'http' even if you send the request to https://...
- $options = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
- 'method' => 'POST',
- 'content' => http_build_query($send),
- ),
- );
- $context = stream_context_create($options);
- $result = file_get_contents(request_url('sendMessage'), false, $context);
- if ($debug)
- print_r($result);
- }
- function send_group($chatid, $msgid2, $text)
- {
- global $debug;
- $send2 = array(
- 'chat_id' => $chatid,
- 'text' => $text,
- 'reply_to_message_id' => $msgid2, // <---- biar ada reply nya balasannya, opsional, bisa dihapus baris ini
- 'parse_mode' => 'html',
- );
- // use key 'http' even if you send the request to https://...
- $options2 = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
- 'method' => 'POST',
- 'content' => http_build_query($send2),
- ),
- );
- $context2 = stream_context_create($options2);
- $result2 = file_get_contents(request_url('sendMessage'), false, $context2);
- if ($debug)
- print_r($result2);
- }
- function send_group2($chatid, $msgid3, $text)
- {
- global $debug;
- $send3 = array(
- 'chat_id' => $chatid,
- 'text' => $text,
- 'parse_mode' => 'html',
- );
- // use key 'http' even if you send the request to https://...
- $options3 = array(
- 'http' => array(
- 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
- 'method' => 'POST',
- 'content' => http_build_query($send3),
- ),
- );
- $context3 = stream_context_create($options3);
- $result3 = file_get_contents(request_url('sendMessage'), false, $context3);
- if ($debug)
- print_r($result3);
- }
- // fungsi mengolahan pesan, menyiapkan pesan untuk dikirimkan
- function create_response($text, $message)
- {
- global $usernamebot;
- // inisiasi variable hasil yang mana merupakan hasil olahan pesan
- $hasil = '';
- $fromid = $message["from"]["id"]; // variable penampung id user
- $chatid = $message["chat"]["id"]; // variable penampung id chat
- $pesanid= $message['message_id']; // variable penampung id message
- // variable penampung username nya user
- isset($message["from"]["username"])
- ? $chatuser = $message["from"]["username"]
- : $chatuser = '';
- // variable penampung nama user
- isset($message["from"]["last_name"])
- ? $namakedua = $message["from"]["last_name"]
- : $namakedua = '';
- $namauser = $message["from"]["first_name"]. ' ' .$namakedua;
- //Disini di koreksi karena new chat member tidak menampung teks dibuat kondisi
- if(isset($message['new_chat_member'])){
- $hasil = $text;
- return $hasil; //Hasil langsung direturn supaya kode dibawah tidak dieksekusi
- }
- // ini saya pergunakan untuk menghapus kelebihan pesan spasi yang dikirim ke bot.
- $textur = preg_replace('/\s\s+/', ' ', $text);
- // memecah pesan dalam 2 blok array, kita ambil yang array pertama saja
- $command = explode(' ',$textur,2); //
- // identifikasi perintah (yakni kata pertama, atau array pertamanya)
- switch ($command[0]) {
- // pesan selamat datang
- case '/start':
- $hasil = "<b>$namauser</b> \n";
- $hasil .= "Selamat datang di $usernamebot \n\n";
- $hasil .= "/start - Mulai bot \n";
- $hasil .= "/id - Untuk cek nama, username dan id Anda \n";
- $hasil .= "/timeworld - Cek waktu seluruh dunia, lihat disini format timezone nya <a href='https://www.w3schools.com/php/php_ref_timezones.asp'>Timezone list</a>. Penulisan (/timeworld Asia/Jakarta) \n";
- break;
- // jika ada pesan /id, bot akan membalas dengan menyebutkan idnya user
- case '/id':
- $hasil = "Name: <b>$namauser</b> \n";
- $hasil .= "Username: <b>@$chatuser</b> \n";
- $hasil .= "My ID: <b>$fromid</b> \n";
- break;
- case '/timeworld'.$input2:
- $input = "$text";
- $input2 = substr($input, 10);
- if ($input > "/timeworld $input2") {
- $regex = preg_match('/\/timeworld (.*)/', $input, $hasil);
- date_default_timezone_set($hasil[1]);
- $hasil = "Cek waktu seluruh dunia, lihat disini format timezone nya <a href='https://www.w3schools.com/php/php_ref_timezones.asp'>Timezone list</a>. Penulisan (/timeworld Asia/Jakarta) \n\n";
- $hasil .= "Tanggal: ";
- $hasil .= "<b>";
- $hasil .= date('d/m/Y', time());
- $hasil .= "</b>";
- $hasil .= "\n";
- $hasil .= "Waktu: ";
- $hasil .= "<b>";
- $hasil .= date('H:i:s', time());
- $hasil .= "</b>";
- $hasil .= "\n";
- $hasil .= "Zona: ";
- $hasil .= "<b>";
- $hasil .= date_default_timezone_get();
- $hasil .= "</b>";
- } else if ($input == "/timeworld") {
- $hasil = "Penulisan salah atau kurang lengkap, lihat disini format timezone nya <a href='https://www.w3schools.com/php/php_ref_timezones.asp'>Timezone list</a>. Penulisan (/timeworld Asia/Jakarta)";
- }
- }
- return $hasil;
- }
- function process_message($message)
- {
- try{
- $db2 = new PDO ("mysql:host=localhost;dbname=bottelegram;","gonit","b0bc1b62");
- }catch(PDOException $e){
- echo $e->getmessage();
- }
- //trusted chatid
- $bot_user2 = $db2->prepare("SELECT * FROM bot_user");
- $bot_user2->execute();
- while($data3 = $bot_user2->fetch(PDO::FETCH_ASSOC)){
- $trustedid = $data3["trustedid"];
- //trusted chatgroup
- $bot_message3 = $db2->prepare("SELECT * FROM bot_message");
- $bot_message3->execute();
- while($data4 = $bot_message3->fetch(PDO::FETCH_ASSOC)){
- $trustedgroup = $data4["message_chatid"];
- $updateid = $message["update_id"];
- $messages = $message["message"];
- $trusted = $message["message"]["chat"]["id"];
- $trustgroup = $message["message"]["chat"]["id"];
- $jenis = $message["message"]["chat"]["type"];
- if (isset($messages["text"])) {
- /*
- if($trusted == $trustedid){
- */
- if($jenis == "private"){
- $chatid = $messages["chat"]["id"];
- $message_id = $messages["message_id"];
- $text = $messages["text"];
- }
- /*
- }
- */
- $response = create_response($text, $messages);
- if (!empty($response))
- send_reply($chatid, $message_id, $response);
- }
- //welcome group
- if (isset($messages["new_chat_member"])) {
- $chatid = $messages["chat"]["id"];
- if($chatid == $trustedgroup) {
- $message_id = $messages["message_id"];
- $firstName = $messages["new_chat_member"]["first_name"];
- $title = $messages["chat"]["title"];
- $new_chat_member = "Selamat datang <b>$firstName</b> di $title \n\n ";
- $new_chat_member .= date("d/m/Y, H:i:s");
- }
- $response = create_response($new_chat_member, $messages);
- if (!empty($response))
- send_group($chatid, $message_id, $response);
- }
- return $updateid;
- }
- }
- }
- $entityBody = file_get_contents('php://input');
- $message = json_decode($entityBody, true);
- process_message($message);
- ?>
- <?php
- $pesan = $data2['message_run'];
- $pesan2 = Emoji::Decode($pesan);
- $website = 'https://api.telegram.org/bot'.$botToken;
- $chatId2 = $data2['message_chatid'];
- $params = [
- 'chat_id' => $chatId2,
- 'parse_mode' => 'HTML',
- 'text' => $pesan2,
- 'disable_web_page_preview' => true,
- ];
- $datenow = date('H:i');
- $delay = $data2['message_delay'];
- $daterun = $data2['message_daterun'];
- $timerun = $data2['message_timerun'];
- if ($datenow == $daterun){
- //sendMessage
- $ch = curl_init($website . '/sendMessage');
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $messageid = curl_exec($ch);
- $messageid2 = json_decode($messageid, true);
- curl_close($ch);
- /* print_r($messageid2); */
- //pinChatMessage
- $id = $messageid2['result']['message_id'];
- $chatidbot = $messageid2['result']['chat']['id'];
- $params2 = [
- 'chat_id' => $chatidbot,
- 'message_id' => $id,
- 'disable_notification' => false,
- ];
- $ch2 = curl_init($website . '/pinChatMessage');
- curl_setopt($ch2, CURLOPT_HEADER, false);
- curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch2, CURLOPT_POST, 1);
- curl_setopt($ch2, CURLOPT_POSTFIELDS, $params2);
- curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
- $messageid3 = curl_exec($ch2);
- $messageid4 = json_decode($messageid3, true);
- curl_close($ch2);
- /* print_r($messageid4); */
- $message_timerun = date("H:i", time() + $delay);
- $bot_message2 = $db->prepare("UPDATE bot_message SET message_timerun = :message_timerun");
- $bot_message2->BindParam(':message_timerun',$message_timerun);
- $bot_message2->execute();
- } else if ($datenow == $timerun){
- //sendMessage
- $ch = curl_init($website . '/sendMessage');
- curl_setopt($ch, CURLOPT_HEADER, false);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
- $messageid = curl_exec($ch);
- $messageid2 = json_decode($messageid, true);
- curl_close($ch);
- /* print_r($messageid2); */
- //pinChatMessage
- $id = $messageid2['result']['message_id'];
- $chatidbot = $messageid2['result']['chat']['id'];
- $params2 = [
- 'chat_id' => $chatidbot,
- 'message_id' => $id,
- 'disable_notification' => false,
- ];
- $ch2 = curl_init($website . '/pinChatMessage');
- curl_setopt($ch2, CURLOPT_HEADER, false);
- curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch2, CURLOPT_POST, 1);
- curl_setopt($ch2, CURLOPT_POSTFIELDS, $params2);
- curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
- $messageid3 = curl_exec($ch2);
- $messageid4 = json_decode($messageid3, true);
- curl_close($ch2);
- /* print_r($messageid4); */
- $message_timerun = date("H:i", time() + $delay);
- $bot_message2 = $db->prepare("UPDATE bot_message SET message_timerun = :message_timerun");
- $bot_message2->BindParam(':message_timerun',$message_timerun);
- $bot_message2->execute();
- } else {
- }
- ?>
- <?php } ?>
- <?php } ?>
Add Comment
Please, Sign In to add comment