diff --git a/.idea/DiscordBot.iml b/.idea/DiscordBot.iml index 4d60b2f9d..31d6e5dd1 100644 --- a/.idea/DiscordBot.iml +++ b/.idea/DiscordBot.iml @@ -5,6 +5,7 @@ + @@ -44,17 +45,47 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -62,6 +93,7 @@ + @@ -70,8 +102,6 @@ - - diff --git a/.idea/php.xml b/.idea/php.xml index e725191de..66ff58d8e 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -48,32 +48,69 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + - - + + + + + + + + + + + + + - - diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cccc7915..bf0bf7918 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Changelog +## [3.0.2] - 2023-09-04 + +### Changed + +- Bump network version to `2` + +### Fixed + +- Fix Modal Text response conversion ([#104](https://github.com/DiscordBot-PMMP/DiscordBot/issues/104)) +- Fix `TextInput` serialization ([#103](https://github.com/DiscordBot-PMMP/DiscordBot/issues/103)) + ## [3.0.1] - 2023-09-03 ### Fixed @@ -18,8 +29,8 @@ _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)_ ### Added -- Add PocketMine-MP `5.x` support ([``](https://github.com/DiscordBot-PMMP/DiscordBot/commit/1467c493d8ba67b830b783dd2334ffb79e6d0c87)) -- Add PHP `8.1.x` support ([``](https://github.com/DiscordBot-PMMP/DiscordBot/commit/797f2d0015881398a70644ff304168ed62bf94de)) +- Add PocketMine-MP `5.x` support +- Add PHP `8.1.x` support - Add `composer/ca-bundle` version `^1.3` - Add `pocketmine/binaryutils` version `0.2.4` @@ -204,7 +215,8 @@ _**Breaking:** Plugin re-released as a central API._ ❌ _This release was never published to public._ - +[3.0.2]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/3.0.2 +[3.0.1]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/3.0.1 [3.0.0]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/3.0.0 [2.1.10]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/2.1.10 [2.1.9]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/2.1.9 diff --git a/plugin.yml b/plugin.yml index 22608610d..3ee5064c9 100644 --- a/plugin.yml +++ b/plugin.yml @@ -1,5 +1,5 @@ name: DiscordBot -version: 3.0.1 +version: 3.0.2 author: JaxkDev src-namespace-prefix: JaxkDev\DiscordBot main: JaxkDev\DiscordBot\Plugin\Main diff --git a/src/Communication/NetworkApi.php b/src/Communication/NetworkApi.php index e30977740..56aa694d0 100644 --- a/src/Communication/NetworkApi.php +++ b/src/Communication/NetworkApi.php @@ -121,7 +121,7 @@ final class NetworkApi{ // Version will change for any breaking changes to the protocol (Models / Packets) - public const VERSION = 1; + public const VERSION = 2; public const MAGIC = 0x4a61786b; //Jaxk (max 4 bytes) /** @var array> */ diff --git a/src/InternalBot/ModelConverter.php b/src/InternalBot/ModelConverter.php index 3c9510c3d..d4d0475db 100644 --- a/src/InternalBot/ModelConverter.php +++ b/src/InternalBot/ModelConverter.php @@ -205,7 +205,31 @@ static public function genModelModalSubmitData(DiscordInteractionData $data): Mo if($data->components === null){ throw new AssertionError("Components is null for modal submit data."); } - return new ModalSubmitData($data->custom_id, self::genModelComponents($data->components->toArray())); + //Discord is a bit weird with components, so we have to do this. + //top level is an ActionRow, we don't want that. + $components = []; + //ActionRow $comp + foreach($data->components as $comp){ + if($comp->type !== ComponentType::ACTION_ROW->value){ + throw new AssertionError("Expected action row component, got {$comp->type}."); + } + //Text Input $component + foreach($comp->components ?? [] as $component){ + if($component->type !== ComponentType::TEXT_INPUT->value){ + throw new AssertionError("Expected text input component, got {$component->type}."); + } + if($component->custom_id === null){ + throw new AssertionError("Custom id is null for text input component."); + } + if($component->value === null){ + throw new AssertionError("Value is null for text input component."); + } + //TODO-Next-Major BREAKING: Discord doesnt send all data only value & custom_id + $components[] = new TextInput($component->custom_id, TextInputStyle::SHORT, "", 1, 1, false, + $component->value, null); + } + } + return new ModalSubmitData($data->custom_id, $components); } /** diff --git a/src/Models/Messages/Component/ActionRow.php b/src/Models/Messages/Component/ActionRow.php index 40935e288..f4d0676de 100644 --- a/src/Models/Messages/Component/ActionRow.php +++ b/src/Models/Messages/Component/ActionRow.php @@ -79,6 +79,7 @@ public static function fromBinary(BinaryStream $stream): self{ private static function componentFromBinary(BinaryStream $stream): Button|TextInput|SelectMenu{ $type = ComponentType::from($stream->getByte()); + $stream->setOffset($stream->getOffset() - 1); //unread first byte so components knows what type. switch($type){ case ComponentType::BUTTON: return Button::fromBinary($stream); @@ -89,7 +90,6 @@ private static function componentFromBinary(BinaryStream $stream): Button|TextIn case ComponentType::ROLE_SELECT: case ComponentType::CHANNEL_SELECT: case ComponentType::MENTIONABLE_SELECT: - $stream->setOffset($stream->getOffset() - 1); //unread first byte so SelectMenu knows what type to build. return SelectMenu::fromBinary($stream); default: throw new \InvalidArgumentException("Unknown component type {$type->name} ({$type->value})"); diff --git a/src/Models/Messages/Component/Button.php b/src/Models/Messages/Component/Button.php index cc6ce4607..7d0ea0f83 100644 --- a/src/Models/Messages/Component/Button.php +++ b/src/Models/Messages/Component/Button.php @@ -124,6 +124,7 @@ public function binarySerialize(): BinaryStream{ } public static function fromBinary(BinaryStream $stream): Button{ + $stream->getByte(); return new self( ButtonStyle::from($stream->getByte()), // style $stream->getNullableString(), // label diff --git a/src/Models/Messages/Component/TextInput.php b/src/Models/Messages/Component/TextInput.php index e4282f8ac..aba4e5088 100644 --- a/src/Models/Messages/Component/TextInput.php +++ b/src/Models/Messages/Component/TextInput.php @@ -143,6 +143,7 @@ public function setPlaceholder(?string $placeholder): void{ public function binarySerialize(): BinaryStream{ $stream = new BinaryStream(); + $stream->putByte($this->type->value); $stream->putString($this->custom_id); $stream->putByte($this->style->value); $stream->putString($this->label); @@ -155,6 +156,7 @@ public function binarySerialize(): BinaryStream{ } public static function fromBinary(BinaryStream $stream): self{ + $stream->getByte(); return new self( $stream->getString(), // custom_id TextInputStyle::from($stream->getByte()), // style