interactions.py icon indicating copy to clipboard operation
interactions.py copied to clipboard

feat: add support for user-installable apps

Open AstreaTSS opened this issue 1 year ago • 4 comments

Pull Request Type

  • [x] Feature addition
  • [x] Bugfix (PR would not work without them)
  • [x] 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
  • [x] I've ensured my code works on Python 3.11.x

Checklist

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

AstreaTSS avatar Mar 30 '24 18:03 AstreaTSS

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'

Scrxtchy avatar Apr 23 '24 04:04 Scrxtchy

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

AstreaTSS avatar Apr 23 '24 04:04 AstreaTSS

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

AstreaTSS avatar Apr 23 '24 04:04 AstreaTSS

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

AstreaTSS avatar May 05 '24 03:05 AstreaTSS