-
-
Notifications
You must be signed in to change notification settings - Fork 239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minor code cleanup #1079
Closed
+16
−15
Closed
Minor code cleanup #1079
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2834ffe
Minor code cleanup
valzargaming 93bad4d
Update Discord.php
valzargaming 4672255
Update Discord.php
valzargaming d0517dd
Update Discord.php
valzargaming b4439b1
Update Discord.php
valzargaming 5a3c1e1
Update Discord.php
valzargaming f6c4e52
Update Discord.php
valzargaming 546d83d
Update Discord.php
valzargaming e19962f
Forgot to use $handler
valzargaming File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -771,10 +771,9 @@ protected function handleDispatch(object $data): void | |||||
/** @var Event */ | ||||||
$handler = new $hData['class']($this); | ||||||
|
||||||
$deferred = new Deferred(); | ||||||
$deferred->promise()->done(function ($d) use ($data, $hData) { | ||||||
if (is_array($d) && count($d) == 2) { | ||||||
list($new, $old) = $d; | ||||||
$onResolve = function ($d) use ($data, $hData) { | ||||||
if (is_array($d) && count($d) === 2) { | ||||||
[$new, $old] = $d; | ||||||
} else { | ||||||
$new = $d; | ||||||
$old = null; | ||||||
|
@@ -786,34 +785,36 @@ protected function handleDispatch(object $data): void | |||||
$this->emit($alternative, [$d, $this]); | ||||||
} | ||||||
|
||||||
if ($data->t == Event::MESSAGE_CREATE && mentioned($this->client->user, $new)) { | ||||||
if ($data->t === Event::MESSAGE_CREATE && mentioned($this->client->user, $new)) { | ||||||
$this->emit('mention', [$new, $this, $old]); | ||||||
} | ||||||
}, function ($e) use ($data) { | ||||||
}; | ||||||
|
||||||
$onReject = function ($e) use ($data) { | ||||||
if ($e instanceof \Error) { | ||||||
throw $e; | ||||||
} elseif ($e instanceof \Exception) { | ||||||
} | ||||||
|
||||||
if ($e instanceof \Exception) { | ||||||
$this->logger->error('exception while trying to handle dispatch packet', ['packet' => $data->t, 'exception' => $e]); | ||||||
} else { | ||||||
$this->logger->warning('rejection while trying to handle dispatch packet', ['packet' => $data->t, 'rejection' => $e]); | ||||||
} | ||||||
}); | ||||||
}; | ||||||
|
||||||
$parse = [ | ||||||
Event::GUILD_CREATE, | ||||||
Event::GUILD_DELETE, | ||||||
]; | ||||||
|
||||||
if (! $this->emittedInit && (! in_array($data->t, $parse))) { | ||||||
$this->unparsedPackets[] = function () use (&$handler, &$deferred, &$data) { | ||||||
/** @var ExtendedPromiseInterface */ | ||||||
|
||||||
if (! $this->emittedInit && ! in_array($data->t, $parse)) { | ||||||
$this->unparsedPackets[] = function () use (&$handler, &$onResolve, &$onReject, &$data) { | ||||||
$promise = coroutine([$handler, 'handle'], $data->d); | ||||||
$promise->done([$deferred, 'resolve'], [$deferred, 'reject']); | ||||||
$promise->done(&$onResolve, &$onReject); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. &$deferred was previously passed by reference, and these functions replace deferred |
||||||
}; | ||||||
} else { | ||||||
/** @var ExtendedPromiseInterface */ | ||||||
$promise = coroutine([$handler, 'handle'], $data->d); | ||||||
$promise->done([$deferred, 'resolve'], [$deferred, 'reject']); | ||||||
$promise->done($onResolve, $onReject); | ||||||
} | ||||||
} | ||||||
|
||||||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you passing these as reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&$deferred was previously passed by reference, and these functions replace deferred