Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support media channels #1050

Merged
merged 34 commits into from
Feb 13, 2024
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
dbf8d6f
feat: basic media channel implementation
onerandomusername Jun 15, 2023
6a98dab
add more support
onerandomusername Jun 15, 2023
53b79b9
add simple changelog
onerandomusername Jun 15, 2023
fe507be
refactor forum channels into a base class
onerandomusername Jun 15, 2023
05cf41b
refactor channel webhooks to a mixin
onerandomusername Jun 15, 2023
41a1f28
chore: rename class to ThreadOnlyGuildChannel
onerandomusername Jun 15, 2023
03605cd
fix: channel factory
onerandomusername Jun 15, 2023
50bc574
fix: document MediaChannel
onerandomusername Jun 18, 2023
116a096
fix: use ` not '
onerandomusername Jun 18, 2023
aa13cd1
fix: update docstring for hide_media_download_options
onerandomusername Jun 18, 2023
82277e6
chore: add ChannelType.media to docs
onerandomusername Jun 18, 2023
69a5705
fix slots (probably)
onerandomusername Jun 18, 2023
72c4209
Merge remote-tracking branch 'origin/master' into feat/media-channel
onerandomusername Jul 26, 2023
3e5ed18
revert: "refactor channel webhooks to a mixin"
shiftinv Aug 1, 2023
8f64746
chore: run codemod
shiftinv Aug 1, 2023
91f381a
chore(docs): update versionadded
shiftinv Aug 1, 2023
5ad01f3
Merge branch 'master' into feat/media-channel
onerandomusername Aug 11, 2023
8751aef
Merge remote-tracking branch 'upstream/master'
shiftinv Feb 12, 2024
b2ca01e
refactor: drop `create_thread` impls in derived classes
shiftinv Feb 12, 2024
7b08757
chore: move comment to correct location
shiftinv Feb 12, 2024
d779a93
fix: move `default_layout` to `ForumChannel`, fix return annotations`
shiftinv Feb 12, 2024
ddf89b4
fix: add missing _fill_overwrites call
shiftinv Feb 12, 2024
b35840d
chore: implement `_get_channel` in base type
shiftinv Feb 12, 2024
b9b8a17
refactor: implement `typing` in base type
shiftinv Feb 12, 2024
f560631
nit: is forumable even a word
shiftinv Feb 12, 2024
972f4cd
fix: handle media channels in `Message.system_content`
shiftinv Feb 12, 2024
aeaef9a
chore: rename `disnake.types.channel._BaseForumGuildChannel`
shiftinv Feb 12, 2024
413c051
fix: consider media channels in audit log tag_id fallback
shiftinv Feb 12, 2024
dcfbbaa
docs: clarify that media channels are essentially fancy forum channels
shiftinv Feb 12, 2024
9e7fc7c
fix: add missing attributes for accessing/creating media channels
shiftinv Feb 12, 2024
60ae8bd
docs: add missing media channel docs, update docs that previously onl…
shiftinv Feb 12, 2024
7546350
feat: add `MediaChannel.hides_media_download_options` shortcut
shiftinv Feb 12, 2024
f0a56a9
docs: more documentation nits
shiftinv Feb 12, 2024
1abcafd
Merge branch 'master' into feat/media-channel
shiftinv Feb 12, 2024
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
Prev Previous commit
Next Next commit
fix: add missing attributes for accessing/creating media channels
  • Loading branch information
shiftinv committed Feb 12, 2024
commit 9e7fc7ce146344c56d4c0b2a99466f680daae06d
43 changes: 41 additions & 2 deletions disnake/channel.py
Original file line number Diff line number Diff line change
@@ -3012,7 +3012,10 @@ def channels(self) -> List[GuildChannelType]:
"""

def comparator(channel):
return (not isinstance(channel, (TextChannel, ForumChannel)), channel.position)
return (
not isinstance(channel, (TextChannel, ThreadOnlyGuildChannel)),
channel.position,
)

ret = [c for c in self.guild.channels if c.category_id == self.id]
ret.sort(key=comparator)
@@ -3068,6 +3071,20 @@ def forum_channels(self) -> List[ForumChannel]:
ret.sort(key=lambda c: (c.position, c.id))
return ret

@property
def media_channels(self) -> List[MediaChannel]:
"""List[:class:`MediaChannel`]: Returns the media channels that are under this category.

.. versionadded:: 2.10
"""
ret = [
c
for c in self.guild.channels
if c.category_id == self.id and isinstance(c, MediaChannel)
]
ret.sort(key=lambda c: (c.position, c.id))
return ret

async def create_text_channel(self, name: str, **options: Any) -> TextChannel:
"""|coro|

@@ -3128,6 +3145,22 @@ async def create_forum_channel(self, name: str, **options: Any) -> ForumChannel:
raise TypeError("got an unexpected keyword argument 'category'")
return await self.guild.create_forum_channel(name, category=self, **options)

async def create_media_channel(self, name: str, **options: Any) -> MediaChannel:
"""|coro|

A shortcut method to :meth:`Guild.create_media_channel` to create a :class:`MediaChannel` in the category.

.. versionadded:: 2.10

Returns
-------
:class:`MediaChannel`
The newly created media channel.
"""
if "category" in options:
raise TypeError("got an unexpected keyword argument 'category'")
return await self.guild.create_media_channel(name, category=self, **options)


class NewsChannel(TextChannel):
"""Represents a Discord news channel
@@ -3166,7 +3199,13 @@ class ThreadOnlyGuildChannel(disnake.abc.GuildChannel, Hashable):
"_overwrites",
)

def __init__(self, *, state: ConnectionState, guild: Guild, data: ForumChannelPayload) -> None:
def __init__(
self,
*,
state: ConnectionState,
guild: Guild,
data: Union[ForumChannelPayload, MediaChannelPayload],
) -> None:
self._state: ConnectionState = state
self.id: int = int(data["id"])
self._type: int = data["type"]
4 changes: 2 additions & 2 deletions disnake/threads.py
Original file line number Diff line number Diff line change
@@ -403,10 +403,10 @@ def applied_tags(self) -> List[ForumTag]:

.. versionadded:: 2.6
"""
from .channel import ForumChannel, MediaChannel # cyclic import
from .channel import ThreadOnlyGuildChannel # cyclic import

parent = self.parent
if not isinstance(parent, (ForumChannel, MediaChannel)):
if not isinstance(parent, ThreadOnlyGuildChannel):
return []

# threads may have tag IDs for tags that don't exist anymore
4 changes: 2 additions & 2 deletions disnake/webhook/async_.py
Original file line number Diff line number Diff line change
@@ -511,7 +511,7 @@ def handle_message_parameters_dict(
allowed_mentions: Optional[AllowedMentions] = MISSING,
previous_allowed_mentions: Optional[AllowedMentions] = None,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING,
# these parameters are exclusive to webhooks in forum channels
# these parameters are exclusive to webhooks in forum/media channels
thread_name: str = MISSING,
applied_tags: Sequence[Snowflake] = MISSING,
) -> DictPayloadParameters:
@@ -602,7 +602,7 @@ def handle_message_parameters(
allowed_mentions: Optional[AllowedMentions] = MISSING,
previous_allowed_mentions: Optional[AllowedMentions] = None,
stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING,
# these parameters are exclusive to webhooks in forum channels
# these parameters are exclusive to webhooks in forum/media channels
thread_name: str = MISSING,
applied_tags: Sequence[Snowflake] = MISSING,
) -> PayloadParameters: