Skip to content
Open
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
12 changes: 3 additions & 9 deletions src/Discord/Discord.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,7 @@ protected function handleReady(object $data)
}

// Emit ready after 60 seconds
$this->loop->addTimer(60, function () {
$this->ready();
});
$this->loop->addTimer(60, fn () => $this->ready());

$guildLoad = new Deferred();

Expand Down Expand Up @@ -849,9 +847,7 @@ public function handleWsConnectionFailed(\Throwable $e): void
{
$this->logger->error('failed to connect to websocket, retry in 5 seconds', ['e' => $e->getMessage()]);

$this->loop->addTimer(5, function () {
$this->connectWs();
});
$this->loop->addTimer(5, fn () => $this->connectWs());
}

/**
Expand Down Expand Up @@ -1367,9 +1363,7 @@ public function connectWs(): void
$this->logger->debug('session data received', ['session' => $session]);
if ($session['remaining'] < 2) {
$this->logger->error('exceeded number of reconnects allowed, waiting before attempting reconnect', $session);
$this->loop->addTimer($session['reset_after'] / 1000, function () {
$this->connectWs();
});
$this->loop->addTimer($session['reset_after'] / 1000, fn () => $this->connectWs());

return;
}
Expand Down
8 changes: 2 additions & 6 deletions src/Discord/Helpers/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,9 @@ public function read(int $length, ?string $format = null, ?int $timeout = -1): P
$this->reads[] = [$deferred, $length];

if ($timeout > 0 && $this->loop !== null) {
$timer = $this->loop->addTimer($timeout / 1000, function () use ($deferred) {
$deferred->reject(new BufferTimedOutException());
});
$timer = $this->loop->addTimer($timeout / 1000, fn () => $deferred->reject(new BufferTimedOutException()));

$deferred->promise()->then(function () use ($timer) {
$this->loop->cancelTimer($timer);
});
$deferred->promise()->then(fn () => $this->loop->cancelTimer($timer));
} elseif ($timeout === 0) {
$deferred->reject(new BufferTimedOutException());
}
Expand Down
4 changes: 1 addition & 3 deletions src/Discord/Parts/Channel/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,7 @@ protected function getGuildAttribute(): ?Guild

// Workaround for Channel::sendMessage() no guild_id
if ($this->channel_id) {
return $this->discord->guilds->find(function (Guild $guild) {
return $guild->channels->offsetExists($this->channel_id);
});
return $this->discord->guilds->find(fn (Guild $guild) => $guild->channels->offsetExists($this->channel_id));
}

return null;
Expand Down
4 changes: 1 addition & 3 deletions src/Discord/Parts/Channel/Message/MessageReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ protected function getGuildAttribute(): ?Guild

// Workaround for Channel::sendMessage() no guild_id
if ($this->channel_id) {
return $this->discord->guilds->find(function (Guild $guild) {
return $guild->channels->offsetExists($this->channel_id);
});
return $this->discord->guilds->find(fn (Guild $guild) => $guild->channels->offsetExists($this->channel_id));
}

return null;
Expand Down
4 changes: 1 addition & 3 deletions src/Discord/Parts/Guild/AuditLog/AuditLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ public function searchByType(int $action_type): ExCollectionInterface
throw new \InvalidArgumentException("The given action type `{$action_type}` is not valid.");
}

return $this->audit_log_entries->filter(function (Entry $entry) use ($action_type) {
return $entry->action_type === $action_type;
});
return $this->audit_log_entries->filter(fn (Entry $entry) => $entry->action_type === $action_type);
}
}
4 changes: 1 addition & 3 deletions src/Discord/Parts/Guild/Emoji.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,7 @@ protected function getRolesAttribute(): ExCollectionInterface
$roles->fill(array_fill_keys($this->attributes['roles'], null));

if ($guild = $this->guild) {
$roles->merge($guild->roles->filter(function ($role) {
return in_array($role->id, $this->attributes['roles']);
}));
$roles->merge($guild->roles->filter(fn ($role) => in_array($role->id, $this->attributes['roles'])));
}

return $roles;
Expand Down
4 changes: 1 addition & 3 deletions src/Discord/Parts/Guild/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,9 +1000,7 @@ public function transferOwnership($member, ?string $reason = null): PromiseInter
public function validateRegion(): PromiseInterface
{
return $this->getVoiceRegions()->then(function () {
$regions = $this->regions->map(function ($region) {
return $region->id;
})->jsonSerialize();
$regions = $this->regions->map(fn ($region) => $region->id)->jsonSerialize();

if (! in_array($this->region, $regions)) {
return self::REGION_DEFAULT;
Expand Down
4 changes: 1 addition & 3 deletions src/Discord/Parts/Guild/Sticker.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ class Sticker extends Part implements Stringable
*/
public function isPartial(): bool
{
$partial = array_filter($this->attributes, function ($var) {
return isset($var);
});
$partial = array_filter($this->attributes, fn ($var) => isset($var));

sort($partial);

Expand Down
4 changes: 1 addition & 3 deletions src/Discord/Repository/Guild/MemberRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,7 @@ public function freshen(?array $queryparams = null): PromiseInterface
$lastValueId = $value->user->id;
}

$this->cacheFreshen($response)->then(function () use ($paginate, $lastValueId) {
$paginate($lastValueId);
});
$this->cacheFreshen($response)->then(fn () => $paginate($lastValueId));
}, [$deferred, 'reject']);
})();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ public function getSubscriptions(array $options = [])
$resolver->setAllowedTypes('before', ['string', 'int', 'null']);
$resolver->setAllowedTypes('after', ['string', 'int', 'null']);
$resolver->setAllowedTypes('limit', ['int', 'null']);
$resolver->setAllowedValues('limit', function ($value) {
return $value === null || ($value >= 1 && $value <= 100);
});
$resolver->setAllowedValues(
'limit',
fn ($value) => $value === null || ($value >= 1 && $value <= 100)
);

$options = $resolver->resolve($options);

Expand Down
22 changes: 10 additions & 12 deletions src/Discord/Voice/OggPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,16 @@ public static function fromBuffer(Buffer $buffer, ?int $timeout = -1): PromiseIn
return $buffer->read($data, timeout: $timeout);
})
// Reading segment data
->then(function ($data) use (&$header, &$pageSegments) {
return new OggPage(
$header['version'],
$header['header_type'],
$header['granule_position'],
$header['bitstream_sn'],
$header['page_seq'],
$header['csum'],
$pageSegments,
$data
);
});
->then(fn ($data) => new OggPage(
$header['version'],
$header['header_type'],
$header['granule_position'],
$header['bitstream_sn'],
$header['page_seq'],
$header['csum'],
$pageSegments,
$data
));
}

/**
Expand Down
16 changes: 4 additions & 12 deletions src/Discord/Voice/ReceiveStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,11 @@ public function pipePCM(WritableStreamInterface $dest, array $options = []): voi
}
});

$dest->on('drain', function () {
$this->resume();
});
$dest->on('drain', fn () => $this->resume());

$end = isset($options['end']) ? $options['end'] : true;
if ($end && $this !== $dest) {
$this->on('end', function () use ($dest) {
$dest->end();
});
$this->on('end', fn () => $dest->end());
}
}

Expand All @@ -273,15 +269,11 @@ public function pipeOpus(WritableStreamInterface $dest, array $options = []): vo
}
});

$dest->on('drain', function () {
$this->resume();
});
$dest->on('drain', fn () => $this->resume());

$end = isset($options['end']) ? $options['end'] : true;
if ($end && $this !== $dest) {
$this->on('end', function () use ($dest) {
$dest->end();
});
$this->on('end', fn () => $dest->end());
}
}
}
4 changes: 1 addition & 3 deletions src/Discord/WebSockets/Events/GuildCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ public function handle($data)
$await[] = $guildPart->sounds->cache->set($sound->sound_id, $guildPart->sounds->create($sound, true));
}

$all = yield all($await)->then(function () use (&$guildPart) {
return $this->discord->guilds->cache->set($guildPart->id, $guildPart)->then(fn ($success) => $guildPart);
});
$all = yield all($await)->then(fn () => $this->discord->guilds->cache->set($guildPart->id, $guildPart)->then(fn ($success) => $guildPart));

if (
(
Expand Down
4 changes: 1 addition & 3 deletions src/Discord/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,7 @@ function escapeMarkdown(string $text): string
function deferFind($array, callable $callback, $loop = null): PromiseInterface
{
$cancelled = false;
$deferred = new Deferred(function () use (&$cancelled) {
$cancelled = true;
});
$deferred = new Deferred(fn () => $cancelled = true);
$iterator = new ArrayIterator($array);

$loop ??= Loop::get();
Expand Down