Skip to content

Commit 4012274

Browse files
committed
Interaction => Unbound
Only certain endpoints are not bound to the global ratelimit, but it's not limited to just Interactions
1 parent bd179ca commit 4012274

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/Discord/Http.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Http implements HttpInterface
117117
*
118118
* @var SplQueue
119119
*/
120-
protected $interactionQueue;
120+
protected $unboundQueue;
121121

122122
/**
123123
* Number of requests that are waiting for a response.
@@ -145,7 +145,7 @@ public function __construct(string $token, LoopInterface $loop, LoggerInterface
145145
$this->logger = $logger;
146146
$this->driver = $driver;
147147
$this->queue = new SplQueue;
148-
$this->interactionQueue = new SplQueue;
148+
$this->unboundQueue = new SplQueue;
149149

150150
$this->promiseV3 = str_starts_with(InstalledVersions::getVersion('react/promise'), '3.');
151151
}

src/Discord/HttpInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function put($url, $content = null, array $headers = []): PromiseInterfac
2828
public function patch($url, $content = null, array $headers = []): PromiseInterface;
2929
public function delete($url, $content = null, array $headers = []): PromiseInterface;
3030
public function queueRequest(string $method, Endpoint $url, $content, array $headers = []): PromiseInterface;
31-
public static function isInteractionEndpoint(Request $request): bool;
31+
public static function isUnboundEndpoint(Request $request): bool;
3232
public function handleError(ResponseInterface $response): \Throwable;
3333
public function getUserAgent(): string;
34-
}
34+
}

src/Discord/HttpTrait.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ protected function getBucket(string $key): Bucket
330330
if (! isset($this->buckets[$key])) {
331331
$bucket = new Bucket($key, $this->loop, $this->logger, function (Request $request) {
332332
$deferred = new Deferred();
333-
self::isInteractionEndpoint($request)
334-
? $this->interactionQueue->enqueue([$request, $deferred])
333+
self::isUnboundEndpoint($request)
334+
? $this->unboundQueue->enqueue([$request, $deferred])
335335
: $this->queue->enqueue([$request, $deferred]);
336336
$this->checkQueue();
337337

@@ -351,7 +351,7 @@ protected function getBucket(string $key): Bucket
351351
protected function checkQueue(bool $check_interactions = true): void
352352
{
353353
if ($check_interactions) {
354-
$this->checkInteractionQueue();
354+
$this->checkunboundQueue();
355355
}
356356

357357
if ($this->waiting >= Http::CONCURRENT_REQUESTS || $this->queue->isEmpty()) {
@@ -382,10 +382,10 @@ protected function checkQueue(bool $check_interactions = true): void
382382
* Checks the interaction queue to see if more requests can be
383383
* sent out.
384384
*/
385-
protected function checkInteractionQueue(): void
385+
protected function checkunboundQueue(): void
386386
{
387-
if ($this->interactionQueue->isEmpty()) {
388-
$this->logger->debug('http not checking interaction queue', ['waiting' => $this->waiting, 'empty' => $this->interactionQueue->isEmpty()]);
387+
if ($this->unboundQueue->isEmpty()) {
388+
$this->logger->debug('http not checking interaction queue', ['waiting' => $this->waiting, 'empty' => $this->unboundQueue->isEmpty()]);
389389

390390
return;
391391
}
@@ -394,7 +394,7 @@ protected function checkInteractionQueue(): void
394394
* @var Request $request
395395
* @var Deferred $deferred
396396
*/
397-
[$request, $deferred] = $this->interactionQueue->dequeue();
397+
[$request, $deferred] = $this->unboundQueue->dequeue();
398398

399399
$this->executeRequest($request)->then(function ($result) use ($deferred) {
400400
$this->checkQueue();
@@ -413,10 +413,11 @@ protected function checkInteractionQueue(): void
413413
* @param Request $request
414414
* @return bool
415415
*/
416-
public static function isInteractionEndpoint(Request $request): bool
416+
public static function isUnboundEndpoint(Request $request): bool
417417
{
418-
$url = $request->getUrl();
419-
return strpos($url, '/interactions') === 0 || strpos($url, '/callback') === 0;
418+
return
419+
(strpos($request->getUrl(), '/interactions') !== false && strpos($request->getUrl(), '/callback') !== false)
420+
|| (strpos($request->getUrl(), '/webhooks') !== false && strpos($request->getUrl(), '/messages') !== false);
420421
}
421422

422423
/**

0 commit comments

Comments
 (0)