From 8f0269f19d26233caa01d3f46b8e238430be5eb9 Mon Sep 17 00:00:00 2001 From: Baptiste Leduc Date: Fri, 17 May 2024 11:43:16 +0200 Subject: [PATCH] Debug QuitTransport --- app/src/Discord/Command/Helper/UserHelper.php | 5 +++ .../Discord/Command/QuitTransportCommand.php | 8 +++- .../Repository/User/FindOrCreateUserDebug.php | 37 +++++++++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 app/src/Repository/User/FindOrCreateUserDebug.php diff --git a/app/src/Discord/Command/Helper/UserHelper.php b/app/src/Discord/Command/Helper/UserHelper.php index eded453..9bc31df 100644 --- a/app/src/Discord/Command/Helper/UserHelper.php +++ b/app/src/Discord/Command/Helper/UserHelper.php @@ -5,6 +5,7 @@ namespace Afup\Hermes\Discord\Command\Helper; use Afup\Hermes\Entity\User; +use Afup\Hermes\Repository\User\FindOrCreateUserDebug; use Discord\Parts\Interactions\Interaction; use Discord\Parts\User\User as DiscordUser; @@ -16,6 +17,10 @@ public function getUserForInteraction(Interaction $interaction): User $discordUser = $interaction->user; $userId = (int) $discordUser->id; + if ($this->findOrCreateUser instanceof FindOrCreateUserDebug) { + return ($this->findOrCreateUser)($userId, $interaction); + } + return ($this->findOrCreateUser)($userId); } } diff --git a/app/src/Discord/Command/QuitTransportCommand.php b/app/src/Discord/Command/QuitTransportCommand.php index 72d2053..e8b110d 100644 --- a/app/src/Discord/Command/QuitTransportCommand.php +++ b/app/src/Discord/Command/QuitTransportCommand.php @@ -13,6 +13,7 @@ use Afup\Hermes\Repository\Event\FindEventByChannel; use Afup\Hermes\Repository\Traveler\GetTravelerListForUserAndEvent; use Afup\Hermes\Repository\User\FindOrCreateUser; +use Afup\Hermes\Repository\User\FindOrCreateUserDebug; use Discord\Builders\CommandBuilder; use Discord\Builders\Components\ActionRow; use Discord\Builders\Components\Button; @@ -34,7 +35,7 @@ public function __construct( private TranslatorInterface $translator, - private FindOrCreateUser $findOrCreateUser, + private FindOrCreateUserDebug $findOrCreateUser, private FindEventByChannel $findEventByChannel, private GetTravelerListForUserAndEvent $getTravelerListForUserAndEvent, private EntityManagerInterface $entityManager, @@ -59,8 +60,10 @@ public function callback(Discord $discord): void return; } + $interaction->respondWithMessage(MessageBuilder::new()->setContent('A')); $user = $this->getUserForInteraction($interaction); + $interaction->respondWithMessage(MessageBuilder::new()->setContent('B')); $travelers = ($this->getTravelerListForUserAndEvent)($user, $event, TravelerType::PASSENGER); if (0 === \count($travelers)) { $interaction->respondWithMessage(MessageBuilder::new()->setContent($this->translator->trans('discord.quit_transport.error.no_transport')), true); @@ -68,6 +71,7 @@ public function callback(Discord $discord): void return; } + $interaction->respondWithMessage(MessageBuilder::new()->setContent('C')); if (1 === \count($travelers)) { $this->validateRemoval($discord, $interaction, $travelers[0]); } else { @@ -89,6 +93,7 @@ public function callback(Discord $discord): void $message->addComponent($chooseAction); } + $interaction->respondWithMessage(MessageBuilder::new()->setContent('D')); $interaction->respondWithMessage($message, true); } }); @@ -96,6 +101,7 @@ public function callback(Discord $discord): void private function validateRemoval(Discord $discord, Interaction $interaction, Traveler $traveler): void { + $interaction->respondWithMessage(MessageBuilder::new()->setContent('E')); $embed = new Embed($discord); $embed->setTitle($this->translator->trans('discord.quit_transport.confirmation')); diff --git a/app/src/Repository/User/FindOrCreateUserDebug.php b/app/src/Repository/User/FindOrCreateUserDebug.php new file mode 100644 index 0000000..97db1c2 --- /dev/null +++ b/app/src/Repository/User/FindOrCreateUserDebug.php @@ -0,0 +1,37 @@ +respondWithMessage(MessageBuilder::new()->setContent('Début')); + $userRepository = $this->entityManager->getRepository(User::class); + $interaction->respondWithMessage(MessageBuilder::new()->setContent('Repository')); + + /** @var User|null $user */ + $user = $userRepository->findOneBy(['userId' => $userId]); + $interaction->respondWithMessage(MessageBuilder::new()->setContent($user instanceof User ? 'OK' : 'KO')); + if (null === $user) { + $user = new User($userId); + $this->entityManager->persist($user); + $this->entityManager->flush(); + } + $interaction->respondWithMessage(MessageBuilder::new()->setContent('return')); + + return $user; + } +}