mkdir("step");
mkdir("ball");
if ($txt == "/test") {
$num1 = rand(1, 30);
$num2 = rand(30, 60);
$javob = $num1 + $num2;
$xato1 = $javob - rand(1, 10);
$xato2 = $javob + rand(1, 10);
$answers = array("$xato1", "$xato2", "$javob");
shuffle($answers);
$true_id = array_keys($answers, "$javob")[0];
$bot->request('SendPoll', [
'chat_id' => $cid,
'question' => $num1 . " + " . $num2 . " = ??",
'allows_multiple_answers' => true,
'type' => 'quiz',
'explanation' => "To'g'ri javob " . $javob . " edi", //malumot berish
'open_period' => 10, //javob berish vaqti
'correct_option_id' => $true_id, //0 dan boshlanadi tog'ri javob varyanti
'is_anonymous' => false, //anonim bolishi
'options' => json_encode($answers),
]);
file_put_contents("step/$cid.txt", $true_id);
file_put_contents("ball/$cid.txt", "0");
}
if (isset($update->poll_answer)) {
$answer_id = $update->poll_answer->option_ids[0];
$user = $update->poll_answer->user->id;
$true_id = file_get_contents("step/$user.txt");
$ball = file_get_contents("ball/$user.txt");
if ($answer_id == $true_id) {
$num1 = rand(1, 30);
$num2 = rand(30, 60);
$javob = $num1 + $num2;
$xato1 = $javob - rand(1, 10);
$xato2 = $javob + rand(1, 10);
$answers = array("$xato1", "$xato2", "$javob");
shuffle($answers);
$true_id = array_keys($answers, "$javob")[0];
file_put_contents("step/$user.txt", $true_id);
$bot->request('SendPoll', [
'chat_id' => $user,
'question' => $num1 . " + " . $num2 . " = ??",
'allows_multiple_answers' => true,
'type' => 'quiz',
'explanation' => "To'g'ri javob " . $javob . " edi", //malumot berish
'open_period' => 10, //javob berish vaqti
'correct_option_id' => $true_id, //0 dan boshlanadi tog'ri javob varyanti
'is_anonymous' => false, //anonim bolishi
'options' => json_encode($answers),
]);
file_put_contents("ball/$user.txt", $ball + 10);
} else {
$bot->request('sendmessage', [
'chat_id' => $user,
'text' => "Siz $ball to'pladingiz va o'yinni yakunladingiz, Yangi test uchun /test"
]);
unlink("ball/$user.txt");
unlink("step/$user.txt");
}
}Kimgadur kerak bolib qolar)
🌚4
<?php
include 'bot.php';
$servername = "localhost";
$username = "your_username";
$password = "your_password";
$dbname = "your_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Bog'lanishda xatolik yuz berdi: " . $conn->connect_error);
}
switch ($txt) {
case 'Tasodifiy videolar':
// Tasodifiy 10 ta video
$sql = "SELECT * FROM videos ORDER BY RAND() LIMIT 10";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$i = 1;
$key = [];
while ($row = $result->fetch_assoc()) {
$video_id = $row['video_id'];
$key[] = ["text" => $i, "callback_data" => $video_id];
$i++;
}
$key = array_chunk($key, 5);
$key[] = [
['text' => '⬅️', 'callback_data' => 'previous'],
['text' => '❌️', 'callback_data' => 'close'],
['text' => '➡️', 'callback_data' => 'next']
];
$sql = "SELECT * FROM videos ORDER BY RAND() LIMIT 1";
$f = $conn->query($sql);
$result = $f->fetch_assoc();
$video = $result['video_url'];
$caption = $result['video_caption'];
$reply_markup = json_encode([
'inline_keyboard' => $key,
]);
$bot->sendVideo($cid, $video, $caption, $reply_markup);
}
break;
}
?>
Kimgadur kerak bo'lib qolar :)
❤2👍2
<?php
function monthFunction($berilganSana) {
$bugun = new DateTime();
$berilganSana = new DateTime($berilganSana);
$farq = $bugun->diff($berilganSana);
$oylar = $farq->y * 12 + $farq->m;
$natija = array();
$oylarMassivi = array(
"Yanvar", "Fevral", "Mart", "Aprel", "May", "Iyun",
"Iyul", "Avgust", "Sentyabr", "Oktyabr", "Noyabr", "Dekabr"
);
$yillar = array();
for ($i = 0; $i < $oylar; $i++) {
$oy = $berilganSana->modify('+1 month')->format('F');
$yil = date('Y', strtotime($berilganSana->format('Y-m-d')));
$yillar[$yil][] = $oy;
}
$natija["ok"] = true;
$natija["result"]["month_count"] = $oylar;
$natija["result"]["month"] = $yillar;
echo json_encode($natija,JSON_PRETTY_PRINT);
}
monthFunction('2023-01-01');
Result:
{
"ok": true,
"result": {
"month_count": 10,
"month": {
"2023": [
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November"
]
}
}
}