LobbyRepository
extends AbstractRepository
in package
Contains lobbies.
Everything here is done with the bot token, as a game's backend does it. What a player does in a lobby — creating or joining one by secret, leaving, linking a channel, sending and reading messages — uses the player's own OAuth2 token instead.
Tags
Table of Contents
Properties
- $cache : CacheWrapper
- $discrim : string
- $class : string
- Class type allowed into the collection.
- $discord : mixed
- $endpoints : array<string|int, mixed>
- Endpoints for interacting with the Discord servers.
- $factory : Factory
- The parts factory.
- $http : Http
- The HTTP client.
- $items : array<string|int, mixed>
- The items contained in the collection.
- $vars : array<string|int, mixed>
- Variables that are related to the repository.
Methods
- __call() : mixed
- This method checks if a method with the name "__Collection__{$name}" exists within the class. If it does, it calls that method with the provided arguments.
- __construct() : mixed
- AbstractRepository constructor.
- __debugInfo() : array<string|int, mixed>
- __get() : mixed
- Exposes the read-only \`discrim\` and \`cache\` properties.
- addMember() : PromiseInterface<string|int, Member>
- Adds the provided user to the specified lobby.
- bulkUpdateMembers() : PromiseInterface<string|int, ExCollectionInterface<string|int, Member>|array<string|int, Member>>
- Adds, updates and removes up to 25 lobby members in one request.
- clear() : void
- Clears the repository.
- create() : Part
- Builds a new, empty part.
- createInvite() : PromiseInterface<string|int, Invite>
- Creates an invite for a lobby member to the channel linked to the lobby.
- createLobby() : PromiseInterface<string|int, Lobby>
- Creates a new lobby, adding any of the specified members to it, if provided.
- delete() : PromiseInterface<string|int, Part>
- Attempts to delete a part on the Discord servers.
- fetch() : PromiseInterface<string|int, Part>
- Gets a part from the repository or Discord servers.
- filter() : ExCollectionInterface
- Runs a filter callback over the repository and returns a new collection based on the response of the callback.
- find() : Lobby|null
- first() : Lobby|null
- fresh() : PromiseInterface<string|int, Part>
- Returns a part with fresh values.
- freshen() : PromiseInterface<string|int, static>
- Freshens the repository cache.
- get() : Lobby|null
- getIterator() : Traversable
- Returns an iterator for the cache.
- has() : bool
- Checks if the array has an object.
- jsonSerialize() : array<string|int, mixed>
- keys() : array<string|int, int>|array<string|int, string>
- Get the keys of the items.
- last() : Lobby|null
- modifyLobby() : PromiseInterface<string|int, Lobby>
- Modifies the specified lobby with new values, if provided.
- offsetExists() : bool
- If the repository has an offset.
- offsetGet() : Part|null
- Gets a part from the repository.
- offsetSet() : void
- Sets a part into the repository.
- offsetUnset() : void
- Unsets an index from the repository.
- pull() : Lobby|null
- pushItem() : self
- Pushes a single item to the repository.
- removeMember() : PromiseInterface
- Removes the provided user from the specified lobby.
- save() : PromiseInterface<string|int, Part>
- Attempts to save a part to the Discord servers.
- set() : mixed
- Sets a part in the repository.
- toArray() : array<string|int, mixed>
- Converts the weak caches to array.
- updateMessageModerationMetadata() : PromiseInterface
- Sets the moderation metadata on a lobby message, which is delivered to the players' clients.
- values() : array<string|int, mixed>
- Get the values of the items.
- cacheFreshen() : PromiseInterface<string|int, static>
- forgetCachedItems() : void
- Drops every cached part, before the repository is refilled from a response that lists all of them.
- updateRoster() : PromiseInterface
- Applies successful REST roster changes to known lobbies without fetching a partial lobby.
Properties
$cache read-only
public
CacheWrapper
$cache
The react/cache wrapper.
$discrim
public
string
$discrim
The discriminator.
$class
Class type allowed into the collection.
protected
string
$class
= \Discord\Parts\Lobby\Lobby::class
Tags
$discord
protected
mixed
$discord
$endpoints
Endpoints for interacting with the Discord servers.
protected
array<string|int, mixed>
$endpoints
= [
//'create' => Endpoint::LOBBIES,
'get' => \Discord\Http\Endpoint::LOBBY,
'update' => \Discord\Http\Endpoint::LOBBY,
'delete' => \Discord\Http\Endpoint::LOBBY,
]
Endpoints.
Tags
$factory
The parts factory.
protected
Factory
$factory
Parts factory.
$http
The HTTP client.
protected
Http
$http
Client.
$items
The items contained in the collection.
protected
array<string|int, mixed>
$items
= []
$vars
Variables that are related to the repository.
protected
array<string|int, mixed>
$vars
= []
Variables.
Methods
__call()
This method checks if a method with the name "__Collection__{$name}" exists within the class. If it does, it calls that method with the provided arguments.
public
__call(string $name, array<string|int, mixed> $arguments) : mixed
If the method does not exist, it throws a BadMethodCallException.
Previously, this class utilized parent::method to call methods from the parent class.
This was changed to use the __Collection__method naming convention to avoid conflicts
Parameters
- $name : string
-
The name of the method being called.
- $arguments : array<string|int, mixed>
-
The arguments passed to the method.
Tags
Return values
mixed —The result of the called method.
__construct()
AbstractRepository constructor.
public
__construct(Discord $discord[, array<string|int, mixed> $vars = [] ]) : mixed
Parameters
- $discord : Discord
- $vars : array<string|int, mixed> = []
-
An array of variables used for the endpoint.
__debugInfo()
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>__get()
Exposes the read-only \`discrim\` and \`cache\` properties.
public
__get(string $key) : mixed
Parameters
- $key : string
addMember()
Adds the provided user to the specified lobby.
public
addMember(Lobby|string $lobby, Member|User|string $user[, ?string $data = [] ]) : PromiseInterface<string|int, Member>
If called when the user is already a member of the lobby will update fields such as metadata on that user instead.
Parameters
- $lobby : Lobby|string
-
The lobby or lobby id to add the member to.
- $user : Member|User|string
-
Member, user, or user id to add to the lobby.
- $data : ?string = []
-
['additional_name'] An additional 1-80 character display name for the member, such as an in-game character name. Null clears it; omit it to keep the current value.
Tags
Return values
PromiseInterface<string|int, Member>bulkUpdateMembers()
Adds, updates and removes up to 25 lobby members in one request.
public
bulkUpdateMembers(Lobby|string $lobby, array<string|int, array<string|int, mixed>>|array<string|int, Member> $members) : PromiseInterface<string|int, ExCollectionInterface<string|int, Member>|array<string|int, Member>>
Each entry is a Member, or an array with an id and any of metadata, flags, additional_name,
and remove_member (true to remove the user rather than add or update them).
Parameters
- $lobby : Lobby|string
-
The lobby or lobby id whose members to update.
- $members : array<string|int, array<string|int, mixed>>|array<string|int, Member>
-
The members to add, update or remove.
Tags
Return values
PromiseInterface<string|int, ExCollectionInterface<string|int, Member>|array<string|int, Member>> —The members that were added or updated. Removed members are not included.
clear()
Clears the repository.
public
clear() : void
Use async $repository->cache->clear()
create()
Builds a new, empty part.
public
create([array<string|int, mixed>|object $attributes = [] ][, bool $created = false ]) : Part
Parameters
- $attributes : array<string|int, mixed>|object = []
-
The attributes for the new part.
- $created : bool = false
Tags
Return values
Part —The new part.
createInvite()
Creates an invite for a lobby member to the channel linked to the lobby.
public
createInvite(Lobby|string $lobby, Member|User|string $user) : PromiseInterface<string|int, Invite>
Parameters
- $lobby : Lobby|string
-
The lobby or lobby id whose linked channel to invite to.
- $user : Member|User|string
-
Member, user, or user id of the lobby member to invite.
Tags
Return values
PromiseInterface<string|int, Invite> —An invite with only its code.
createLobby()
Creates a new lobby, adding any of the specified members to it, if provided.
public
createLobby([?int $data = [] ]) : PromiseInterface<string|int, Lobby>
Parameters
- $data : ?int = []
-
['idle_timeout_seconds'] Seconds to wait before shutting down a lobby after it becomes idle. Value can be between 5 and 604800 (7 days). See LobbyHandle for more details on this behavior.
Tags
Return values
PromiseInterface<string|int, Lobby>delete()
Attempts to delete a part on the Discord servers.
public
delete(Part|string $part[, string|null $reason = null ]) : PromiseInterface<string|int, Part>
Parameters
- $part : Part|string
-
The part to delete.
- $reason : string|null = null
-
Reason for Audit Log (if supported).
Tags
Return values
PromiseInterface<string|int, Part>fetch()
Gets a part from the repository or Discord servers.
public
fetch(string $id[, bool $fresh = false ]) : PromiseInterface<string|int, Part>
Parameters
- $id : string
-
The ID to search for.
- $fresh : bool = false
-
Whether we should skip checking the cache.
Tags
Return values
PromiseInterface<string|int, Part>filter()
Runs a filter callback over the repository and returns a new collection based on the response of the callback.
public
filter(callable $callback) : ExCollectionInterface
Parameters
- $callback : callable
Tags
Return values
ExCollectionInterfacefind()
public
find(callable $callback) : Lobby|null
Parameters
- $callback : callable
Return values
Lobby|nullfirst()
public
first() : Lobby|null
Return values
Lobby|nullfresh()
Returns a part with fresh values.
public
fresh(Part $part[, array<string|int, mixed> $queryparams = [] ]) : PromiseInterface<string|int, Part>
Parameters
- $part : Part
-
The part to get fresh values.
- $queryparams : array<string|int, mixed> = []
-
Query string params to add to the request (no validation)
Tags
Return values
PromiseInterface<string|int, Part>freshen()
Freshens the repository cache.
public
freshen([array<string|int, mixed> $queryparams = [] ]) : PromiseInterface<string|int, static>
Parameters
- $queryparams : array<string|int, mixed> = []
-
Query string params to add to the request (no validation)
Tags
Return values
PromiseInterface<string|int, static>get()
public
get(string $discrim, mixed $key) : Lobby|null
Parameters
- $discrim : string
- $key : mixed
Return values
Lobby|nullgetIterator()
Returns an iterator for the cache.
public
& getIterator() : Traversable
Return values
Traversablehas()
Checks if the array has an object.
public
has(string|int ...$keys) : bool
Use async $repository->cache->has()
Parameters
- $keys : string|int
Return values
booljsonSerialize()
public
jsonSerialize([bool $assoc = true ]) : array<string|int, mixed>
Parameters
- $assoc : bool = true
Tags
Return values
array<string|int, mixed>keys()
Get the keys of the items.
public
keys() : array<string|int, int>|array<string|int, string>
Return values
array<string|int, int>|array<string|int, string>last()
public
last() : Lobby|null
Return values
Lobby|nullmodifyLobby()
Modifies the specified lobby with new values, if provided.
public
modifyLobby(Lobby|string $lobby[, ?int $data = [] ]) : PromiseInterface<string|int, Lobby>
Parameters
- $lobby : Lobby|string
-
The lobby or lobby id to modify.
- $data : ?int = []
-
['idle_timeout_seconds'] Seconds to wait before shutting down a lobby after it becomes idle. Value can be between 5 and 604800 (7 days). See LobbyHandle for more details on this behavior.
Tags
Return values
PromiseInterface<string|int, Lobby>offsetExists()
If the repository has an offset.
public
offsetExists(string|int $offset) : bool
Use async $repository->cache->has()
This method is deprecated for userland code but can still be used internally within the library.
Parameters
- $offset : string|int
Return values
booloffsetGet()
Gets a part from the repository.
public
offsetGet(string|int $offset) : Part|null
Use async $repository->cacheGet() or sync $repository->get()
This method is deprecated for userland code but can still be used internally within the library.
Parameters
- $offset : string|int
Return values
Part|nulloffsetSet()
Sets a part into the repository.
public
offsetSet(string|int $offset, ?Part $value) : void
Use async $repository->cache->set()
Parameters
- $offset : string|int
- $value : ?Part
offsetUnset()
Unsets an index from the repository.
public
offsetUnset(string|int $offset) : void
Use async $repository->cache->delete()
Parameters
- $offset : string|int
pull()
public
pull(string|int $key[, mixed $default = = 'null' ]) : Lobby|null
Parameters
- $key : string|int
- $default : mixed = = 'null'
Return values
Lobby|nullpushItem()
Pushes a single item to the repository.
public
pushItem(Part $item) : self
Use async $repository->cache->set()
This method is deprecated for userland code but can still be used internally within the library.
Parameters
- $item : Part
Return values
selfremoveMember()
Removes the provided user from the specified lobby.
public
removeMember(Lobby|string $lobby, Member|User|string $user) : PromiseInterface
It is safe to call this even if the user is no longer a member of the lobby, but will fail if the lobby does not exist.
Parameters
- $lobby : Lobby|string
-
The lobby or lobby id to remove the member from.
- $user : Member|User|string
-
Member, user, or user id to remove from the lobby.
Return values
PromiseInterfacesave()
Attempts to save a part to the Discord servers.
public
save(Part $part[, string|null $reason = null ]) : PromiseInterface<string|int, Part>
Use Part->save($reason) to ensure permissions are checked.
Parameters
- $part : Part
-
The part to save.
- $reason : string|null = null
-
Reason for Audit Log (if supported).
Tags
Return values
PromiseInterface<string|int, Part>set()
Sets a part in the repository.
public
set(string|int $offset, Part $value) : mixed
Parameters
- $offset : string|int
- $value : Part
toArray()
Converts the weak caches to array.
public
toArray([bool $assoc = true ]) : array<string|int, mixed>
Use jsonSerialize
Parameters
- $assoc : bool = true
Return values
array<string|int, mixed>updateMessageModerationMetadata()
Sets the moderation metadata on a lobby message, which is delivered to the players' clients.
public
updateMessageModerationMetadata(Lobby|string $lobby, Message|string $message, array<string|int, mixed> $metadata) : PromiseInterface
Parameters
- $lobby : Lobby|string
-
The lobby or lobby id the message was sent in.
- $message : Message|string
-
The lobby message or its id.
- $metadata : array<string|int, mixed>
-
Up to 5 free-form string key/value pairs describing the decision, e.g.
['action' => 'hide', 'reason' => 'toxicity'].
Tags
Return values
PromiseInterfacevalues()
Get the values of the items.
public
values() : array<string|int, mixed>
Return values
array<string|int, mixed>cacheFreshen()
protected
cacheFreshen(object $response) : PromiseInterface<string|int, static>
Parameters
- $response : object
Return values
PromiseInterface<string|int, static>forgetCachedItems()
Drops every cached part, before the repository is refilled from a response that lists all of them.
protected
forgetCachedItems() : void
Parts still referenced elsewhere are kept as weak references, so they are reused if the response names them again.
Tags
updateRoster()
Applies successful REST roster changes to known lobbies without fetching a partial lobby.
protected
updateRoster(string $id, Lobby|string $lobby, array<string|int, Member> $upserted[, array<string|int, string> $removed = [] ]) : PromiseInterface
Parameters
- $id : string
- $lobby : Lobby|string
- $upserted : array<string|int, Member>
-
Members returned by Discord, keyed by id, never the requested additions.
- $removed : array<string|int, string> = []