T
T
Treimox2022-03-11 09:44:51
PHP
Treimox, 2022-03-11 09:44:51

How to delay a command in a VKontakte bot?

I created a bot based on the Callback API , I took the basis for the code from this site - here
I don’t quite understand how to create a delay for the command. Can you please explain - how to create this very delay? I want to make an approximate delay construction -

- The user enters a command (if for the first time), the bot answers him with the code that I entered.
After that, 24 hours should pass, that is, a day.
- If the user enters a command earlier than a day before, then a message is displayed stating that the command has already been used.

The command code itself is

else if ($message == '/писюн') {

    
    $userInfo = $vk->request("users.get", ["user_ids" => $vk_id]);
    $first_name = $userInfo[0]['first_name']; // Имя пользователя
    $last_name = $userInfo[0]['last_name']; // Фамилия пользователя
    
    $sm = dbquery("SELECT * FROM usrazmer WHERE vk_id = $vk_id")->fetch();
    
    $raz = (mt_rand(1, 15));
    
    if (dbquery("SELECT vk_id FROM usrazmer WHERE vk_id = $vk_id")->fetchAll(PDO::FETCH_ASSOC)) {
                    $otv = 1;
                }
                     if ($otv) {
                        switch (mt_rand(0, 1)) {
                        
                        case 0: $vk->sendMessage($peer_id, "❓@id$vk_id($first_name $last_name)  твій пісюн виріс на $raz см. Тепер його довжина " . $sm['razmer'] . " см"); break; {
                             
                            $sm = dbquery("SELECT * FROM usrazmer WHERE vk_id = $vk_id")->fetch();
                             
                            for ($i = $sm['razmer']; $i < $raz; $i++);
                                $db->query("UPDATE usrazmer SET razmer WHERE razmer = $i");
                        }
                        case 1: $vk->sendMessage($peer_id, "❓@id$vk_id($first_name $last_name)  твій пісюн зменшився на $raz см. Тепер його довжина " . $sm['razmer'] ." см"); break;
                        };
                    } else {
                 
                $db->query("INSERT INTO usrazmer (vk_id, razmer) VALUES ($vk_id, $raz)");
               
                $vk->sendMessage($peer_id, "❓@id$vk_id($first_name $last_name) вітаю в грі писюн, ти зіграв в перший раз і зараз твій пісюн має довжину $raz см");

                    }

}

I ask you not to pay attention to the motive of the team.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2022-03-11
@Treimox

So store the time of the user's last access to the bot in the database along with the size of the pisyun. When a command arrives, select from the database along with the data and the time of the last call. Compare it with the current one and either display an error, or do what you wanted there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question