From ee1698f815f63ebedfe1643c9e852c9535ec9091 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Sat, 19 Mar 2022 10:13:15 +0700 Subject: [PATCH 01/11] feat: Adding icon_url property for team.Application --- interactions/api/models/team.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/interactions/api/models/team.py b/interactions/api/models/team.py index 78c877a3b..c20b9d7aa 100644 --- a/interactions/api/models/team.py +++ b/interactions/api/models/team.py @@ -117,3 +117,18 @@ def __init__(self, **kwargs): self.owner = User(**self.owner) if self._json.get("owner") else None self.team = Team(**self.team) if self._json.get("team") else None self.flags = AppFlags(self.flags) if self._json.get("flags") else None + @property + def icon_url(self) -> str: + """ + Returns the URL of the application's icon + + :return: URL of the application's icon. + :rtype: str + """ + url = "https://cdn.discordapp.com/" + if self.icon: + url += f"avatars/{int(self.id)}/{self.icon}" + url += ".gif" if self.icon.startswith("a_") else ".png" + else: + url += f"embed/avatars/{int(self.discriminator) % 5}.png" + return url From b2b3e0242ae49d0dff8daad0494d8b7fb09b4736 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 19 Mar 2022 03:17:55 +0000 Subject: [PATCH 02/11] ci: correct from checks. --- interactions/api/models/team.py | 1 + 1 file changed, 1 insertion(+) diff --git a/interactions/api/models/team.py b/interactions/api/models/team.py index c20b9d7aa..3a0d6d6f1 100644 --- a/interactions/api/models/team.py +++ b/interactions/api/models/team.py @@ -117,6 +117,7 @@ def __init__(self, **kwargs): self.owner = User(**self.owner) if self._json.get("owner") else None self.team = Team(**self.team) if self._json.get("team") else None self.flags = AppFlags(self.flags) if self._json.get("flags") else None + @property def icon_url(self) -> str: """ From fa98338946bc506411a77b26795449bb9ab97b97 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Sun, 20 Mar 2022 00:28:08 +0700 Subject: [PATCH 03/11] Update team.pyi --- interactions/api/models/team.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interactions/api/models/team.pyi b/interactions/api/models/team.pyi index 2d2a610df..5aa158887 100644 --- a/interactions/api/models/team.pyi +++ b/interactions/api/models/team.pyi @@ -44,3 +44,5 @@ class Application(DictSerializerMixin): type: Optional[Any] hook: Optional[Any] def __init__(self, **kwargs): ... + @property + def icon_url(self) -> str: From 42218399db57888f9e5e2c957224a4c76aa7af12 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Sun, 20 Mar 2022 00:33:05 +0700 Subject: [PATCH 04/11] feat: Adding icon_url property for team.Application --- interactions/api/models/team.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/api/models/team.pyi b/interactions/api/models/team.pyi index 5aa158887..84c053f16 100644 --- a/interactions/api/models/team.pyi +++ b/interactions/api/models/team.pyi @@ -45,4 +45,4 @@ class Application(DictSerializerMixin): hook: Optional[Any] def __init__(self, **kwargs): ... @property - def icon_url(self) -> str: + def icon_url(self) -> str: ... From 8eb00252c95e3b2397e87dbd272ec1d7b1f8f593 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Sat, 26 Mar 2022 23:11:46 +0700 Subject: [PATCH 05/11] fix: Fix the ``icon_url`` property and how the ``url`` is returned --- interactions/api/models/team.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/interactions/api/models/team.py b/interactions/api/models/team.py index 3a0d6d6f1..12f3191cb 100644 --- a/interactions/api/models/team.py +++ b/interactions/api/models/team.py @@ -124,12 +124,11 @@ def icon_url(self) -> str: Returns the URL of the application's icon :return: URL of the application's icon. - :rtype: str + :rtype: str (None will be returned if none of any icon is set) """ url = "https://cdn.discordapp.com/" if self.icon: - url += f"avatars/{int(self.id)}/{self.icon}" - url += ".gif" if self.icon.startswith("a_") else ".png" + url += f"app-icons/{int(self.id)}/{self.icon}.png" else: - url += f"embed/avatars/{int(self.discriminator) % 5}.png" + url = None return url From 3f7ca3490e901d062954bced804671f50d768f02 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Mon, 28 Mar 2022 18:23:59 +0700 Subject: [PATCH 06/11] feat: Adding ``icon_url`` property for api.models.guild.Guild --- interactions/api/models/guild.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 2f2476bb5..2c7fa187c 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1599,6 +1599,21 @@ async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Mem guild_id=int(self.id), query=query, limit=limit ) return [Member(**member, _client=self._client) for member in res] + + @property + def icon_url(self) -> str: + """ + Returns the URL of the guild's icon. + + :return: URL of the guild's icon (None will be returned if none of icon is set) + :rtype: str + """ + url = "https://cdn.discordapp.com/" + if self.icon is not None: + url += f"icons/{int(self.id)}/{self.icon}.png" + else: + url = None + return url class GuildPreview(DictSerializerMixin): From faa3bf16130e50addff501ddfd3c25f746d249db Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Mon, 28 Mar 2022 18:31:45 +0700 Subject: [PATCH 07/11] feat: Adding icon_url property for returning the guild's icon under api.models.guild.Guild --- interactions/api/models/guild.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interactions/api/models/guild.pyi b/interactions/api/models/guild.pyi index 69bbea3bd..bb20ca5af 100644 --- a/interactions/api/models/guild.pyi +++ b/interactions/api/models/guild.pyi @@ -409,6 +409,8 @@ class Guild(DictSerializerMixin): query: str, limit: Optional[int] = 1 ) -> List[Member]: ... + @property + def icon_url(self) -> str: ... class GuildPreview(DictSerializerMixin): _json: dict From ead106cadf048b3afb34a0d12ce4e683e8d1e8d2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 28 Mar 2022 11:35:33 +0000 Subject: [PATCH 08/11] ci: correct from checks. --- interactions/api/models/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 2c7fa187c..7b30beca3 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1599,7 +1599,7 @@ async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Mem guild_id=int(self.id), query=query, limit=limit ) return [Member(**member, _client=self._client) for member in res] - + @property def icon_url(self) -> str: """ From 530ec9e78c632b3a362be10b9f335189a47a3921 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:50:54 +0700 Subject: [PATCH 09/11] feat: Adding support if ``self.icon`` is animated (fix for Pull Request 680) --- interactions/api/models/guild.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 7b30beca3..331d76894 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1608,11 +1608,9 @@ def icon_url(self) -> str: :return: URL of the guild's icon (None will be returned if none of icon is set) :rtype: str """ - url = "https://cdn.discordapp.com/" if self.icon is not None: - url += f"icons/{int(self.id)}/{self.icon}.png" - else: - url = None + url = f"https://cdn.discordapp.com/icons/{int(self.id)}/{self.icon}" + url += ".gif" if self.icon.startswith("a_") else ".png" return url From b5e5e544960fb8a36b39197aebf84a4a6026e5c1 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Tue, 29 Mar 2022 09:56:10 +0700 Subject: [PATCH 10/11] feat: Add else and set url as ``None`` is nothing icon returns ``None`` --- interactions/api/models/guild.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 331d76894..1571a3041 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1611,6 +1611,8 @@ def icon_url(self) -> str: if self.icon is not None: url = f"https://cdn.discordapp.com/icons/{int(self.id)}/{self.icon}" url += ".gif" if self.icon.startswith("a_") else ".png" + else: + url = None return url From 5c43ff996896b7405d1944f8b1fd315fdfa92344 Mon Sep 17 00:00:00 2001 From: Blue <60958064+Jimmy-Blue@users.noreply.github.com> Date: Thu, 31 Mar 2022 11:22:46 +0700 Subject: [PATCH 11/11] Resolving conflicts --- interactions/api/models/guild.py | 65 ++++++++++++++++++++++++++++---- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 1571a3041..44bc1f059 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -699,7 +699,7 @@ async def create_channel( :param topic?: The topic of that channel :type topic: Optional[str] :param bitrate?: (voice channel only) The bitrate (in bits) of the voice channel - :type bitrate Optional[int] + :type bitrate: Optional[int] :param user_limit?: (voice channel only) Maximum amount of users in the channel :type user_limit: Optional[int] :param rate_limit_per_use?: Amount of seconds a user has to wait before sending another message (0-21600) @@ -779,11 +779,17 @@ async def modify_channel( permission_overwrites: Optional[List[Overwrite]] = MISSING, parent_id: Optional[int] = MISSING, nsfw: Optional[bool] = MISSING, + archived: Optional[bool] = MISSING, + auto_archive_duration: Optional[int] = MISSING, + locked: Optional[bool] = MISSING, reason: Optional[str] = None, ) -> Channel: """ Edits a channel of the guild. + .. note:: + The fields `archived`, `auto_archive_duration` and `locked` require the provided channel to be a thread. + :param channel_id: The id of the channel to modify :type channel_id: int :param name?: The name of the channel, defaults to the current value of the channel @@ -791,7 +797,7 @@ async def modify_channel( :param topic?: The topic of that channel, defaults to the current value of the channel :type topic: Optional[str] :param bitrate?: (voice channel only) The bitrate (in bits) of the voice channel, defaults to the current value of the channel - :type bitrate Optional[int] + :type bitrate: Optional[int] :param user_limit?: (voice channel only) Maximum amount of users in the channel, defaults to the current value of the channel :type user_limit: Optional[int] :param rate_limit_per_use?: Amount of seconds a user has to wait before sending another message (0-21600), defaults to the current value of the channel @@ -804,6 +810,12 @@ async def modify_channel( :type permission_overwrites: Optional[Overwrite] :param nsfw?: Whether the channel is nsfw or not, defaults to the current value of the channel :type nsfw: Optional[bool] + :param archived?: Whether the thread is archived + :type archived: Optional[bool] + :param auto_archive_duration?: The time after the thread is automatically archived. One of 60, 1440, 4320, 10080 + :type auto_archive_duration: Optional[int] + :param locked?: Whether the thread is locked + :type locked: Optional[bool] :param reason: The reason for the edit :type reason: Optional[str] :return: The modified channel @@ -843,10 +855,24 @@ async def modify_channel( nsfw=_nsfw, ) + payload = payload._json + + if ( + archived is not MISSING or auto_archive_duration is not MISSING or locked is not MISSING + ) and not ch.thread_metadata: + raise ValueError("The specified channel is not a Thread!") + + if archived is not MISSING: + payload["archived"] = archived + if auto_archive_duration is not MISSING: + payload["auto_archive_duration"] = auto_archive_duration + if locked is not MISSING: + payload["locked"] = locked + res = await self._client.modify_channel( channel_id=channel_id, reason=reason, - payload=payload._json, + payload=payload, ) return Channel(**res, _client=self._client) @@ -1600,19 +1626,44 @@ async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Mem ) return [Member(**member, _client=self._client) for member in res] + async def get_all_members(self) -> List[Member]: + """ + Gets all members of a guild. + + .. warning:: Calling this method can lead to rate-limits in larger guilds. + + :return: Returns a list of all members of the guild + :rtype: List[Member] + """ + if not self._client: + raise AttributeError("HTTPClient not found!") + + _all_members: List[dict] = [] + _last_member: Member + _members: List[dict] = await self._client.get_list_of_members( + guild_id=int(self.id), limit=100 + ) + if len(_members) == 100: + while len(_members) >= 100: + _all_members.extend(_members) + _last_member = Member(**_members[-1]) + _members = await self._client.get_list_of_members( + guild_id=int(self.id), limit=100, after=int(_last_member.id) + ) + _all_members.extend(_members) + + return [Member(**_, _client=self._client) for _ in _all_members] + @property def icon_url(self) -> str: """ Returns the URL of the guild's icon. - :return: URL of the guild's icon (None will be returned if none of icon is set) :rtype: str """ if self.icon is not None: url = f"https://cdn.discordapp.com/icons/{int(self.id)}/{self.icon}" url += ".gif" if self.icon.startswith("a_") else ".png" - else: - url = None return url @@ -1911,4 +1962,4 @@ def __init__(self, **kwargs): self.entity_metadata = ( EventMetadata(**self.entity_metadata) if self._json.get("entity_metadata") else None ) - self.creator = User(**self.creator) if self._json.get("creator") else None + self.creator = User(**self.creator) if self._json.get("creator") else None \ No newline at end of file