Skip to content

Commit

Permalink
v3.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JaxkDev committed Sep 4, 2023
2 parents 8ef8118 + 20b5732 commit 819a61d
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 33 deletions.
40 changes: 35 additions & 5 deletions .idea/DiscordBot.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 58 additions & 21 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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`

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Communication/NetworkApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, class-string<Packet>> */
Expand Down
26 changes: 25 additions & 1 deletion src/InternalBot/ModelConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Messages/Component/ActionRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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})");
Expand Down
1 change: 1 addition & 0 deletions src/Models/Messages/Component/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/Models/Messages/Component/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 819a61d

Please sign in to comment.