Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/formats.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Formats

on: ['push', 'pull_request']
on:
push:
branches:
- main
pull_request:

jobs:
ci:
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Tests

on: ['push', 'pull_request']
on:
push:
branches:
- main
pull_request:

jobs:
ci:
Expand Down
27 changes: 19 additions & 8 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,19 +385,19 @@ $teamspeak->channelGroups()->setClientChannelGroup(channelGroupId: 5, channelId:

## tokenadd

Not implemented.
Alias for `privilegekeyadd`. See [privilegekeyadd](#privilegekeyadd).

## tokendelete

Not implemented.
Alias for `privilegekeydelete`. See [privilegekeydelete](#privilegekeydelete).

## tokenlist

Not implemented.
Alias for `privilegekeylist`. See [privilegekeylist](#privilegekeylist).

## tokenuse

Not implemented.
Alias for `privilegekeyuse`. See [privilegekeyuse](#privilegekeyuse).

## channelpermlist

Expand Down Expand Up @@ -642,19 +642,30 @@ $teamspeak->permissions()->reset();

## privilegekeylist

Not implemented.
```php
$teamspeak->privilegeKeys()->list();
```

## privilegekeyadd

Not implemented.
```php
// Server group key (type 0):
$teamspeak->privilegeKeys()->add(type: 0, id1: 6);
// Channel group key (type 1):
$teamspeak->privilegeKeys()->add(type: 1, id1: 5, id2: 3, description: 'VIP channel', customSet: 'custom');
```

## privilegekeydelete

Not implemented.
```php
$teamspeak->privilegeKeys()->delete(token: 'eKnFZQ9EK7G7EmPvt1Ch7vsXi5Uq+1Us7xrQKBVsMxM=');
```

## privilegekeyuse

Not implemented.
```php
$teamspeak->privilegeKeys()->redeem(token: 'eKnFZQ9EK7G7EmPvt1Ch7vsXi5Uq+1Us7xrQKBVsMxM=');
```

## messagelist

Expand Down
9 changes: 0 additions & 9 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
use TeamSpeak\WebQuery\Resources\PrivilegeKeys;
use TeamSpeak\WebQuery\Resources\ServerGroups;
use TeamSpeak\WebQuery\Resources\Servers;
use TeamSpeak\WebQuery\Resources\Tokens;
use TeamSpeak\WebQuery\Responses\WhoAmI\WhoAmIResponse;
use TeamSpeak\WebQuery\ValueObjects\Transporter\Payload;

Expand Down Expand Up @@ -141,14 +140,6 @@ public function servers(): Servers
return new Servers($this->transporter);
}

/**
* Interact with the tokens.
*/
public function tokens(): Tokens
{
return new Tokens($this->transporter);
}

/**
* Returns information about the current query client session.
*/
Expand Down
6 changes: 0 additions & 6 deletions src/Contracts/ClientContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use TeamSpeak\WebQuery\Contracts\Resources\PrivilegeKeysContract;
use TeamSpeak\WebQuery\Contracts\Resources\ServerGroupsContract;
use TeamSpeak\WebQuery\Contracts\Resources\ServersContract;
use TeamSpeak\WebQuery\Contracts\Resources\TokensContract;
use TeamSpeak\WebQuery\Responses\WhoAmI\WhoAmIResponse;

interface ClientContract
Expand Down Expand Up @@ -93,11 +92,6 @@ public function serversGroups(): ServerGroupsContract;
*/
public function servers(): ServersContract;

/**
* Interact with the tokens.
*/
public function tokens(): TokensContract;

/**
* Returns information about the current query client session.
*/
Expand Down
40 changes: 39 additions & 1 deletion src/Contracts/Resources/PrivilegeKeysContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,42 @@

namespace TeamSpeak\WebQuery\Contracts\Resources;

interface PrivilegeKeysContract {}
use TeamSpeak\WebQuery\Enums\PrivilegeKeyType;
use TeamSpeak\WebQuery\Responses\PrivilegeKeys\AddResponse;
use TeamSpeak\WebQuery\Responses\PrivilegeKeys\ListResponse;

interface PrivilegeKeysContract
{
/**
* Displays a list of privilege keys available on the virtual server.
*/
public function list(): ListResponse;

/**
* Creates a new privilege key of the given type.
*
* For ServerGroup: id1 = server group ID, id2 = 0.
* For ChannelGroup: id1 = channel group ID, id2 = channel ID.
*/
public function add(PrivilegeKeyType $type, int $id1, int $id2 = 0, string $description = '', string $customSet = ''): AddResponse;

/**
* Creates a privilege key that grants membership to a server group.
*/
public function addServerGroup(int $serverGroupId, string $description = '', string $customSet = ''): AddResponse;

/**
* Creates a privilege key that grants membership to a channel group in a specific channel.
*/
public function addChannelGroup(int $channelGroupId, int $channelId, string $description = '', string $customSet = ''): AddResponse;

/**
* Deletes an existing privilege key.
*/
public function delete(string $token): void;

/**
* Redeems a privilege key and gains the associated group memberships.
*/
public function redeem(string $token): void;
}
7 changes: 0 additions & 7 deletions src/Contracts/Resources/TokensContract.php

This file was deleted.

18 changes: 18 additions & 0 deletions src/Enums/PrivilegeKeyType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Enums;

enum PrivilegeKeyType: int
{
/**
* Grants membership to a server group.
*/
case ServerGroup = 0;

/**
* Grants membership to a channel group in a specific channel.
*/
case ChannelGroup = 1;
}
85 changes: 85 additions & 0 deletions src/Resources/PrivilegeKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,93 @@
namespace TeamSpeak\WebQuery\Resources;

use TeamSpeak\WebQuery\Contracts\Resources\PrivilegeKeysContract;
use TeamSpeak\WebQuery\Enums\PrivilegeKeyType;
use TeamSpeak\WebQuery\Enums\Query\Command;
use TeamSpeak\WebQuery\Responses\PrivilegeKeys\AddResponse;
use TeamSpeak\WebQuery\Responses\PrivilegeKeys\ListResponse;
use TeamSpeak\WebQuery\ValueObjects\Transporter\Payload;

final class PrivilegeKeys implements PrivilegeKeysContract
{
use Concerns\Transportable;

/**
* Displays a list of privilege keys available on the virtual server.
*/
public function list(): ListResponse
{
$payload = new Payload(Command::PrivilegeKeyList);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<list<array{token: string, token_type: string, token_id1: string, token_id2: string, token_description: string, token_created: string, token_customset?: string}>> $response */
$response = $this->transporter->request($payload);

return ListResponse::from($response->body());
}

/**
* Creates a new privilege key of the given type.
*
* For ServerGroup: id1 = server group ID, id2 = 0.
* For ChannelGroup: id1 = channel group ID, id2 = channel ID.
*/
public function add(PrivilegeKeyType $type, int $id1, int $id2 = 0, string $description = '', string $customSet = ''): AddResponse
{
$payload = new Payload(
command: Command::PrivilegeKeyAdd,
parameters: [
'tokentype' => $type->value,
'tokenid1' => $id1,
'tokenid2' => $id2,
'tokendescription' => $description ?: null,
'tokencustomset' => $customSet ?: null,
],
);

/** @var \TeamSpeak\WebQuery\ValueObjects\Transporter\Response<array{0: array{token: string}}> $response */
$response = $this->transporter->request($payload);

return AddResponse::from($response->body());
}

/**
* Creates a privilege key that grants membership to a server group.
*/
public function addServerGroup(int $serverGroupId, string $description = '', string $customSet = ''): AddResponse
{
return $this->add(PrivilegeKeyType::ServerGroup, $serverGroupId, 0, $description, $customSet);
}

/**
* Creates a privilege key that grants membership to a channel group in a specific channel.
*/
public function addChannelGroup(int $channelGroupId, int $channelId, string $description = '', string $customSet = ''): AddResponse
{
return $this->add(PrivilegeKeyType::ChannelGroup, $channelGroupId, $channelId, $description, $customSet);
}

/**
* Deletes an existing privilege key.
*/
public function delete(string $token): void
{
$payload = new Payload(
command: Command::PrivilegeKeyDelete,
parameters: ['token' => $token],
);

$this->transporter->request($payload);
}

/**
* Redeems a privilege key and gains the associated group memberships.
*/
public function redeem(string $token): void
{
$payload = new Payload(
command: Command::PrivilegeKeyUse,
parameters: ['token' => $token],
);

$this->transporter->request($payload);
}
}
12 changes: 0 additions & 12 deletions src/Resources/Tokens.php

This file was deleted.

22 changes: 22 additions & 0 deletions src/Responses/PrivilegeKeys/AddResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\PrivilegeKeys;

final readonly class AddResponse
{
private function __construct(
public string $token,
) {}

/**
* @param array{0: array{token: string}} $attributes
*/
public static function from(array $attributes): self
{
return new self(
$attributes[0]['token'],
);
}
}
25 changes: 25 additions & 0 deletions src/Responses/PrivilegeKeys/ListResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\PrivilegeKeys;

final readonly class ListResponse
{
/**
* @param list<ListResponseKey> $keys
*/
private function __construct(
public array $keys,
) {}

/**
* @param list<array{token: string, token_type: string, token_id1: string, token_id2: string, token_description: string, token_created: string, token_customset?: string}> $attributes
*/
public static function from(array $attributes): self
{
return new self(
array_map(ListResponseKey::from(...), $attributes),
);
}
}
34 changes: 34 additions & 0 deletions src/Responses/PrivilegeKeys/ListResponseKey.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace TeamSpeak\WebQuery\Responses\PrivilegeKeys;

final readonly class ListResponseKey
{
private function __construct(
public string $token,
public int $type,
public int $id1,
public int $id2,
public string $description,
public int $createdAt,
public string $customSet,
) {}

/**
* @param array{token: string, token_type: string, token_id1: string, token_id2: string, token_description: string, token_created: string, token_customset?: string} $attributes
*/
public static function from(array $attributes): self
{
return new self(
$attributes['token'],
(int) $attributes['token_type'],
(int) $attributes['token_id1'],
(int) $attributes['token_id2'],
$attributes['token_description'],
(int) $attributes['token_created'],
$attributes['token_customset'] ?? '',
);
}
}
Loading
Loading