feat: max-bot-test initial — full surface coverage
Some checks failed
Deploy Max Bot Test / deploy (push) Failing after 3s
Some checks failed
Deploy Max Bot Test / deploy (push) Failing after 3s
- Slim 4 PSR-15 webhook, PHP-DI 7, Symfony Console 8 - 13 update handlers, 30+ command scenarios, all 7 button types - Composer pulls pkirillw/max-bot-api-php from GitHub vcs - Multi-stage Dockerfile (php-fpm 8.4-alpine) + nginx - docker-compose.yml targets server (npm_default external) - docker-compose.override.yml for local dev (gitignored) - .gitea/workflows/deploy.yml mirrors ghost-blog-bot pattern Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
89
src/Scenario/ChatsScenario.php
Normal file
89
src/Scenario/ChatsScenario.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Scenario;
|
||||
|
||||
use App\Util\ParsedCommand;
|
||||
use Pkirillw\MaxBotApi\Builder\Message as MessageBuilder;
|
||||
use Pkirillw\MaxBotApi\Scheme\Enum\Format;
|
||||
use Pkirillw\MaxBotApi\Scheme\Update\MessageCreatedUpdate;
|
||||
|
||||
final class ChatsScenario extends AbstractScenario
|
||||
{
|
||||
public function handle(MessageCreatedUpdate $update, ParsedCommand $command): void
|
||||
{
|
||||
switch ($command->name) {
|
||||
case 'chats':
|
||||
$this->listChats($update, $command);
|
||||
return;
|
||||
case 'chat':
|
||||
$this->showChat($update, $command);
|
||||
return;
|
||||
case 'chat_membership':
|
||||
$this->showMembership($update, $command);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private function listChats(MessageCreatedUpdate $update, ParsedCommand $command): void
|
||||
{
|
||||
$count = $command->argInt(0, 10);
|
||||
$list = $this->api->chats->getChats($count);
|
||||
$lines = [];
|
||||
foreach ($list->chats as $chat) {
|
||||
$lines[] = sprintf('• `%d` %s (type=%s, members=%d)', $chat->chatId, $chat->title ?? '—', $chat->type?->value ?? '?', $chat->participantsCount);
|
||||
}
|
||||
$text = "*Chats* (count=$count, marker=" . ($list->marker ?? 'null') . ")\n" . ($lines === [] ? '(empty)' : implode("\n", $lines));
|
||||
$this->api->messages->send(
|
||||
MessageBuilder::new()->setChat($update->getChatId())->setText($text)->setFormat(Format::Markdown),
|
||||
);
|
||||
}
|
||||
|
||||
private function showChat(MessageCreatedUpdate $update, ParsedCommand $command): void
|
||||
{
|
||||
$chatId = $command->argInt(0);
|
||||
if ($chatId <= 0) {
|
||||
$this->replyMarkdown($update, 'Usage: `/chat <chatId>`');
|
||||
return;
|
||||
}
|
||||
$chat = $this->api->chats->getChat($chatId);
|
||||
$text = sprintf(
|
||||
"*Chat %d*\ntitle: %s\ntype: %s\nstatus: %s\nowner: %d\nmembers: %d\npublic: %s\nlink: %s\ndescription: %s",
|
||||
$chat->chatId,
|
||||
$chat->title ?? '—',
|
||||
$chat->type?->value ?? '?',
|
||||
$chat->status?->value ?? '?',
|
||||
$chat->ownerId,
|
||||
$chat->participantsCount,
|
||||
$chat->isPublic ? 'yes' : 'no',
|
||||
$chat->link ?? '—',
|
||||
$chat->description ?? '—',
|
||||
);
|
||||
$this->api->messages->send(
|
||||
MessageBuilder::new()->setChat($update->getChatId())->setText($text)->setFormat(Format::Markdown),
|
||||
);
|
||||
}
|
||||
|
||||
private function showMembership(MessageCreatedUpdate $update, ParsedCommand $command): void
|
||||
{
|
||||
$chatId = $command->argInt(0);
|
||||
if ($chatId <= 0) {
|
||||
$this->replyMarkdown($update, 'Usage: `/chat_membership <chatId>`');
|
||||
return;
|
||||
}
|
||||
$m = $this->api->chats->getChatMembership($chatId);
|
||||
$perms = array_map(fn($p) => $p->value, $m->permissions);
|
||||
$text = sprintf(
|
||||
"*Membership in %d*\nisOwner: %s\nisAdmin: %s\njoinTime: %d\npermissions: %s",
|
||||
$chatId,
|
||||
$m->isOwner ? 'yes' : 'no',
|
||||
$m->isAdmin ? 'yes' : 'no',
|
||||
$m->joinTime,
|
||||
$perms === [] ? '(none)' : '`' . implode('`, `', $perms) . '`',
|
||||
);
|
||||
$this->api->messages->send(
|
||||
MessageBuilder::new()->setChat($update->getChatId())->setText($text)->setFormat(Format::Markdown),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user