|
19 | 19 | use Discord\Parts\Thread\Thread; |
20 | 20 | use Discord\Parts\User\User; |
21 | 21 | use React\Promise\ExtendedPromiseInterface; |
| 22 | +use stdClass; |
22 | 23 | use Symfony\Component\OptionsResolver\OptionsResolver; |
23 | 24 |
|
24 | 25 | use function Discord\normalizePartId; |
@@ -50,6 +51,7 @@ class Reaction extends Part |
50 | 51 | * {@inheritDoc} |
51 | 52 | */ |
52 | 53 | protected $fillable = [ |
| 54 | + 'id', // internal |
53 | 55 | 'count', |
54 | 56 | 'me', |
55 | 57 | 'emoji', |
@@ -81,6 +83,42 @@ public function fetch(): ExtendedPromiseInterface |
81 | 83 | }); |
82 | 84 | } |
83 | 85 |
|
| 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 | + |
84 | 122 | /** |
85 | 123 | * Gets the emoji identifier. |
86 | 124 | * |
|
0 commit comments