@@ -33,8 +33,8 @@ use ZenithGram\ZenithGram\Bot;
3333$tg = ZG::create('ТОКЕН_БОТА');
3434$bot = new Bot($tg);
3535
36- $bot->onCommand('ban', '/ban %w ')
37- ->func(function(ZG $tg, $banned_user ) {
36+ $bot->onCommand('ban', '/ban {user} ')
37+ ->func(function(ZG $tg, string $user ) {
3838 $tg->msg("✅ Пользователь `{$banned_user}` забанен")->send();
3939
4040 })
@@ -54,9 +54,9 @@ use ZenithGram\ZenithGram\Bot;
5454$tg = ZG::create('ТОКЕН_БОТА');
5555$bot = new Bot($tg);
5656
57- $bot->onCommand('ban', '/ban %w ')
58- ->func(function(ZG $tg, $banned_user ) {
59- $tg->msg("✅ Пользователь `{$banned_user }` забанен")->send();
57+ $bot->onCommand('ban', '/ban {user} ')
58+ ->func(function(ZG $tg, $user ) {
59+ $tg->msg("✅ Пользователь `{$user }` забанен")->send();
6060
6161 })
6262 ->access(123456, function(ZG $tg) {
@@ -2011,7 +2011,8 @@ description: Выполняет пользовательскую функцию-
20112011
20122012* `ZG` - экземпляр основного класса.
20132013 Ваша функция может принимать аргументы, извлеченные из сообщения пользователя:
2014- * Для `onCommand`: значения, соответствующие плейсхолдерам (`%w`, `%n`, `%s`), или все аргументы команды.
2014+ * Для `onCommand`: значения, соответствующие плейсхолдерам (`{name}`, `{age}`), или все аргументы команды.
2015+ * Для `onCallback`: значения, соответствующие плейсхолдерам (`{name}`, `{age}`).
20152016* Для `onTextPreg`: значения совпадений из `preg_match`.
20162017* Для `onReferral`: значения из реферальной ссылки.
20172018* Для `onLeftChatMember`: экземпляр класса `UserDto`.
@@ -2030,7 +2031,7 @@ $tg = ZG::create('ТОКЕН_БОТА');
20302031$bot = new Bot($tg);
20312032
20322033// Пример с onCommand и аргументами
2033- $bot->onCommand('ban', '!ban %w %s ')
2034+ $bot->onCommand('ban', '!ban {username} {reason} ')
20342035 ->func(function(ZG $tg, string $username, string $reason) {
20352036 // Здесь может быть ваша логика: запись в БД, проверка прав и т.д.
20362037 $tg->msg("✅ Пользователь `{$username}` забанен по причине: `{$reason}`")
@@ -3457,13 +3458,13 @@ use ZenithGram\ZenithGram\Bot;
34573458$tg = ZG::create('ТОКЕН_БОТА');
34583459$bot = new Bot($tg);
34593460
3460- $bot->onCommand('ban', '/ban %w ')
3461- ->func(function(ZG $tg, string $bunned_user ) {
3461+ $bot->onCommand('ban', '/ban {username} ')
3462+ ->func(function(ZG $tg, string $username ) {
34623463 $tg->msg("✅ Пользователь `{$bunned_user}` забанен")->send();
34633464
34643465 })
34653466 ->middleware(function(ZG $tg, callable $next) {
3466- $user_id = $tg->getUserID ();
3467+ $user_id = $tg->getUserId ();
34673468 if ($user_id === 123456) {
34683469 $next();
34693470 } else {
@@ -3824,9 +3825,9 @@ use ZenithGram\ZenithGram\Bot;
38243825$tg = ZG::create('ТОКЕН_БОТА');
38253826$bot = new Bot($tg);
38263827
3827- $bot->onCommand('ban', '/ban %w ')
3828- ->func(function(ZG $tg, $arg1 ) {
3829- $tg->msg("✅ Пользователь `{$arg1 }` забанен")->send();
3828+ $bot->onCommand('ban', '/ban {username} ')
3829+ ->func(function(ZG $tg, $username ) {
3830+ $tg->msg("✅ Пользователь `{$username }` забанен")->send();
38303831
38313832 })
38323833 ->noAccess(123456); // Только пользователь с ID 123456 не может использовать команду
@@ -3845,9 +3846,9 @@ use ZenithGram\ZenithGram\Bot;
38453846$tg = ZG::create('ТОКЕН_БОТА');
38463847$bot = new Bot($tg);
38473848
3848- $bot->onCommand('ban', '/ban %w ')
3849- ->func(function(ZG $tg, $arg1 ) {
3850- $tg->msg("✅ Пользователь `{$arg1 }` забанен")->send();
3849+ $bot->onCommand('ban', '/ban {username} ')
3850+ ->func(function(ZG $tg, $username ) {
3851+ $tg->msg("✅ Пользователь `{$username }` забанен")->send();
38513852
38523853 })
38533854 ->noAccess(123456, function(ZG $tg) {
@@ -8149,11 +8150,11 @@ public function onCommand(string $id, array|string $command = null): Action
81498150$bot->onCommand('ping', '!ping')->text('Pong!');
81508151
81518152// Команда бана: !ban 12345 причина
8152- $bot->onCommand('ban', '!ban %n %s ')
8153- ->func(function(ZG $tg, $userId , $reason) {
8154- // $userId = 12345 (int)
8153+ $bot->onCommand('ban', '!ban {user_id} {reason} ')
8154+ ->func(function(ZG $tg, $user_id , $reason) {
8155+ // $user_id = 12345 (int)
81558156 // $reason = "причина" (string)
8156- $tg->reply("Пользователь {$userId } забанен. Причина: {$reason}");
8157+ $tg->reply("Пользователь {$user_id } забанен. Причина: {$reason}");
81578158 });
81588159```
81598160
@@ -8271,11 +8272,11 @@ $bot->onBotCommand('actions', '/actions')
82718272 ]);
82728273
82738274// Ловим паттерн: слово_число_слово
8274- $bot->onCallback('ban_handler', 'ban_%n_%w ')
8275- ->func(function (ZG $tg, $userId, $reason) {
8275+ $bot->onCallback('ban_handler', 'ban_{user_id}_{reason} ')
8276+ ->func(function (ZG $tg, string $user_id, string $reason) {
82768277 // Аргументы автоматически попадают в функцию в нужном порядке
8277- // $userId = 55 (int)
8278- // $reason = "spam" (string)
8278+ // $user_id = 55
8279+ // $reason = "spam"
82798280
82808281 $tg->answerCallbackQuery($tg->getQueryId(), ['text' => "Забанен!"]);
82818282 $tg->reply("Пользователь #{$userId} заблокирован за {$reason}.");
@@ -8930,7 +8931,7 @@ use ZenithGram\ZenithGram\LongPoll;
89308931use ZenithGram\ZenithGram\ZG;
89318932use ZenithGram\ZenithGram\Bot;
89328933
8933- $lp = LongPoll::create('ТОКЕН_БОТА', 20 );
8934+ $lp = LongPoll::create('ТОКЕН_БОТА');
89348935$bot = new Bot(); // Создаем экземпляр бота без основного класса
89358936
89368937$bot->onMessage()->func(function(ZG $tg) {
@@ -9000,7 +9001,7 @@ $bot->onBotCommand('img', '/img')
90009001 ->text('Изображение с котиком');
90019002
90029003// Обработка команды с параметрами
9003- $bot->onCommand('sum', '!посчитай %n + %n ')
9004+ $bot->onCommand('sum', '!посчитай {number1} + {number2} ')
90049005 ->func(function (ZG $tg, $number1, $number2) {
90059006 $tg->msg($number1 + $number2)->send();
90069007 });
0 commit comments