Skip to content

Commit

Permalink
Debug QuitTransport
Browse files Browse the repository at this point in the history
  • Loading branch information
Korbeil committed May 17, 2024
1 parent f68e83d commit 3f1663c
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/src/Discord/Command/Helper/UserHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Afup\Hermes\Discord\Command\Helper;

use Afup\Hermes\Entity\User;
use Afup\Hermes\Repository\User\FindOrCreateUserDebug;
use Discord\Builders\MessageBuilder;
use Discord\Parts\Interactions\Interaction;
use Discord\Parts\User\User as DiscordUser;

Expand Down
12 changes: 9 additions & 3 deletions app/src/Discord/Command/QuitTransportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -69,7 +70,7 @@ public function callback(Discord $discord): void
}

if (1 === \count($travelers)) {
$this->validateRemoval($discord, $interaction, $travelers[0]);
$this->validateRemoval($discord, $interaction, $travelers[0], true);
} else {
$embed = new Embed($discord);
$embed->setTitle($this->translator->trans('discord.quit_transport.travel_choice'));
Expand All @@ -94,7 +95,7 @@ public function callback(Discord $discord): void
});
}

private function validateRemoval(Discord $discord, Interaction $interaction, Traveler $traveler): void
private function validateRemoval(Discord $discord, Interaction $interaction, Traveler $traveler, bool $shouldRespond = false): void
{
$embed = new Embed($discord);
$embed->setTitle($this->translator->trans('discord.quit_transport.confirmation'));
Expand All @@ -116,6 +117,11 @@ private function validateRemoval(Discord $discord, Interaction $interaction, Tra
$interaction->updateMessage(MessageBuilder::new()->setContent($this->translator->trans('discord.quit_transport.cancel_label'))->setComponents([])->setEmbeds([]));
}, $discord));

$interaction->updateMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation));
if ($shouldRespond) {
$interaction->respondWithMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation), true);
} else {
$interaction->updateMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation));
}

}
}
10 changes: 7 additions & 3 deletions app/src/Discord/Command/RemoveTransportCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function callback(Discord $discord): void
}

if (1 === \count($transports)) {
$this->validateRemoval($discord, $interaction, $transports[0]);
$this->validateRemoval($discord, $interaction, $transports[0], true);
} else {
$embed = new Embed($discord);
$embed->setTitle($this->translator->trans('discord.remove_transport.ask_remove'));
Expand All @@ -91,7 +91,7 @@ public function callback(Discord $discord): void
});
}

private function validateRemoval(Discord $discord, Interaction $interaction, Transport $transport): void
private function validateRemoval(Discord $discord, Interaction $interaction, Transport $transport, bool $shouldRespond = false): void
{
$embed = new Embed($discord);
$embed->setTitle($this->translator->trans('discord.remove_transport.validation_remove'));
Expand Down Expand Up @@ -120,6 +120,10 @@ private function validateRemoval(Discord $discord, Interaction $interaction, Tra
$interaction->updateMessage(MessageBuilder::new()->setContent($this->translator->trans('discord.remove_transport.label_cancel'))->setComponents([])->setEmbeds([]));
}, $discord));

$interaction->updateMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation));
if ($shouldRespond) {
$interaction->respondWithMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation), true);
} else {
$interaction->updateMessage(MessageBuilder::new()->addEmbed($embed)->addComponent($validation));
}
}
}
2 changes: 2 additions & 0 deletions app/src/Repository/User/FindOrCreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
namespace Afup\Hermes\Repository\User;

use Afup\Hermes\Entity\User;
use Discord\Builders\MessageBuilder;
use Discord\Parts\Interactions\Interaction;
use Doctrine\ORM\EntityManagerInterface;

final readonly class FindOrCreateUser
Expand Down

0 comments on commit 3f1663c

Please sign in to comment.