From cc69d06586d32f77194824f51ae6d0e6b810ad21 Mon Sep 17 00:00:00 2001 From: Nan R Date: Wed, 18 May 2022 00:12:16 +0200 Subject: [PATCH 1/7] Add the things --- interactions/api/models/guild.py | 20 ++++++++++++++++++++ interactions/api/models/guild.pyi | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 3edadda1b..317759465 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -768,6 +768,26 @@ async def create_channel( return Channel(**res, _client=self._client) + async def clone_channel( + self, + channel_id: int + ) -> Channel: + """ + Clones a channel of the guild. + + :param channel_id: The id of the channel to clone + :type channel_id: int + """ + if not self._client: + raise AttributeError("HTTPClient not found!") + ch = Channel(**await self._client.get_channel(channel_id=channel_id)) + + ch._json["permission_overwrites"] = [Overwrite(**_) for _ in ch._json["permission_overwrites"]] + [ch._json.pop(attr, None) for attr in {"flags", "last_pin_timestamp", "guild_id", "id", "last_message_id"}] + + return await self.create_channel(**ch._json) + + async def modify_channel( self, channel_id: int, diff --git a/interactions/api/models/guild.pyi b/interactions/api/models/guild.pyi index e9108a6cc..9b6c6083a 100644 --- a/interactions/api/models/guild.pyi +++ b/interactions/api/models/guild.pyi @@ -224,6 +224,10 @@ class Guild(DictSerializerMixin): nsfw: Optional[bool] = MISSING, reason: Optional[str] = None, ) -> Channel: ... + async def clone_channel( + self, + channel_id: int + ) -> Channel: ... async def modify_channel( self, channel_id: int, From ec9beb5fd0ba79304104869afa5d5d89c28403e8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 May 2022 22:16:59 +0000 Subject: [PATCH 2/7] ci: correct from checks. --- interactions/api/models/guild.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 317759465..15f4f01fe 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -768,10 +768,7 @@ async def create_channel( return Channel(**res, _client=self._client) - async def clone_channel( - self, - channel_id: int - ) -> Channel: + async def clone_channel(self, channel_id: int) -> Channel: """ Clones a channel of the guild. @@ -782,12 +779,16 @@ async def clone_channel( raise AttributeError("HTTPClient not found!") ch = Channel(**await self._client.get_channel(channel_id=channel_id)) - ch._json["permission_overwrites"] = [Overwrite(**_) for _ in ch._json["permission_overwrites"]] - [ch._json.pop(attr, None) for attr in {"flags", "last_pin_timestamp", "guild_id", "id", "last_message_id"}] + ch._json["permission_overwrites"] = [ + Overwrite(**_) for _ in ch._json["permission_overwrites"] + ] + [ + ch._json.pop(attr, None) + for attr in {"flags", "last_pin_timestamp", "guild_id", "id", "last_message_id"} + ] return await self.create_channel(**ch._json) - async def modify_channel( self, channel_id: int, From be5570846277f767ce32c713702935f0d83514e2 Mon Sep 17 00:00:00 2001 From: Nan R Date: Wed, 18 May 2022 00:27:31 +0200 Subject: [PATCH 3/7] Fix return in docstrings --- 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 317759465..02cc755bd 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -777,6 +777,8 @@ async def clone_channel( :param channel_id: The id of the channel to clone :type channel_id: int + :return: The created (cloned) channel + :rtype: Channel """ if not self._client: raise AttributeError("HTTPClient not found!") From e12c4a80800699d530afab79e5f7cd61f5216c15 Mon Sep 17 00:00:00 2001 From: Nan R Date: Wed, 18 May 2022 00:33:47 +0200 Subject: [PATCH 4/7] Remove redundancy --- interactions/api/models/guild.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 3de4f0de2..6c94f6a0a 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -779,17 +779,17 @@ async def clone_channel(self, channel_id: int) -> Channel: """ if not self._client: raise AttributeError("HTTPClient not found!") - ch = Channel(**await self._client.get_channel(channel_id=channel_id)) + res = await self._client.get_channel(channel_id=channel_id) - ch._json["permission_overwrites"] = [ - Overwrite(**_) for _ in ch._json["permission_overwrites"] + res["permission_overwrites"] = [ + Overwrite(**_) for _ in res["permission_overwrites"] ] [ - ch._json.pop(attr, None) + res.pop(attr, None) for attr in {"flags", "last_pin_timestamp", "guild_id", "id", "last_message_id"} ] - return await self.create_channel(**ch._json) + return await self.create_channel(**res) async def modify_channel( self, From bd30e3100d74b98553442a097d160df6627626f1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 17 May 2022 22:34:04 +0000 Subject: [PATCH 5/7] ci: correct from checks. --- interactions/api/models/guild.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 6c94f6a0a..f0bc6696e 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -781,9 +781,7 @@ async def clone_channel(self, channel_id: int) -> Channel: raise AttributeError("HTTPClient not found!") res = await self._client.get_channel(channel_id=channel_id) - res["permission_overwrites"] = [ - Overwrite(**_) for _ in res["permission_overwrites"] - ] + res["permission_overwrites"] = [Overwrite(**_) for _ in res["permission_overwrites"]] [ res.pop(attr, None) for attr in {"flags", "last_pin_timestamp", "guild_id", "id", "last_message_id"} From 85199738f3b4f3cf236091194292746af02bcc73 Mon Sep 17 00:00:00 2001 From: Nan R <88463477+Nanrech@users.noreply.github.com> Date: Wed, 18 May 2022 09:43:34 +0200 Subject: [PATCH 6/7] Update interactions/api/models/guild.py Co-authored-by: Toricane <73972068+Toricane@users.noreply.github.com> --- interactions/api/models/guild.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index f0bc6696e..7362d8214 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -782,10 +782,8 @@ async def clone_channel(self, channel_id: int) -> Channel: res = await self._client.get_channel(channel_id=channel_id) res["permission_overwrites"] = [Overwrite(**_) for _ in res["permission_overwrites"]] - [ + for attr in {"flags", "guild_id", "id", "last_message_id", "last_pin_timestamp"}: res.pop(attr, None) - for attr in {"flags", "last_pin_timestamp", "guild_id", "id", "last_message_id"} - ] return await self.create_channel(**res) From 4f0bfa9fc80f4160331ad2182bf9e6e86a4c7888 Mon Sep 17 00:00:00 2001 From: Toricane <73972068+Toricane@users.noreply.github.com> Date: Mon, 23 May 2022 14:39:48 -0700 Subject: [PATCH 7/7] Update interactions/api/models/guild.py --- 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 7362d8214..2f211de7e 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -774,7 +774,7 @@ async def clone_channel(self, channel_id: int) -> Channel: :param channel_id: The id of the channel to clone :type channel_id: int - :return: The created (cloned) channel + :return: The cloned channel :rtype: Channel """ if not self._client: