Skip to content

Commit

Permalink
Subscription events
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Sep 29, 2024
1 parent 86b21f6 commit 2ed4eca
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Discord/WebSockets/Events/EntitlementDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EntitlementDelete extends Event
public function handle($data)
{
/** @var ?Entitlement */
$entitlementPart = yield $this->discord->entitlements->cachePull($data->role_id);
$entitlementPart = yield $this->discord->entitlements->cachePull($data->id);

return $entitlementPart ?? $this->factory->part(Entitlement::class, (array) $data);
}
Expand Down
37 changes: 37 additions & 0 deletions src/Discord/WebSockets/Events/SubscriptionCreate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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\Entitlements\SKU;
use Discord\WebSockets\Event;

/**
* @link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-create
*
* @since 10.0.0
*/
class SKUCreate extends Event
{
/**
* {@inheritDoc}
*/
public function handle($data)
{
/** @var SKU */
$SKUPart = $this->factory->part(SKU::class, (array) $data, true);

$this->discord->skus->set($data->id, $SKUPart);

return $SKUPart;
}
}
34 changes: 34 additions & 0 deletions src/Discord/WebSockets/Events/SubscriptionDelete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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\Entitlements\SKU;
use Discord\WebSockets\Event;

/**
* @link https://discord.com/developers/docs/topics/gateway-events#guild-soundboard-sound-delete
*
* @since 10.0.0
*/
class SKUDelete extends Event
{
/**
* {@inheritDoc}
*/
public function handle($data)
{
/** @var ?SKU */
$SKUPart = yield $this->discord->skus->cachePull($data->id);

return $SKUPart ?? $this->factory->part(SKU::class, (array) $data);
}
}
54 changes: 54 additions & 0 deletions src/Discord/WebSockets/Events/SubscriptionUpdate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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\Entitlements\SKU;
use Discord\WebSockets\Event;

/**
* @link https://discord.com/developers/docs/topics/gateway-events#guild-SKUboard-SKU-update
*
* @since 10.0.0
*/
class SKUUpdate extends Event
{
/**
* {@inheritDoc}
*/
public function handle($data)
{
$newSKUPart = $oldSKUPart = null;

/** @var ?SKU */
$oldSKUPart = yield $this->discord->skus->cacheGet($data->id);
if ($oldSKUPart instanceof SKU) {
$newSKUPart = clone $oldSKUPart;
$newSKUPart->fill((array) $data);
}

/** @var SKU */
$newSKUPart = $newSKUPart ?? $this->factory->part(SKU::class, (array) $data, true);

$this->discord->skus->set($data->id, $newSKUPart);

return [$newSKUPart, $oldSKUPart];
}
}








0 comments on commit 2ed4eca

Please sign in to comment.