-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e584be6
commit 1dd4760
Showing
5 changed files
with
247 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/Discord/WebSockets/Events/GuildSoundboardSoundCreate.php
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the DiscordPHP project. | ||
* | ||
* Copyright (c) 2015-present David Cole <david.cole1340@gmail.com> | ||
* | ||
* This file is subject to the MIT license that is bundled | ||
* with this source code in the LICENSE.md file. | ||
*/ | ||
|
||
namespace Discord\WebSockets\Events; | ||
|
||
use Discord\Parts\Guild\Guild; | ||
use Discord\Parts\Guild\Sound; | ||
use Discord\Repository\Guild\SoundRepository; | ||
use Discord\WebSockets\Event; | ||
|
||
/** | ||
* @link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-create | ||
* | ||
* @since 10.0.0 | ||
*/ | ||
class GuildSoundboardSoundCreate extends Event | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle($data) | ||
{ | ||
/** @var Sound */ | ||
$part = $this->factory->part(Sound::class, (array) $data, true); | ||
|
||
/** @var Guild|null */ | ||
$guild = yield $this->discord->guilds->cacheGet($data->guild_id); | ||
|
||
if (! $guild instanceof Guild) { | ||
return $part; | ||
} | ||
|
||
/** @var SoundRepository */ | ||
if ($repository = $guild->sounds) { | ||
$repository->set($part->sound_id, $part); | ||
} | ||
|
||
return $part; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Discord/WebSockets/Events/GuildSoundboardSoundDelete.php
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the DiscordPHP project. | ||
* | ||
* Copyright (c) 2015-present David Cole <david.cole1340@gmail.com> | ||
* | ||
* This file is subject to the MIT license that is bundled | ||
* with this source code in the LICENSE.md file. | ||
*/ | ||
|
||
namespace Discord\WebSockets\Events; | ||
|
||
use Discord\Parts\Guild\Guild; | ||
use Discord\Parts\Guild\Sound; | ||
use Discord\WebSockets\Event; | ||
|
||
/** | ||
* @link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-delete | ||
* | ||
* @since 10.0.0 | ||
*/ | ||
class GuildSoundboardSoundDelete extends Event | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle($data) | ||
{ | ||
$part = null; | ||
|
||
/** @var ?Guild */ | ||
if ($guild = yield $this->discord->guilds->cacheGet($data->guild_id)) { | ||
/** @var ?Sound */ | ||
$part = yield $guild->soundboard_sounds->cachePull($data->sound_id); | ||
if ($part instanceof Sound) { | ||
$part->fill((array) $data); | ||
$part->created = false; | ||
} | ||
} | ||
|
||
return $part ?? $this->factory->part(Sound::class, (array) $data); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Discord/WebSockets/Events/GuildSoundboardSoundUpdate.php
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the DiscordPHP project. | ||
* | ||
* Copyright (c) 2015-present David Cole <david.cole1340@gmail.com> | ||
* | ||
* This file is subject to the MIT license that is bundled | ||
* with this source code in the LICENSE.md file. | ||
*/ | ||
|
||
namespace Discord\WebSockets\Events; | ||
|
||
use Discord\Parts\Guild\Guild; | ||
use Discord\Parts\Guild\Sound; | ||
use Discord\WebSockets\Event; | ||
|
||
/** | ||
* @link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-update | ||
* | ||
* @since 10.0.0 | ||
*/ | ||
class GuildSoundboardSoundUpdate extends Event | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle($data) | ||
{ | ||
$newPart = $oldPart = null; | ||
|
||
/** @var Guild|null */ | ||
$guild = yield $this->discord->guilds->cacheGet($data->guild_id); | ||
if (! $guild instanceof Guild) { | ||
/** @var Sound */ | ||
$newPart = $this->factory->part(Sound::class, (array) $data, true); | ||
return [$newPart, $oldPart]; | ||
} | ||
|
||
/** @var ?Sound */ | ||
$oldPart = yield $guild->sounds->cacheGet($data->sound_id); | ||
if ($oldPart instanceof Sound) { | ||
$newPart = clone $oldPart; | ||
$newPart->fill((array) $data); | ||
} else { | ||
/** @var Sound */ | ||
$newPart = $this->factory->part(Sound::class, (array) $data, true); | ||
} | ||
|
||
/** @var SoundRepository */ | ||
if ($repository = $guild->sounds) { | ||
$repository->set($newPart->sound_id, $newPart); | ||
} | ||
|
||
return [$newPart, $oldPart]; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Discord/WebSockets/Events/GuildSoundboardSoundsUpdate.php
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the DiscordPHP project. | ||
* | ||
* Copyright (c) 2015-present David Cole <david.cole1340@gmail.com> | ||
* | ||
* This file is subject to the MIT license that is bundled | ||
* with this source code in the LICENSE.md file. | ||
*/ | ||
|
||
namespace Discord\WebSockets\Events; | ||
|
||
use Discord\Parts\Guild\Guild; | ||
use Discord\Parts\Guild\Sound; | ||
use Discord\Repository\Guild\SoundRepository; | ||
use Discord\WebSockets\Event; | ||
|
||
/** | ||
* @link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sounds-update | ||
* | ||
* @since 10.0.0 | ||
*/ | ||
class GuildSoundboardSoundsUpdate extends Event | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle($data) | ||
{ | ||
/** @var Guild|null */ | ||
$guild = yield $this->discord->guilds->cacheGet($data->guild_id); | ||
|
||
if (! $guild instanceof Guild) { | ||
return null; | ||
} | ||
|
||
/** @var SoundRepository */ | ||
$repository = $guild->sounds; | ||
|
||
foreach ($data as $soundData) { | ||
/** @var SoundboardSound */ | ||
$part = $this->factory->part(Sound::class, (array) $soundData, true); | ||
$repository->set($part->sound_id, $part); | ||
} | ||
|
||
return $repository; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is a part of the DiscordPHP project. | ||
* | ||
* Copyright (c) 2015-present David Cole <david.cole1340@gmail.com> | ||
* | ||
* This file is subject to the MIT license that is bundled | ||
* with this source code in the LICENSE.md file. | ||
*/ | ||
|
||
namespace Discord\WebSockets\Events; | ||
|
||
use Discord\Parts\Guild\Guild; | ||
use Discord\Parts\Guild\Sound; | ||
use Discord\Repository\Guild\SoundRepository; | ||
use Discord\WebSockets\Event; | ||
|
||
/** | ||
* @link https://discord.com/developers/docs/topics/gateway-events#soundboard-sounds | ||
* | ||
* @since 10.0.0 | ||
*/ | ||
class SoundboardSounds extends Event | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function handle($data) | ||
{ | ||
/** @var Guild|null */ | ||
$guild = yield $this->discord->guilds->cacheGet($data->guild_id); | ||
|
||
if (! $guild instanceof Guild) { | ||
return null; | ||
} | ||
|
||
/** @var SoundRepository */ | ||
$repository = $guild->sounds; | ||
|
||
foreach ($data->soundboard_sounds as $soundData) { | ||
/** @var Sound */ | ||
$part = $this->factory->part(Sound::class, (array) $soundData, true); | ||
$repository->set($part->sound_id, $part); | ||
} | ||
|
||
return $repository; | ||
} | ||
} |