* Fixed type in \TgBotLib\Objects\Telegram > Message > fromArray()
where forum_topic_created
is being parsed for forum_topic_edited instead of forum_topic_edited
Updated README.md to reflect the new changes with TamerLib 2.+
This commit is contained in:
parent
fbc472d8de
commit
54e81b4137
7 changed files with 51 additions and 40 deletions
|
@ -63,6 +63,13 @@ input objects for methods that require input objects.
|
||||||
* Updated class type to `final class` in `\TgBotLib\Enums > ThumbnailMimeType`
|
* Updated class type to `final class` in `\TgBotLib\Enums > ThumbnailMimeType`
|
||||||
* Updated class type to `final class` in `\TgBotLib\Enums > UpdateEventType`
|
* Updated class type to `final class` in `\TgBotLib\Enums > UpdateEventType`
|
||||||
* Updated method `\TgBotLib > Bot > handleGetUpdates()` to handle exceptions
|
* Updated method `\TgBotLib > Bot > handleGetUpdates()` to handle exceptions
|
||||||
|
* Updated README.md to reflect the new changes with TamerLib 2.+
|
||||||
|
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
* Fixed type in `\TgBotLib\Objects\Telegram > Message > fromArray()` where `forum_topic_created` is being parsed for
|
||||||
|
forum_topic_edited instead of `forum_topic_edited`
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [6.6.0] - 2023-04-10
|
## [6.6.0] - 2023-04-10
|
||||||
|
|
41
README.md
41
README.md
|
@ -187,21 +187,16 @@ 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\Bot('<BOT TOKEN>');
|
||||||
|
|
||||||
// Set the command handlers
|
// Setup command handlers
|
||||||
$bot->setCommandHandler('start', new \commands\StartCommand());
|
$bot->setCommandHandler('start', new \commands\StartCommand());
|
||||||
$bot->setCommandHandler('hash', new \commands\HashCommand());
|
$bot->setCommandHandler('hash', new \commands\HashCommand());
|
||||||
|
|
||||||
// Initialize the worker & register the handle_update function
|
// Run TamerLib forever.
|
||||||
TamerLib\Tamer::initWorker();
|
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::WORKER);
|
||||||
TamerLib\Tamer::addFunction('handle_update', function (\TamerLib\Objects\Job $job) use ($bot)
|
\TamerLib\tm::addFunction('handle_update', [$bot, 'handleUpdate']);
|
||||||
{
|
\TamerLib\tm::run();
|
||||||
$bot->handleUpdate(\TgBotLib\Objects\Telegram\Update::fromArray(json_decode($job->getData(), true)));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Work forever
|
|
||||||
TamerLib\Tamer::work();
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then create a master process that will send the updates to the worker:
|
Then create a master process that will send the updates to the worker:
|
||||||
|
@ -216,30 +211,20 @@ 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');
|
||||||
|
|
||||||
// Require commands
|
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
||||||
require 'commands' . DIRECTORY_SEPARATOR . 'StartCommand.php';
|
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::CLIENT);
|
||||||
require 'commands' . DIRECTORY_SEPARATOR . 'HashCommand.php';
|
\TamerLib\tm::createWorker(8, __DIR__ . DIRECTORY_SEPARATOR . 'worker.php');
|
||||||
|
|
||||||
// Initialize the bot
|
|
||||||
$bot = new TgBotLib\Bot('bot_token');
|
|
||||||
|
|
||||||
// Initialize the master & add the worker
|
|
||||||
TamerLib\Tamer::init(\TamerLib\Abstracts\ProtocolType::Gearman, [
|
|
||||||
'127.0.0.1:4730'
|
|
||||||
]);
|
|
||||||
TamerLib\Tamer::addWorker('handle_update', 4);
|
|
||||||
|
|
||||||
// Start the workers
|
|
||||||
TamerLib\Tamer::startWorkers();
|
|
||||||
|
|
||||||
// Handle updates forever
|
// Handle updates forever
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
/** @var \TgBotLib\Objects\Telegram\Update $update */
|
// Get updates, push the update object to the worker
|
||||||
foreach ($bot->getUpdates() as $update)
|
foreach ($bot->getUpdates() as $update)
|
||||||
{
|
{
|
||||||
TamerLib\Tamer::do('handle_update', json_encode($update->toArray()));
|
\TamerLib\tm::dof('handle_update', [$update]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
\TamerLib\tm::wait(3);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,11 @@
|
||||||
$this->last_update_id = 0;
|
$this->last_update_id = 0;
|
||||||
$this->command_handlers = [];
|
$this->command_handlers = [];
|
||||||
$this->event_handlers = [];
|
$this->event_handlers = [];
|
||||||
|
|
||||||
|
if(!preg_match('/^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$/', $this->token))
|
||||||
|
{
|
||||||
|
throw new InvalidArgumentException(sprintf('Invalid token "%s"', $this->token));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1298,7 +1298,7 @@
|
||||||
$object->passport_data = isset($data['passport_data']) ? PassportData::fromArray($data['passport_data']) : null;
|
$object->passport_data = isset($data['passport_data']) ? PassportData::fromArray($data['passport_data']) : null;
|
||||||
$object->proximity_alert_triggered = isset($data['proximity_alert_triggered']) ? ProximityAlertTriggered::fromArray($data['proximity_alert_triggered']) : null;
|
$object->proximity_alert_triggered = isset($data['proximity_alert_triggered']) ? ProximityAlertTriggered::fromArray($data['proximity_alert_triggered']) : null;
|
||||||
$object->forum_topic_created = isset($data['forum_topic_created']) ? ForumTopicCreated::fromArray($data['forum_topic_created']) : null;
|
$object->forum_topic_created = isset($data['forum_topic_created']) ? ForumTopicCreated::fromArray($data['forum_topic_created']) : null;
|
||||||
$object->forum_topic_edited = isset($data['forum_topic_created']) ? ForumTopicEdited::fromArray($data['forum_topic_edited']) : null;
|
$object->forum_topic_edited = isset($data['forum_topic_edited']) ? ForumTopicEdited::fromArray($data['forum_topic_edited']) : null;
|
||||||
$object->forum_topic_closed = isset($data['forum_topic_closed']) ? ForumTopicClosed::fromArray($data['forum_topic_closed']) : null;
|
$object->forum_topic_closed = isset($data['forum_topic_closed']) ? ForumTopicClosed::fromArray($data['forum_topic_closed']) : null;
|
||||||
$object->forum_topic_reopened = isset($data['forum_topic_reopened']) ? ForumTopicReopened::fromArray($data['forum_topic_reopened']) : null;
|
$object->forum_topic_reopened = isset($data['forum_topic_reopened']) ? ForumTopicReopened::fromArray($data['forum_topic_reopened']) : null;
|
||||||
$object->general_forum_topic_hidden = isset($data['general_forum_topic_hidden']) ? GeneralForumTopicHidden::fromArray($data['general_forum_topic_hidden']) : null;
|
$object->general_forum_topic_hidden = isset($data['general_forum_topic_hidden']) ? GeneralForumTopicHidden::fromArray($data['general_forum_topic_hidden']) : null;
|
||||||
|
|
19
tests/multi_threaded.php
Normal file
19
tests/multi_threaded.php
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
import('net.nosial.tamerlib');
|
||||||
|
|
||||||
|
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
||||||
|
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::CLIENT);
|
||||||
|
\TamerLib\tm::createWorker(8, __DIR__ . DIRECTORY_SEPARATOR . 'worker.php');
|
||||||
|
|
||||||
|
// Handle updates forever
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
foreach ($bot->getUpdates() as $update)
|
||||||
|
{
|
||||||
|
\TamerLib\tm::dof('handle_update', [$update]);
|
||||||
|
}
|
||||||
|
|
||||||
|
\TamerLib\tm::wait(3);
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
|
|
||||||
$bot = new TgBotLib\Bot(getenv('BOT_TOKEN'));
|
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
||||||
|
|
||||||
$bot->setCommandHandler('start', new \commands\StartCommand());
|
$bot->setCommandHandler('start', new \commands\StartCommand());
|
||||||
$bot->setCommandHandler('hash', new \commands\HashCommand());
|
$bot->setCommandHandler('hash', new \commands\HashCommand());
|
||||||
|
|
|
@ -3,16 +3,11 @@
|
||||||
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
require __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
|
||||||
import('net.nosial.tamerlib');
|
import('net.nosial.tamerlib');
|
||||||
|
|
||||||
$bot = new TgBotLib\Bot('bot_token');
|
$bot = new TgBotLib\Bot('<BOT TOKEN>');
|
||||||
|
|
||||||
$bot->setCommandHandler('start', new \commands\StartCommand());
|
$bot->setCommandHandler('start', new \commands\StartCommand());
|
||||||
$bot->setCommandHandler('hash', new \commands\HashCommand());
|
$bot->setCommandHandler('hash', new \commands\HashCommand());
|
||||||
|
|
||||||
TamerLib\Tamer::initWorker();
|
\TamerLib\tm::initialize(\TamerLib\Enums\TamerMode::WORKER);
|
||||||
|
\TamerLib\tm::addFunction('handle_update', [$bot, 'handleUpdate']);
|
||||||
TamerLib\Tamer::addFunction('handle_update', function (\TamerLib\Objects\Job $job) use ($bot)
|
\TamerLib\tm::run();
|
||||||
{
|
|
||||||
$bot->handleUpdate(\TgBotLib\Objects\Telegram\Update::fromArray(json_decode($job->getData(), true)));
|
|
||||||
});
|
|
||||||
|
|
||||||
TamerLib\Tamer::work();
|
|
Loading…
Add table
Reference in a new issue