Skip to content

Commit 1552401

Browse files
committed
Add reactions->fetch()
1 parent bd4f6dd commit 1552401

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Discord/Parts/Channel/Reaction.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Discord\Parts\Thread\Thread;
2020
use Discord\Parts\User\User;
2121
use React\Promise\ExtendedPromiseInterface;
22+
use stdClass;
2223
use Symfony\Component\OptionsResolver\OptionsResolver;
2324

2425
use function Discord\normalizePartId;
@@ -50,6 +51,7 @@ class Reaction extends Part
5051
* {@inheritDoc}
5152
*/
5253
protected $fillable = [
54+
'id', // internal
5355
'count',
5456
'me',
5557
'emoji',
@@ -81,6 +83,42 @@ public function fetch(): ExtendedPromiseInterface
8183
});
8284
}
8385

86+
/**
87+
* Sets the emoji identifier.
88+
*
89+
* @internal Used for ReactionRepository::fetch()
90+
*
91+
* @param string $value name:id or the character of standard emoji
92+
*
93+
* @return void
94+
*
95+
* @since 10.0.0
96+
*/
97+
protected function setIdAttribute(string $value): void
98+
{
99+
if (! isset($this->attributes['emoji'])) {
100+
$this->attributes['emoji'] = new stdClass;
101+
}
102+
103+
$colonDelimiter = explode(':', $value);
104+
$delimitedCount = count($colonDelimiter);
105+
$emojiId = $emojiAnimated = null;
106+
107+
if ($delimitedCount == 2) { // Custom emoji name:id
108+
[$emojiName, $emojiId] = $colonDelimiter;
109+
} elseif ($delimitedCount == 3) { // Custom animated emoji a:name:id
110+
[$emojiAnimated, $emojiName, $emojiId] = $colonDelimiter;
111+
} else { // Standard emoji (or just have abnormal colon count)
112+
$emojiName = $value;
113+
}
114+
115+
$this->attributes['emoji']->id = $emojiId;
116+
$this->attributes['emoji']->name = $emojiName;
117+
if ($emojiAnimated == 'a') {
118+
$this->attributes['emoji']->animated = true;
119+
}
120+
}
121+
84122
/**
85123
* Gets the emoji identifier.
86124
*

src/Discord/Repository/Channel/ReactionRepository.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ReactionRepository extends AbstractRepository
3636
* {@inheritDoc}
3737
*/
3838
protected $endpoints = [
39+
'get' => Endpoint::MESSAGE_REACTION_EMOJI,
3940
'delete' => Endpoint::MESSAGE_REACTION_EMOJI,
4041
];
4142

0 commit comments

Comments
 (0)