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

feat: add support for user-installable apps #1647

Merged
merged 25 commits into from
Jun 8, 2024
Merged

feat: add support for user-installable apps #1647

merged 25 commits into from
Jun 8, 2024

Conversation

AstreaTSS
Copy link
Member

@AstreaTSS AstreaTSS commented Mar 30, 2024

Pull Request Type

  • Feature addition
  • Bugfix (PR would not work without them)
  • Documentation update
  • Code refactor
  • Tests improvement
  • CI/CD pipeline enhancement
  • Other: [Replace with a description]

Description

This PR adds support for user-installable applications, allowing developers to let users install the bot to themselves to use as they wish. This also adds many fields related to user-installable applications and fixes a few bugs out of necessity.

Changes

The scope of this PR is quite large, even with ta set scope in mind. That being said, here's a summary:

  • Add contexts and integration_types to InteractionCommand and its related decorators.
    • dm_permission has been depreciated and is no longer serialized - instead, it is converted to its contexts equivalent.
    • Hybrid commands also support these two fields, though for prefixed commands, it only attempts to mock contexts.
  • Add @contexts and @integration_types decorators to make specifying them easy.
    • This PR also adds two sections (replacing the old dm_permission section) to explain these two.
  • Add authorizing_integration_owners and context to BaseInteractionContext.
  • Add interaction_metadata to Message and note deprecation of interaction field.
  • Add integration_types_config to Application, although this is extremely basic.
  • Added other related fields and enums.

Possible things to consider:

  • Should @contexts be renamed to something else for clarity?
  • Should there be something like disable_dm_commands be added to Client for the new contexts and integration_types?

Related Issues

#1634

Test Scenarios

from interactions import contexts

@slash_command(name="my_guild_only_command")
@contexts(guild=True, bot_dm=False, private_channel=False)
async def my_command_function(ctx: SlashContext):
    ...
from interactions import integration_types

@slash_command(name="my_command")
@integration_types(guild=True, user=True)
async def my_command_function(ctx: SlashContext):
    ...

Python Compatibility

  • I've ensured my code works on Python 3.10.x
  • I've ensured my code works on Python 3.11.x

Checklist

  • I've run the pre-commit code linter over all edited files
  • I've tested my changes on supported Python versions
  • I've added tests for my code, if applicable
  • I've updated / added documentation, where applicable

@eightween eightween requested a review from silasary March 30, 2024 21:11
@eightween eightween added documentation Improvements or additions to documentation enhancement New feature or request pending Pending approve labels Mar 30, 2024
@eightween eightween linked an issue Mar 30, 2024 that may be closed by this pull request
1 task
@Scrxtchy
Copy link
Contributor

New error I'm getting as of today when responding to application commands
Doesn't happen on unstable, only userapps.
The command is responded to fine, but placing the item into the cache appears to be the problem.

Traceback (most recent call last):
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\client.py", line 1917, in __dispatch_interaction
    response = await callback
               ^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\client.py", line 1785, in _run_slash_command
    return await command(ctx, **ctx.kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\command.py", line 132, in __call__
    await self.call_callback(self.callback, context)
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\application_commands.py", line 841, in call_callback
    return await self.call_with_binding(callback, ctx)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\callback.py", line 44, in call_with_binding
    return await callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\bot-test.py", line 21, in idacUpdateRoles
    await ctx.send("update command issued", ephemeral=True)
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\internal\context.py", line 565, in send
    return await super().send(
           ^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\mixins\send.py", line 123, in send
    message = self.client.cache.place_message_data(message_data)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\client\smart_cache.py", line 436, in place_message_data
    message = Message.from_dict(data, self._client)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\discord\base.py", line 36, in from_dict
    data = cls._process_dict(data, client)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\discord\message.py", line 559, in _process_dict
    data["interaction_metadata"] = MessageInteractionMetadata.from_dict(data["interaction_metadata"], client)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Scratch\Documents\Git\June\Lib\site-packages\interactions\models\discord\base.py", line 37, in from_dict
    return cls(client=client, **cls._filter_kwargs(data, cls._get_init_keys()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: MessageInteractionMetadata.__init__() missing 1 required keyword-only argument: 'user_id'

@AstreaTSS
Copy link
Member Author

They changed the payload recently, yes. I'll fix it soon.

@AstreaTSS
Copy link
Member Author

AstreaTSS commented Apr 23, 2024

This PR, as well as the branch, has been rebased. The bug mentioned above should also be fixed.

@AstreaTSS
Copy link
Member Author

Another rebase has been done to match the branch closely with 5.12.0. It's unlikely that I'll do any more rebases.

Copy link
Member

@silasary silasary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ship it

@AstreaTSS AstreaTSS merged commit ecb9fca into unstable Jun 8, 2024
9 of 12 checks passed
@AstreaTSS AstreaTSS deleted the userapps branch June 8, 2024 02:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request pending Pending approve
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEAT] Add support for user-installable apps
5 participants