From 07a1ccf421314e4cd0cca21015b6e7a4201eed57 Mon Sep 17 00:00:00 2001 From: EdVraz <88881326+EdVraz@users.noreply.github.com> Date: Thu, 10 Mar 2022 19:22:49 +0100 Subject: [PATCH 1/5] refactor: modify self when editing its object --- interactions/api/models/channel.py | 4 +++- interactions/api/models/guild.py | 4 +++- interactions/api/models/member.py | 4 +++- interactions/api/models/message.py | 7 ++++++- interactions/api/models/role.py | 4 +++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/interactions/api/models/channel.py b/interactions/api/models/channel.py index 53dae9a50..46640bb36 100644 --- a/interactions/api/models/channel.py +++ b/interactions/api/models/channel.py @@ -337,7 +337,9 @@ async def modify( reason=reason, data=payload._json, ) - return Channel(**res, _client=self._client) + ch = Channel(**res, _client=self._client) + self = ch + return ch async def set_name( self, diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index d1d5b2d82..93c1127f5 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1040,7 +1040,9 @@ async def modify( payload=payload, reason=reason, ) - return Guild(**res, _client=self._client) + guild = Guild(**res, _client=self._client) + self = guild + return guild async def set_name( self, diff --git a/interactions/api/models/member.py b/interactions/api/models/member.py index d03054b6a..2258520b5 100644 --- a/interactions/api/models/member.py +++ b/interactions/api/models/member.py @@ -343,7 +343,9 @@ async def modify( payload=payload, reason=reason, ) - return Member(**res, _client=self._client) + member = Member(**res, _client=self._client) + self = member + return member async def add_to_thread( self, diff --git a/interactions/api/models/message.py b/interactions/api/models/message.py index 529e6bb32..35ded0292 100644 --- a/interactions/api/models/message.py +++ b/interactions/api/models/message.py @@ -415,7 +415,12 @@ async def edit( payload=payload._json, ) - return Message(**_dct) if not _dct.get("code") else payload + msg = Message(**_dct) if not _dct.get("code") else payload + + if isinstance(msg, Message): + self = msg + + return msg async def reply( self, diff --git a/interactions/api/models/role.py b/interactions/api/models/role.py index f34d1ba51..5285c9e39 100644 --- a/interactions/api/models/role.py +++ b/interactions/api/models/role.py @@ -137,7 +137,9 @@ async def modify( data=payload._json, reason=reason, ) - return Role(**res, _client=self._client) + role = Role(**res, _client=self._client) + self = role + return role async def modify_position( self, From e0b4741d5de93147a5fc75c76355bbf674cb7531 Mon Sep 17 00:00:00 2001 From: EdVraz <88881326+EdVraz@users.noreply.github.com> Date: Thu, 10 Mar 2022 19:41:41 +0100 Subject: [PATCH 2/5] refactor: modify class instance when editing it and fix me being naive --- interactions/api/models/channel.py | 5 ++++- interactions/api/models/guild.py | 5 ++++- interactions/api/models/member.py | 5 ++++- interactions/api/models/message.py | 4 ++-- interactions/api/models/role.py | 5 ++++- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/interactions/api/models/channel.py b/interactions/api/models/channel.py index 46640bb36..9546aef9d 100644 --- a/interactions/api/models/channel.py +++ b/interactions/api/models/channel.py @@ -338,7 +338,10 @@ async def modify( data=payload._json, ) ch = Channel(**res, _client=self._client) - self = ch + + for attr in self.__slots__: + setattr(self, attr, getattr(ch, attr)) + return ch async def set_name( diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 93c1127f5..82f63ebb9 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1041,7 +1041,10 @@ async def modify( reason=reason, ) guild = Guild(**res, _client=self._client) - self = guild + + for attr in self.__slots__: + setattr(self, attr, getattr(guild, attr)) + return guild async def set_name( diff --git a/interactions/api/models/member.py b/interactions/api/models/member.py index 2258520b5..c8357877a 100644 --- a/interactions/api/models/member.py +++ b/interactions/api/models/member.py @@ -344,7 +344,10 @@ async def modify( reason=reason, ) member = Member(**res, _client=self._client) - self = member + + for attr in self.__slots__: + setattr(self, attr, getattr(member, attr)) + return member async def add_to_thread( diff --git a/interactions/api/models/message.py b/interactions/api/models/message.py index 35ded0292..80a382560 100644 --- a/interactions/api/models/message.py +++ b/interactions/api/models/message.py @@ -417,8 +417,8 @@ async def edit( msg = Message(**_dct) if not _dct.get("code") else payload - if isinstance(msg, Message): - self = msg + for attr in self.__slots__: + setattr(self, attr, getattr(msg, attr)) return msg diff --git a/interactions/api/models/role.py b/interactions/api/models/role.py index 5285c9e39..6a8ac3a3c 100644 --- a/interactions/api/models/role.py +++ b/interactions/api/models/role.py @@ -138,7 +138,10 @@ async def modify( reason=reason, ) role = Role(**res, _client=self._client) - self = role + + for attr in self.__slots__: + setattr(self, attr, getattr(role, attr)) + return role async def modify_position( From aaee13229f658250dcfa6e6054ee4afa91bcff92 Mon Sep 17 00:00:00 2001 From: EdVraz <88881326+EdVraz@users.noreply.github.com> Date: Thu, 10 Mar 2022 19:55:09 +0100 Subject: [PATCH 3/5] fix!: typo --- 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 82f63ebb9..11a375357 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1503,7 +1503,7 @@ async def get_emoji( res = await self._client.get_guild_emoji(guild_id=int(self.id), emoji_id=emoji_id) return Emoji(**res, _client=self._client) - async def get_all_emojis(self) -> List[Emoji]: + async def get_all_emoji(self) -> List[Emoji]: """ Gets all emojis of a guild. From 75383cb9de67452b04207fe3e72d5f4cb3ddba1b Mon Sep 17 00:00:00 2001 From: EdVraz <88881326+EdVraz@users.noreply.github.com> Date: Sun, 20 Mar 2022 20:32:39 +0100 Subject: [PATCH 4/5] Update channel.py --- interactions/api/models/channel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/api/models/channel.py b/interactions/api/models/channel.py index 9546aef9d..94e36f25f 100644 --- a/interactions/api/models/channel.py +++ b/interactions/api/models/channel.py @@ -17,7 +17,7 @@ class ChannelType(IntEnum): GUILD_STORE = 6 GUILD_NEWS_THREAD = 10 GUILD_PUBLIC_THREAD = 11 - GUILD_PRIVATE_THREAD = 12 + GUILD_PRIVATE_THREAD = 12 GUILD_STAGE_VOICE = 13 From 5ef459220c3b5b8453a831eacdd2092a06ff24cf Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 20 Mar 2022 19:32:50 +0000 Subject: [PATCH 5/5] ci: correct from checks. --- interactions/api/models/channel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interactions/api/models/channel.py b/interactions/api/models/channel.py index 94e36f25f..9546aef9d 100644 --- a/interactions/api/models/channel.py +++ b/interactions/api/models/channel.py @@ -17,7 +17,7 @@ class ChannelType(IntEnum): GUILD_STORE = 6 GUILD_NEWS_THREAD = 10 GUILD_PUBLIC_THREAD = 11 - GUILD_PRIVATE_THREAD = 12 + GUILD_PRIVATE_THREAD = 12 GUILD_STAGE_VOICE = 13