/* //-------------------------------------- ip checker $telegram_ip_ranges = [ ['lower' => '149.154.160.0', 'upper' => '149.154.175.255'], // literally 149.154.160.0/20 ['lower' => '91.108.4.0', 'upper' => '91.108.7.255'], // literally 91.108.4.0/22 ]; $ip_dec = (float) sprintf("%u", ip2long($_SERVER['REMOTE_ADDR'])); $ok=false; foreach ($telegram_ip_ranges as $telegram_ip_range) if (!$ok) { $lower_dec = (float) sprintf("%u", ip2long($telegram_ip_range['lower'])); $upper_dec = (float) sprintf("%u", ip2long($telegram_ip_range['upper'])); if ($ip_dec >= $lower_dec and $ip_dec <= $upper_dec) $ok=true; } if (!$ok) die("Are You Okay ?"); //-------------------------------------- times and data //$est_time = ini_set('date.timezone', 'US/Eastern'); //set time zoon ini_set('date.timezone', 'Asia/Tehran'); $time_h_i = date('H:i'); $date = date('y-m-d'); //-------------------------------------- $hello = "hello"; //-------------------------------------- $bot_url = "https://api.telegram.org/bot6726949554:AAHAHV1EQaDNFHHmRsTo57l0umW0OXwqbQY"; //-------------------------------------- $update = file_get_contents("php://input"); $update_array = json_decode($update, true); if(isset($update_array["callback_query"])) { $callback_id= $update_array["callback_query"]["id"]; $data = $update_array["callback_query"]["data"]; $chat_id = $update_array["callback_query"]["message"]["chat"]["id"]; $first_name = $update_array["callback_query"]["message"]["chat"]["first_name"]; $last_name = $update_array["callback_query"]["message"]["chat"]["last_name"]; $message_id = $update_array["callback_query"]["message"]["message_id"]; detect_callback_received_and_reply(); } else if(isset($update_array["message"])) { $text = $update_array["message"]["text"]; $chat_id = $update_array["message"]["chat"]["id"]; $chat_title = $update_array["message"]["chat"]["title"]; $new_chat_parti = $update_array["message"]["new_chat_participant"]["username"]; $message_id = $update_array["message"]["message_id"]; $thread_id = $update_array["message"]["message_thread_id"]; $msg_from = $update_array["message"]["from"]["id"]; $language_code = $update_array["message"]["from"]["language_code"]; $first_name = $update_array["message"]["from"]["first_name"]; $last_name = $update_array["message"]["from"]["last_name"]; $username = $update_array["message"]["from"]["username"]; //-------------------------------------- // $reply = "$text \n\n" . $update; // $url = $GLOBALS['bot_url']."/sendMessage"; // $post_params = [ // 'chat_id' => "101863118" , // 'text' => $reply , // ]; // send_reply($url, $post_params); //-------------------- if($new_chat_parti == "Birthdaysashahep_bot") { $reply = "Thanks for adding me to your Group!"; $url = $GLOBALS['bot_url']."/sendMessage"; $post_params = [ 'chat_id' => "$chat_id" , 'text' => $reply , ]; send_reply($url, $post_params); } if (isset($update_array["message"]["reply_to_message"])) { $text_replied = $update_array["message"]["reply_to_message"]["text"]; $chat_id_replied = $update_array["message"]["reply_to_message"]["id"]; $message_id_replied = $update_array["message"]["reply_to_message"]["message_id"]; } if ($chat_id == '73241507') { admin_settings(); return; } //-------------------------- detect_text_received_and_reply(); //-------------------------- $ch = substr($text, 0, 1); if($ch == '/') detect_command_and_reply(); } //------------------------------------- function admin_settings() { $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot WHERE month ='01'"); while($row = $result -> fetch_assoc()) { $id_db1 = $row['id']; } //------------------------ for($num=1;$num<=$id_db1;$num++) { $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot WHERE id = '$num'"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; $name = $row['name']; $month = $row['month']; } $reply = "$id_db\n\n$name\n\n$month"; $url = $GLOBALS['bot_url']."/sendMessage"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'text' => $reply , // 'photo' => "$photo_year", // 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); } $connection -> close(); } //------------------------------------- function detect_text_received_and_reply() { $text = $GLOBALS['text']; $chat_id = $GLOBALS['chat_id']; $message_id = $GLOBALS['message_id']; $thread_id = $GLOBALS['thread_id']; $username = $GLOBALS['username']; $first_name = $GLOBALS['first_name']; $last_name = $GLOBALS['last_name']; $text_replied = $GLOBALS['text_replied']; $update_array = $GLOBALS['update_array']; $hello = $GLOBALS['hello']; $msg_id = $message_id-1; //----------------------------- $photo_year = "https://bot.kanap.ir/saeed_bots/photo_2024-04-12_19-08-46-year.jpg"; $hello_test = file_get_contents("https://api.telegram.org/bot6726949554:AAHAHV1EQaDNFHHmRsTo57l0umW0OXwqbQY/getUpdates?chat_id=$chat_id&message_id=$msg_id"); $reply = "$message_id\n\n $hello_test"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => "$photo_year", // 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); } //------------------------------------- function detect_callback_received_and_reply() { $first_name = $GLOBALS['first_name']; $chat_id = $GLOBALS['chat_id']; $callback_data = $GLOBALS['data']; $message_id = $GLOBALS['message_id']; $first_name = $GLOBALS['first_name']; $last_name = $GLOBALS['last_name']; //---------------------- $photo_day = "https://bot.kanap.ir/saeed_bots/photo_2024-04-12_19-08-38-day.jpg"; switch($callback_data) { case ("far") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '01' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("ord") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '02' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("kho") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '03' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("tir") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '04' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("mor") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '05' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("sha") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '06' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("meh") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '07' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("aba") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '08' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("aza") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '09' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("dey") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '10' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("bah") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '11' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; case ("esf") : $connection = connect_to_db(); $result = $connection -> query("SELECT * FROM Birthdaysashahep_bot"); while($row = $result -> fetch_assoc()) { $id_db = $row['id']; } $connection -> query("UPDATE Birthdaysashahep_bot SET month = '12' WHERE id = $id_db"); $connection -> close(); //------------------------ $reply = "لطفا روز تولد را انتخاب کنید:"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => $photo_day, 'reply_markup' => $json_kb , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); break; } } //------------------------------------- function detect_command_and_reply() { $text = $GLOBALS['text']; $chat_id = $GLOBALS['chat_id']; $thread_id = $GLOBALS['thread_id']; $first_name = $GLOBALS['first_name']; $username = $GLOBALS['username']; if ($text == "/start" ) { show_menu(); } if ($text == "/add" ) { show_add(); } } //------------------------------------- function show_menu() { $first_name = $GLOBALS['first_name']; $username = $GLOBALS['username']; $chat_id = $GLOBALS['chat_id']; $thread_id = $GLOBALS['thread_id']; $lastname = $GLOBALS['lastfirstname']; $connection = connect_to_db(); $connection -> query("UPDATE Birthdaysashahep_bot SET username = '$username' WHERE telegram_id = $chat_id"); $connection -> query("INSERT INTO Birthdaysashahep_bot (telegram_id,username) VALUES ('$chat_id','$username')"); $connection -> close(); //------------------------- add to group inline keyboard $reply = "*به ربات تاریخ تولد خوش آمدید*🥳\n\nfor new birthday add please click /add"; $pic_url = "https://bot.kanap.ir/saeed_bots/photo_2024-04-12_16-42-15.jpg"; $url = $GLOBALS['bot_url']."/sendPhoto"; $post_params = [ 'chat_id' => $GLOBALS['chat_id'] , 'message_thread_id' => $GLOBALS['thread_id'], 'caption' => $reply , 'photo' => "$pic_url", 'reply_markup' => $json_kb_add , 'parse_mode' => 'Markdown' ]; send_reply($url, $post_params); } //------------------------------------- function show_add() { } //------------------------------------- function check_channel_member($channel , $chat_id){ $result = file_get_contents($GLOBALS['bot_url'] . "/getChatMember?chat_id=@$channel&user_id=$chat_id"); $result_array = json_decode($result , true); if(isset($result_array['result']['user']) && $result_array['result']['status'] == "member"){ return "yes"; } elseif($result_array['result']['status'] == "administrator"){ return "yes"; } elseif($result_array['result']['status'] == "creator"){ return "yes"; } else{ return "no"; } } //------------------------------------- function nice_number($n) { // first strip any formatting; $n = (0+str_replace(",", "", $n)); // is this a number? if (!is_numeric($n)) return false; // now filter it; if ($n > 1000000000000) return round(($n/1000000000000), 2).' T'; elseif ($n > 1000000000) return round(($n/1000000000), 2).' B'; elseif ($n > 1000000) return round(($n/1000000), 2).' M'; elseif ($n > 1000) return round(($n/1000), 2).' t'; return number_format($n,2); } //------------------------------------- Formatting decimal numbers and counting zeros after the decimal point function sigFig($num) { $num_as_string = number_format($num,PHP_FLOAT_DIG,'.',''); $zeros = strspn($num_as_string, "0", strpos($num_as_string, ".")+1); return num_format($num, (3+$zeros), '.', ','); } //------------------------------------- function num_format($numVal,$afterPoint=2,$minAfterPoint=0,$thousandSep=",",$decPoint=".") { // Same as number_format() but without unnecessary zeros. $ret = number_format($numVal,$afterPoint,$decPoint,$thousandSep); if($afterPoint!=$minAfterPoint){ while(($afterPoint>$minAfterPoint) && (substr($ret,-1) =="0") ){ // $minAfterPoint!=$minAfterPoint and number ends with a '0' // Remove '0' from end of string and set $afterPoint=$afterPoint-1 $ret = substr($ret,0,-1); $afterPoint = $afterPoint-1; } } if(substr($ret,-1)==$decPoint) {$ret = substr($ret,0,-1);} return $ret; } //------------------------------------- function connect_to_db() { $connection = new mysqli("localhost", "cp53656_bot_admin", "upxFAvGahVrV", "cp53656_bot-db"); if ($connection -> connect_error) echo "Failed to connect to db: " . $connection -> connect_error; $connection -> query("SET NAMES utf8mb4"); return $connection; } //------------------------------------- function send_reply($url, $post_params) { $cu = curl_init(); curl_setopt($cu, CURLOPT_URL, $url); curl_setopt($cu, CURLOPT_POSTFIELDS, $post_params); curl_setopt($cu, CURLOPT_RETURNTRANSFER, true); // get result $result = curl_exec($cu); curl_close($cu); return $result; } //------------------------------------- ?>