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

Implement interaction.data.guild_id for command interactions #1930

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions changes/1930.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `registered_guild_id` field to `BaseCommandInteraction`
2 changes: 2 additions & 0 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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", ())],
)

Expand Down
3 changes: 3 additions & 0 deletions hikari/interactions/command_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
7 changes: 7 additions & 0 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand All @@ -4560,6 +4565,7 @@ def autocomplete_interaction_payload(self, member_payload, user_payload, interac
],
}
],
"guild_id": 12345678,
},
"channel_id": "49949494",
"user": user_payload,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/hikari/interactions/test_command_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
Loading