From 99499d1371b241f7652cea14c0e077638c8d88be Mon Sep 17 00:00:00 2001 From: "thomm.o" Date: Tue, 28 May 2024 12:26:55 +0100 Subject: [PATCH 1/2] Implement interaction.data.guild_id as 'registered_guild_id' field for command interactions --- hikari/impl/entity_factory.py | 2 ++ hikari/interactions/command_interactions.py | 3 +++ tests/hikari/impl/test_entity_factory.py | 7 +++++++ tests/hikari/interactions/test_command_interactions.py | 2 ++ 4 files changed, 14 insertions(+) diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index e52c206153..409c3920ba 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -2579,6 +2579,7 @@ def deserialize_command_interaction( resolved=resolved, target_id=target_id, app_permissions=permission_models.Permissions(app_perms) if app_perms else None, + registered_guild_id=snowflakes.Snowflake(data_payload["guild_id"]) if "guild_id" in data_payload else None, entitlements=entitlements, ) @@ -2621,6 +2622,7 @@ def deserialize_autocomplete_interaction( options=options, locale=locales.Locale(payload["locale"]), guild_locale=locales.Locale(payload["guild_locale"]) if "guild_locale" in payload else None, + registered_guild_id=snowflakes.Snowflake(data_payload["guild_id"]) if "guild_id" in data_payload else None, entitlements=[self.deserialize_entitlement(entitlement) for entitlement in payload.get("entitlements", ())], ) diff --git a/hikari/interactions/command_interactions.py b/hikari/interactions/command_interactions.py index cbfb1a7a12..32cda9e8ef 100644 --- a/hikari/interactions/command_interactions.py +++ b/hikari/interactions/command_interactions.py @@ -181,6 +181,9 @@ class BaseCommandInteraction(base_interactions.PartialInteraction): command_type: typing.Union[commands.CommandType, int] = attrs.field(eq=False, hash=False, repr=True) """The type of the command.""" + registered_guild_id: typing.Optional[snowflakes.Snowflake] = attrs.field(eq=False, hash=False, repr=True) + """ID of the guild the command is registered to.""" + entitlements: typing.Sequence[monetization.Entitlement] = attrs.field(eq=False, hash=False, repr=True) """For monetized apps, any entitlements for the invoking user, represents access to SKUs.""" diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py index 35a9be678e..e5038f9d2f 100644 --- a/tests/hikari/impl/test_entity_factory.py +++ b/tests/hikari/impl/test_entity_factory.py @@ -4388,6 +4388,7 @@ def command_interaction_payload(self, interaction_member_payload, interaction_re ], } ], + "guild_id": "12345678", "resolved": interaction_resolved_data_payload, }, "channel_id": "49949494", @@ -4447,6 +4448,7 @@ def test_deserialize_command_interaction( assert interaction.app_permissions == 54123 assert len(interaction.entitlements) == 1 assert interaction.entitlements[0].id == 696969696969696 + assert interaction.registered_guild_id == 12345678 # CommandInteractionOption assert len(interaction.options) == 1 @@ -4486,6 +4488,7 @@ def context_menu_command_interaction_payload(self, interaction_member_payload, u "type": 2, "target_id": "115590097100865541", "resolved": {"users": {"115590097100865541": user_payload}}, + "guild_id": 12345678, }, "channel_id": "49949494", "member": interaction_member_payload, @@ -4528,6 +4531,7 @@ def test_deserialize_command_interaction_with_null_attributes( del command_interaction_payload["data"]["options"] del command_interaction_payload["guild_locale"] del command_interaction_payload["app_permissions"] + del command_interaction_payload["data"]["guild_id"] interaction = entity_factory_impl.deserialize_command_interaction(command_interaction_payload) @@ -4538,6 +4542,7 @@ def test_deserialize_command_interaction_with_null_attributes( assert interaction.resolved is None assert interaction.guild_locale is None assert interaction.app_permissions is None + assert interaction.registered_guild_id is None @pytest.fixture def autocomplete_interaction_payload(self, member_payload, user_payload, interaction_resolved_data_payload): @@ -4560,6 +4565,7 @@ def autocomplete_interaction_payload(self, member_payload, user_payload, interac ], } ], + "guild_id": 12345678, }, "channel_id": "49949494", "user": user_payload, @@ -4608,6 +4614,7 @@ def test_deserialize_autocomplete_interaction( entity_factory_impl._deserialize_interaction_member.assert_called_once_with(member_payload, guild_id=43123123) assert interaction.locale is locales.Locale.ES_ES assert interaction.guild_locale is locales.Locale.EN_US + assert interaction.registered_guild_id == 12345678 # AutocompleteInteractionOption assert len(interaction.options) == 1 diff --git a/tests/hikari/interactions/test_command_interactions.py b/tests/hikari/interactions/test_command_interactions.py index 010e652c77..874ca33491 100644 --- a/tests/hikari/interactions/test_command_interactions.py +++ b/tests/hikari/interactions/test_command_interactions.py @@ -58,6 +58,7 @@ def mock_command_interaction(self, mock_app): locale="es-ES", guild_locale="en-US", app_permissions=543123, + registered_guild_id=snowflakes.Snowflake(12345678), entitlements=[ monetization.Entitlement( id=snowflakes.Snowflake(123123), @@ -135,6 +136,7 @@ def mock_autocomplete_interaction(self, mock_app): command_name="OKOKOK", command_type=1, options=[], + registered_guild_id=snowflakes.Snowflake(12345678), entitlements=[ monetization.Entitlement( id=snowflakes.Snowflake(123123), From 238b51cab2338e3a9c64a46a7ff0ec243c970c9a Mon Sep 17 00:00:00 2001 From: "thomm.o" Date: Tue, 28 May 2024 15:04:59 +0100 Subject: [PATCH 2/2] Add fragment --- changes/1930.feature.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/1930.feature.md diff --git a/changes/1930.feature.md b/changes/1930.feature.md new file mode 100644 index 0000000000..26e1a6c30a --- /dev/null +++ b/changes/1930.feature.md @@ -0,0 +1 @@ +Add `registered_guild_id` field to `BaseCommandInteraction`