Skip to content

Commit 819a61d

Browse files
authored
v3.0.2
#105
2 parents 8ef8118 + 20b5732 commit 819a61d

File tree

9 files changed

+139
-33
lines changed

9 files changed

+139
-33
lines changed

.idea/DiscordBot.iml

Lines changed: 35 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 58 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## [3.0.2] - 2023-09-04
4+
5+
### Changed
6+
7+
- Bump network version to `2`
8+
9+
### Fixed
10+
11+
- Fix Modal Text response conversion ([#104](https://github.com/DiscordBot-PMMP/DiscordBot/issues/104))
12+
- Fix `TextInput` serialization ([#103](https://github.com/DiscordBot-PMMP/DiscordBot/issues/103))
13+
314
## [3.0.1] - 2023-09-03
415

516
### Fixed
@@ -18,8 +29,8 @@ _If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)_
1829

1930
### Added
2031

21-
- Add PocketMine-MP `5.x` support ([``](https://github.com/DiscordBot-PMMP/DiscordBot/commit/1467c493d8ba67b830b783dd2334ffb79e6d0c87))
22-
- Add PHP `8.1.x` support ([``](https://github.com/DiscordBot-PMMP/DiscordBot/commit/797f2d0015881398a70644ff304168ed62bf94de))
32+
- Add PocketMine-MP `5.x` support
33+
- Add PHP `8.1.x` support
2334
- Add `composer/ca-bundle` version `^1.3`
2435
- Add `pocketmine/binaryutils` version `0.2.4`
2536

@@ -204,7 +215,8 @@ _**Breaking:** Plugin re-released as a central API._
204215

205216
_This release was never published to public._
206217

207-
218+
[3.0.2]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/3.0.2
219+
[3.0.1]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/3.0.1
208220
[3.0.0]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/3.0.0
209221
[2.1.10]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/2.1.10
210222
[2.1.9]: https://github.com/DiscordBot-PMMP/DiscordBot/releases/tag/2.1.9

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: DiscordBot
2-
version: 3.0.1
2+
version: 3.0.2
33
author: JaxkDev
44
src-namespace-prefix: JaxkDev\DiscordBot
55
main: JaxkDev\DiscordBot\Plugin\Main

src/Communication/NetworkApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@
121121
final class NetworkApi{
122122

123123
// Version will change for any breaking changes to the protocol (Models / Packets)
124-
public const VERSION = 1;
124+
public const VERSION = 2;
125125
public const MAGIC = 0x4a61786b; //Jaxk (max 4 bytes)
126126

127127
/** @var array<int, class-string<Packet>> */

src/InternalBot/ModelConverter.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,31 @@ static public function genModelModalSubmitData(DiscordInteractionData $data): Mo
205205
if($data->components === null){
206206
throw new AssertionError("Components is null for modal submit data.");
207207
}
208-
return new ModalSubmitData($data->custom_id, self::genModelComponents($data->components->toArray()));
208+
//Discord is a bit weird with components, so we have to do this.
209+
//top level is an ActionRow, we don't want that.
210+
$components = [];
211+
//ActionRow $comp
212+
foreach($data->components as $comp){
213+
if($comp->type !== ComponentType::ACTION_ROW->value){
214+
throw new AssertionError("Expected action row component, got {$comp->type}.");
215+
}
216+
//Text Input $component
217+
foreach($comp->components ?? [] as $component){
218+
if($component->type !== ComponentType::TEXT_INPUT->value){
219+
throw new AssertionError("Expected text input component, got {$component->type}.");
220+
}
221+
if($component->custom_id === null){
222+
throw new AssertionError("Custom id is null for text input component.");
223+
}
224+
if($component->value === null){
225+
throw new AssertionError("Value is null for text input component.");
226+
}
227+
//TODO-Next-Major BREAKING: Discord doesnt send all data only value & custom_id
228+
$components[] = new TextInput($component->custom_id, TextInputStyle::SHORT, "", 1, 1, false,
229+
$component->value, null);
230+
}
231+
}
232+
return new ModalSubmitData($data->custom_id, $components);
209233
}
210234

211235
/**

src/Models/Messages/Component/ActionRow.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public static function fromBinary(BinaryStream $stream): self{
7979

8080
private static function componentFromBinary(BinaryStream $stream): Button|TextInput|SelectMenu{
8181
$type = ComponentType::from($stream->getByte());
82+
$stream->setOffset($stream->getOffset() - 1); //unread first byte so components knows what type.
8283
switch($type){
8384
case ComponentType::BUTTON:
8485
return Button::fromBinary($stream);
@@ -89,7 +90,6 @@ private static function componentFromBinary(BinaryStream $stream): Button|TextIn
8990
case ComponentType::ROLE_SELECT:
9091
case ComponentType::CHANNEL_SELECT:
9192
case ComponentType::MENTIONABLE_SELECT:
92-
$stream->setOffset($stream->getOffset() - 1); //unread first byte so SelectMenu knows what type to build.
9393
return SelectMenu::fromBinary($stream);
9494
default:
9595
throw new \InvalidArgumentException("Unknown component type {$type->name} ({$type->value})");

src/Models/Messages/Component/Button.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function binarySerialize(): BinaryStream{
124124
}
125125

126126
public static function fromBinary(BinaryStream $stream): Button{
127+
$stream->getByte();
127128
return new self(
128129
ButtonStyle::from($stream->getByte()), // style
129130
$stream->getNullableString(), // label

src/Models/Messages/Component/TextInput.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ public function setPlaceholder(?string $placeholder): void{
143143

144144
public function binarySerialize(): BinaryStream{
145145
$stream = new BinaryStream();
146+
$stream->putByte($this->type->value);
146147
$stream->putString($this->custom_id);
147148
$stream->putByte($this->style->value);
148149
$stream->putString($this->label);
@@ -155,6 +156,7 @@ public function binarySerialize(): BinaryStream{
155156
}
156157

157158
public static function fromBinary(BinaryStream $stream): self{
159+
$stream->getByte();
158160
return new self(
159161
$stream->getString(), // custom_id
160162
TextInputStyle::from($stream->getByte()), // style

0 commit comments

Comments
 (0)