Skip to content

Commit

Permalink
Implemented ability to open DM channel (#8)
Browse files Browse the repository at this point in the history
* Implemented ability to open DM channel

* Fix styling

---------

Co-authored-by: Plytas <[email protected]>
  • Loading branch information
Plytas and Plytas authored Aug 15, 2024
1 parent c87ad1b commit 5dde823
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/Components/ActionRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class ActionRow extends Data implements DiscordComponent

public function __construct(
/** @var Collection<int, DiscordComponent> */
public Collection $components = new Collection(),
public Collection $components = new Collection,
) {}

public static function new(): self
{
return new self();
return new self;
}

public function addComponent(DiscordComponent $component): self
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(

public static function new(): self
{
return new self();
return new self;
}

public function setCustomId(string $customId): self
Expand Down
2 changes: 1 addition & 1 deletion src/Components/StringSelect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class StringSelect extends Data implements DiscordComponent
public function __construct(
public string $custom_id,
/** @var Collection<int, SelectOption> */
public Collection $options = new Collection(),
public Collection $options = new Collection,
public ?string $placeholder = null,
public ?int $min_values = 1,
public ?int $max_values = 1,
Expand Down
1 change: 1 addition & 0 deletions src/Data/DiscordInteraction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function __construct(
public int $version,
public string $token,
public ?DiscordMember $member = null,
public ?DiscordUser $user = null,
public ?string $guild_id = null,
public ?string $channel_id = null,
/**
Expand Down
8 changes: 4 additions & 4 deletions src/Data/DiscordMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ public function __construct(
public ?string $content = null,
public int $flags = 0,
/** @var Collection<int, DiscordMessageEmbed> */
public Collection $embeds = new Collection(),
public Collection $embeds = new Collection,
/** @var Collection<int, DiscordComponent> */
public Collection $components = new Collection(),
public Collection $components = new Collection,
/** @var array<int, mixed> */
public ?array $attachments = null,
/** @var Collection<int, DiscordMessageFile> */
private Collection $files = new Collection(),
private Collection $files = new Collection,
) {}

public static function new(): self
{
return new self();
return new self;
}

public function setContent(string $content): self
Expand Down
4 changes: 2 additions & 2 deletions src/Data/DiscordMessageEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ public function __construct(
public ?string $description = null,
public int|EmbedColor $color = EmbedColor::Default,
/** @var Collection<int, DiscordMessageEmbedField> */
public Collection $fields = new Collection(),
public Collection $fields = new Collection,
public ?DiscordMessageEmbedImage $image = null,
) {}

public static function new(): self
{
return new self();
return new self;
}

public function setTitle(string $title): self
Expand Down
2 changes: 1 addition & 1 deletion src/Data/DiscordModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public function __construct(
public string $custom_id,
public string $title,
/** @var Collection<int, DiscordComponent> */
public Collection $components = new Collection(),
public Collection $components = new Collection,
) {}

public static function new(string $custom_id, string $title): self
Expand Down
5 changes: 5 additions & 0 deletions src/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public function deleteMessage(string $channelId, string $messageId): Response
return $this->client->delete("/channels/{$channelId}/messages/{$messageId}");
}

public function openDirectMessageChannel(string $userId): Response
{
return $this->client->asJson()->post('/users/@me/channels', ['recipient_id' => $userId]);
}

public function getGuild(string $guildId): DiscordGuild
{
return DiscordGuild::from($this->client->get("/guilds/{$guildId}")->json());
Expand Down
2 changes: 1 addition & 1 deletion src/DiscordCommandRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static function setCommands(array $commands): void

public static function new(): self
{
return new self();
return new self;
}

public function register(): void
Expand Down
2 changes: 1 addition & 1 deletion src/DiscordComponentRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static function handleComponentsUsing(Closure $callback): void

public static function new(): self
{
return new self();
return new self;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Facades/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @method static Response createMessage(string $channelId, DiscordMessage $message)
* @method static Response updateMessage(string $channelId, string $messageId, DiscordMessage $message)
* @method static Response deleteMessage(string $channelId, string $messageId)
* @method static Response openDirectMessageChannel(string $userId)
* @method static DiscordGuild getGuild(string $guildId)
* @method static Collection<int, DiscordChannel> getChannels(string $guildId)
* @method static Collection<int, DiscordRole> getRoles(string $guildId)
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Middleware/VerifyDiscordSignatureMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function handle(Request $request, Closure $next): mixed
$timestamp = $request->header('X-Signature-Timestamp');

if (! $signature || ! $timestamp || ! $this->verify($signature, $timestamp, $request->getContent())) {
throw new AuthenticationException();
throw new AuthenticationException;
}

$applicationId = config('discord-interactions.application_id');
Expand All @@ -35,7 +35,7 @@ public function handle(Request $request, Closure $next): mixed
}

if (! $request->string('application_id')->exactly($applicationId)) {
throw new AuthorizationException();
throw new AuthorizationException;
}

return $next($request);
Expand Down

0 comments on commit 5dde823

Please sign in to comment.