Update bot initialization to BotOld
; configure PHPUnit
This commit is contained in:
parent
17e31c9bce
commit
20735b36db
2 changed files with 15 additions and 10 deletions
5
.idea/php.xml
generated
5
.idea/php.xml
generated
|
@ -25,6 +25,11 @@
|
||||||
<component name="PhpStanOptionsConfiguration">
|
<component name="PhpStanOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="PhpUnit">
|
||||||
|
<phpunit_settings>
|
||||||
|
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="" phpunit_phar_path="$USER_HOME$/phpunit.phar" />
|
||||||
|
</phpunit_settings>
|
||||||
|
</component>
|
||||||
<component name="PsalmOptionsConfiguration">
|
<component name="PsalmOptionsConfiguration">
|
||||||
<option name="transferred" value="true" />
|
<option name="transferred" value="true" />
|
||||||
</component>
|
</component>
|
||||||
|
|
20
README.md
20
README.md
|
@ -90,7 +90,7 @@ The library requires PHP 8.0 or higher.
|
||||||
require 'ncc';
|
require 'ncc';
|
||||||
import('net.nosial.tgbotlib');
|
import('net.nosial.tgbotlib');
|
||||||
|
|
||||||
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
$bot = new TgBotLib\BotOld('<BOT TOKEN>');
|
||||||
|
|
||||||
/** @var \TgBotLib\Objects\Telegram\Update $update */
|
/** @var \TgBotLib\Objects\Telegram\Update $update */
|
||||||
foreach ($bot->getUpdates() as $update)
|
foreach ($bot->getUpdates() as $update)
|
||||||
|
@ -147,7 +147,7 @@ To implement a single-threaded bot, it's very self-explanatory, you just need to
|
||||||
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
|
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
|
||||||
|
|
||||||
// Create a new instance of the bot
|
// Create a new instance of the bot
|
||||||
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
|
$bot = new TgBotLib\BotOld(getenv('BOT_TOKEN'));
|
||||||
|
|
||||||
// Loop forever
|
// Loop forever
|
||||||
while(true)
|
while(true)
|
||||||
|
@ -187,7 +187,7 @@ First create a worker process that will handle the updates:
|
||||||
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
|
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
|
||||||
|
|
||||||
// Initialize the bot
|
// Initialize the bot
|
||||||
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
$bot = new TgBotLib\BotOld('<BOT TOKEN>');
|
||||||
|
|
||||||
// Setup command handlers
|
// Setup command handlers
|
||||||
$bot->setCommandHandler('start', new \commands\StartCommand());
|
$bot->setCommandHandler('start', new \commands\StartCommand());
|
||||||
|
@ -211,7 +211,7 @@ Then create a master process that will send the updates to the worker:
|
||||||
import('net.nosial.tgbotlib');
|
import('net.nosial.tgbotlib');
|
||||||
import('net.nosial.tamerlib');
|
import('net.nosial.tamerlib');
|
||||||
|
|
||||||
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
$bot = new TgBotLib\BotOld('<BOT TOKEN>');
|
||||||
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::CLIENT);
|
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::CLIENT);
|
||||||
\TamerLib\tm::createWorker(8, __DIR__ . DIRECTORY_SEPARATOR . 'worker.php');
|
\TamerLib\tm::createWorker(8, __DIR__ . DIRECTORY_SEPARATOR . 'worker.php');
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ the `/start` command, you can use the `setCommandHandler` method:
|
||||||
require 'ncc';
|
require 'ncc';
|
||||||
import('net.nosial.tgbotlib');
|
import('net.nosial.tgbotlib');
|
||||||
|
|
||||||
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
|
$bot = new TgBotLib\BotOld(getenv('BOT_TOKEN'));
|
||||||
$bot->setCommandHandler('start', new \commands\StartCommand());
|
$bot->setCommandHandler('start', new \commands\StartCommand());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -261,13 +261,13 @@ all the information about the update.
|
||||||
|
|
||||||
namespace commands;
|
namespace commands;
|
||||||
|
|
||||||
use TgBotLib\Bot;
|
use TgBotLib\BotOld;
|
||||||
use TgBotLib\Interfaces\CommandInterface;
|
use TgBotLib\Interfaces\CommandInterface;
|
||||||
use TgBotLib\Objects\Telegram\Update;
|
use TgBotLib\Objects\Telegram\Update;
|
||||||
|
|
||||||
class StartCommand extends CommandInterface
|
class StartCommand extends CommandInterface
|
||||||
{
|
{
|
||||||
public function handle(Bot $bot, Update $update): void
|
public function handle(BotOld $bot, Update $update): void
|
||||||
{
|
{
|
||||||
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
|
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
|
||||||
}
|
}
|
||||||
|
@ -284,7 +284,7 @@ Event handles are similarly implemented, but instead of using the `setCommandHan
|
||||||
|
|
||||||
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
|
$bot = new TgBotLib\BotOld(getenv('BOT_TOKEN'));
|
||||||
|
|
||||||
$bot->setEventHandler('message', new \events\MessageEvent());
|
$bot->setEventHandler('message', new \events\MessageEvent());
|
||||||
```
|
```
|
||||||
|
@ -296,13 +296,13 @@ And the interface EventInterface is used instead of CommandInterface:
|
||||||
|
|
||||||
namespace events;
|
namespace events;
|
||||||
|
|
||||||
use TgBotLib\Bot;
|
use TgBotLib\BotOld;
|
||||||
use TgBotLib\Interfaces\EventInterface;
|
use TgBotLib\Interfaces\EventInterface;
|
||||||
use TgBotLib\Objects\Telegram\Update;
|
use TgBotLib\Objects\Telegram\Update;
|
||||||
|
|
||||||
class MessageEvent implements EventInterface
|
class MessageEvent implements EventInterface
|
||||||
{
|
{
|
||||||
public function handle(Bot $bot, Update $update): void
|
public function handle(BotOld $bot, Update $update): void
|
||||||
{
|
{
|
||||||
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
|
$bot->sendMessage($update->getMessage()->getChat()->getId(), 'Hello World!');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue