PHP code example of galancev / bot

1. Go to this page and download the library: Download galancev/bot library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

galancev / bot example snippets



/**
 * Пример создания роботов
 */

namespace {
    
}

namespace bot {

    use Galantcev\Components\Bot;

    /**
     * Пример робота
     * Class SampleBot
     * @package bot
     */
    class SampleBot extends Bot
    {
        /**
         * Робот что-нибудь делает
         */
        public function go()
        {
            // Устанавливаем коллбек в случае некорректного завершения робота
            $this->start(function () {
                die('А вот тут у нас случилось прерывание, а ничего успешно не завершено!');
            });
            
            // Устанавливаем коллбек для добавления записи в лог
            $this->log(function ($text) {
                echo $text;
            });

            $this->log->text('Текст');
            $this->log->error('Ошибка!');
            $this->log->warning('Внимание.');
            $this->log->success('Успех :)');

            // А здесь говорим, что на самом деле всё хорошо отработало
            $this->finish();
        }
    }

    $bot = new SampleBot();

    $bot->log->text('Начинаем работу!');

    $bot->go();

    $bot->log->text('Завершаем работу.');
}