STRaKER
Umid qilamanki foydasi tegadi
lug'at bot
Kod · PHP147 qator
<?php



include('vendor/autoload.php');

include('config.php');



 use Telegram\Bot\Api;

 use Telegram\Bot\Actions;



 $telegram = new Api('api');



 $result = $telegram -> getWebhookUpdates();



 $text = $result["message"]["text"];



 $chat_id = $result["message"]["chat"]["id"];



 $user_id = $result["message"]["from"]["id"];



$key_haqida = [["Bot haqida"]];

$haqida = $telegram->replyKeyboardMarkup([ 'keyboard' => $key_haqida, 'resize_keyboard' => true, 'one_time_keyboard' => true ]);

$telegram->sendChatAction([ 'chat_id' => $chat_id, 'action' => Actions::TYPING ]);

 if($text){

if ($text == "/start") {

 $reply = "Inglizcha so`zni kiriting men uni tarjimasini sizga jo`nataman ;)";



 $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $haqida ]);



 }elseif ($text == "Bot haqida") {

 $reply = "Inglizcha-O`zbekcha lug`at.

 Dasturchi: Ahrorbek Abdullayev

 E-mail: ahrorbeksoft@mail.ru

 Telegram: @ahrorbeksoft";



 $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply ]);

}else{

//boshlandi

$text = txt($text);

 if (preg_match("- (.*) -", $text, $word2)) {

 $soz = $word2[1];

 $sql_words = mysql_query("SELECT * FROM `en-uz` WHERE `word` = '".input($soz)."' LIMIT 1");

 while ($sozlar = mysql_fetch_assoc($sql_words)) {

 $reply = "<b>".output($sozlar['word'])."</b> - <code>".output($sozlar['meaning'])."</code>";

 }

 $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $haqida, 'parse_mode' => 'HTML' ]);

}else{

$c_words = mysql_result(mysql_query("SELECT COUNT(*) FROM `en-uz` Where `word` Like '".input($text)."%'"), 0); 

$sql_words = mysql_query("SELECT * FROM `en-uz` WHERE `word` like '".input($text)."%' LIMIT 5");

if ($c_words > 1) {

while ($sozlar = mysql_fetch_assoc($sql_words)) {

$klav[] = '- '.$sozlar['word'].' -';

}

$reply = "Bundan so`zdan ".$c_words." ta topildi, quyidagilardan birini tanlang:";

if (count($klav) == 2) {$keyboard = [ [$klav[0]], [$klav[1]] ];}

if (count($klav) == 3) {$keyboard = [ [$klav[0]], [$klav[1]], [$klav[2]] ];}

if (count($klav) == 4) {$keyboard = [ [$klav[0]], [$klav[1]], [$klav[2]], [$klav[3]] ];}

if (count($klav) == 5) {$keyboard = [ [$klav[0]], [$klav[1]], [$klav[2]], [$klav[3]], [$klav[4]] ];}

$reply_markup = $telegram->replyKeyboardMarkup([ 'keyboard' => $keyboard, 'resize_keyboard' => true, 'one_time_keyboard' => true ]);

$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $reply_markup ]);

}elseif($c_words == 1){

while ($sozlar = mysql_fetch_assoc($sql_words)) {

$reply = "<b>".output($sozlar['word'])."</b> - <code>".output($sozlar['meaning'])."</code>";

 $telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $haqida, 'parse_mode' => 'HTML' ]);

 }

}else{

$reply = "Afsuski lug`atda bunday so`z mavjud emas!";

$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => $reply, 'reply_markup' => $haqida ]);

}

}



}

 }else{

$telegram->sendMessage([ 'chat_id' => $chat_id, 'text' => "So`z noto`gri kiritildi!", 'reply_markup' => $haqida ]);

 }

?>