Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Discord/Builders/ChannelBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@
namespace Discord\Builders;

use Discord\Http\Exceptions\RequestFailedException;
use Discord\Parts\Channel\AnnouncementThread;
use Discord\Parts\Channel\Channel;
use Discord\Parts\Channel\DM;
use Discord\Parts\Channel\GroupDM;
use Discord\Parts\Channel\GuildAnnouncement;
use Discord\Parts\Channel\GuildCategory;
use Discord\Parts\Channel\GuildDirectory;
use Discord\Parts\Channel\GuildForum;
use Discord\Parts\Channel\GuildMedia;
use Discord\Parts\Channel\GuildStageVoice;
use Discord\Parts\Channel\GuildText;
use Discord\Parts\Channel\GuildVoice;
use Discord\Parts\Channel\Overwrite;
use Discord\Parts\Channel\PrivateThread;
use Discord\Parts\Channel\PublicThread;
use Discord\Parts\Guild\Emoji;
use Discord\Voice\Region;
use JsonSerializable;
Expand All @@ -31,6 +44,22 @@
*/
class ChannelBuilder extends Builder implements JsonSerializable
{
public const TYPES = [
Channel::TYPE_GUILD_TEXT => GuildText::class, // A text channel within a server
Channel::TYPE_DM => DM::class, // A direct message between users
Channel::TYPE_GUILD_VOICE => GuildVoice::class, // A voice channel within a server
Channel::TYPE_GROUP_DM => GroupDM::class, // A direct message between multiple users
Channel::TYPE_GUILD_CATEGORY => GuildCategory::class, // An organizational category that contains up to 50 channels
Channel::TYPE_GUILD_ANNOUNCEMENT => GuildAnnouncement::class, // A channel that users can follow and crosspost into their own server (formerly news channels)
Channel::TYPE_ANNOUNCEMENT_THREAD => AnnouncementThread::class, // A temporary sub-channel within a GUILD_ANNOUNCEMENT channel
Channel::TYPE_PUBLIC_THREAD => PublicThread::class, // A temporary sub-channel within a GUILD_TEXT or GUILD_FORUM channel
Channel::TYPE_PRIVATE_THREAD => PrivateThread::class, // A temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
Channel::TYPE_GUILD_STAGE_VOICE => GuildStageVoice::class, // A voice channel for hosting events with an audience
Channel::TYPE_GUILD_DIRECTORY => GuildDirectory::class, // The channel in a hub containing the listed servers
Channel::TYPE_GUILD_FORUM => GuildForum::class, // Channel that can only contain threads
Channel::TYPE_GUILD_MEDIA => GuildMedia::class, // Channel that can only contain threads, similar to GUILD_FORUM channels
];

protected string $name;
protected ?int $type;
protected ?string $topic; // Text, Announcement, Forum, Media
Expand Down
20 changes: 20 additions & 0 deletions src/Discord/Parts/Channel/AnnouncementThread.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

use Discord\Parts\Thread\Thread;

class AnnouncementThread extends Thread
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/DM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class DM extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GroupDM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GroupDM extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildAnnouncement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildAnnouncement extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildCategory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildCategory extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildDirectory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildDirectory extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildForum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildForum extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildMedia extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildStageVoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildStageVoice extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildText extends Channel
{
}
18 changes: 18 additions & 0 deletions src/Discord/Parts/Channel/GuildVoice.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

class GuildVoice extends Channel
{
}
3 changes: 2 additions & 1 deletion src/Discord/Parts/Channel/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,9 +471,10 @@ protected function getChannelAttribute(): Part
return $channel;
}

return $this->factory->part(Channel::class, [
return $this->factory->part(DM::class, [
'id' => $this->channel_id,
'type' => Channel::TYPE_DM,
'recipients' => [$this->author],
], true);
}

Expand Down
20 changes: 20 additions & 0 deletions src/Discord/Parts/Channel/PrivateThread.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

use Discord\Parts\Thread\Thread;

class PrivateThread extends Thread
{
}
20 changes: 20 additions & 0 deletions src/Discord/Parts/Channel/PublicThread.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

/*
* This file is a part of the DiscordPHP project.
*
* Copyright (c) 2015-present David Cole <[email protected]>
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/

namespace Discord\Parts\Channel;

use Discord\Parts\Thread\Thread;

class PublicThread extends Thread
{
}
1 change: 1 addition & 0 deletions src/Discord/Parts/Guild/Guild.php
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,7 @@ public function save(?string $reason = null): PromiseInterface
return reject(new NoPermissionsException("You do not have permission to save changes to the guild {$this->id}."));
}
}

return $this->discord->guilds->save($this, $reason);
}

Expand Down
7 changes: 2 additions & 5 deletions src/Discord/Parts/Interactions/Request/Resolved.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Discord\Parts\Interactions\Request;

use Discord\Builders\ChannelBuilder;
use Discord\Helpers\Collection;
use Discord\Helpers\ExCollectionInterface;
use Discord\Parts\Channel\Attachment;
Expand Down Expand Up @@ -186,11 +187,7 @@ protected function getChannelsAttribute(): ExCollectionInterface
}

if (! isset($channelPart)) {
if (in_array($channel->type, [Channel::TYPE_ANNOUNCEMENT_THREAD, Channel::TYPE_PRIVATE_THREAD, Channel::TYPE_PUBLIC_THREAD])) {
$channelPart = $this->factory->part(Thread::class, (array) $channel + ['guild_id' => $this->guild_id], true);
} else {
$channelPart = $this->factory->part(Channel::class, (array) $channel + ['guild_id' => $this->guild_id], true);
}
$channelPart = $this->factory->part(ChannelBuilder::TYPES[$channel->type] ?? Channel::class, (array) $channel + ['guild_id' => $this->guild_id], true);
}

$collection->pushItem($channelPart);
Expand Down
2 changes: 1 addition & 1 deletion src/Discord/Parts/PartTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function afterConstruct(): void
*
* @param string|null $reason The reason for the audit log, if supported.
*
* @throws \Exception If the part does not support saving.
* @throws \Exception If the part does not support saving.
* @throws NoPermissionsException Missing permission.
*
* @return PromiseInterface<Part> Resolves with the saved part.
Expand Down
3 changes: 2 additions & 1 deletion src/Discord/WebSockets/Events/ChannelCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Discord\WebSockets\Events;

use Discord\Builders\ChannelBuilder;
use Discord\Parts\Channel\Channel;
use Discord\WebSockets\Event;
use Discord\Parts\Guild\Guild;
Expand All @@ -30,7 +31,7 @@ class ChannelCreate extends Event
public function handle($data)
{
/** @var Channel */
$channelPart = $this->factory->part(Channel::class, (array) $data, true);
$channelPart = $this->factory->part(ChannelBuilder::TYPES[$data->type] ?? Channel::class, (array) $data, true);

if ($channelPart->is_private) {
$this->discord->private_channels->set($data->id, $channelPart);
Expand Down
3 changes: 2 additions & 1 deletion src/Discord/WebSockets/Events/ChannelDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Discord\WebSockets\Events;

use Discord\Builders\ChannelBuilder;
use Discord\Parts\Channel\Channel;
use Discord\WebSockets\Event;

Expand All @@ -39,6 +40,6 @@ public function handle($data)
}
}

return $channelPart ?? $this->factory->part(Channel::class, (array) $data);
return $channelPart ?? $this->factory->part(ChannelBuilder::TYPES[$data->type] ?? Channel::class, (array) $data);
}
}
3 changes: 2 additions & 1 deletion src/Discord/WebSockets/Events/ChannelUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Discord\WebSockets\Events;

use Discord\Builders\ChannelBuilder;
use Discord\Parts\Channel\Channel;
use Discord\WebSockets\Event;

Expand All @@ -31,7 +32,7 @@ public function handle($data)
$oldChannel = $repository = null;

/** @var Channel */
$channelPart = $this->factory->part(Channel::class, (array) $data, true);
$channelPart = $this->factory->part(ChannelBuilder::TYPES[$data->type] ?? Channel::class, (array) $data, true);

if ($channelPart->is_private) {
/** @var ?Channel */
Expand Down
Loading