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

Add support for user-installable apps #2633

Open
wants to merge 74 commits into
base: master
Choose a base branch
from

Conversation

freya022
Copy link
Contributor

@freya022 freya022 commented Mar 22, 2024

Pull Request Etiquette

Changes

  • Internal code
  • Library interface (affecting end-user code)
  • Documentation
  • Other: _____

Closes Issue: NaN

Description

This adds support for user-installable apps (Preview, Release).

You are able to create application commands using the new properties, read the new data structures provided in ApplicationInfo, Interaction and Message, as well as responding to interactions in detached guilds (where your bot isn't it in) and group DMs.

Interesting elements include:

  • (Slash)CommandData#setContexts (Default: GUILD and BOT_DM)
  • (Slash)CommandData#setIntegrationTypes (Default: GUILD_INSTALL)
  • IDetachableEntity#isDetached (for Guild, Channel, Role, Member...)
  • Interaction#hasFullGuild
  • Interaction#getIntegrationOwners
  • Message#getInteractionMetadata

Note: The default contexts and integration types align with the current behavior, meaning there is no breaking change.

You can see examples here, you can also see the example changes in the Files changed tab.

Installation (Preview)

You can use the "Using new features" guide from the JDA wiki.

Alternatively, you can get the newest version for your favorite tool, by using the /jitpack pr command in the JDA Discord server. You can use the Update PR button to merge the latest changes if necessary (note that it may not update it if there are conflicts).

image

@freya022 freya022 force-pushed the feature/user-installable-apps branch from a55eba3 to 5bc36cb Compare March 26, 2024 11:02
@freya022 freya022 force-pushed the feature/user-installable-apps branch 3 times, most recently from 8bb9df6 to 34bae66 Compare April 11, 2024 20:35
@freya022 freya022 changed the title Add partial support for user-installable apps Add support for user-installable apps Apr 11, 2024
@freya022 freya022 force-pushed the feature/user-installable-apps branch from 7d78c12 to f2d4e9d Compare April 12, 2024 20:42
@freya022 freya022 marked this pull request as ready for review April 12, 2024 21:05
@freya022 freya022 force-pushed the feature/user-installable-apps branch from d2d8463 to a1a3954 Compare April 23, 2024 21:16
Copy link
Contributor

@Xirado Xirado left a comment

Choose a reason for hiding this comment

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

Looking quite good

@Ran-Mewo
Copy link

There seems to be a caching issue
If two different people use the same command in the same dm then all subsequent event.getUser() will return whoever used the command first.

@freya022 freya022 force-pushed the feature/user-installable-apps branch from c495b94 to 5488620 Compare May 18, 2024 16:20
@freya022
Copy link
Contributor Author

There seems to be a caching issue If two different people use the same command in the same dm then all subsequent event.getUser() will return whoever used the command first.

Should be fixed

@Ran-Mewo
Copy link

I am not sure if this is an issue on my code or the library
but updating attachments with editOriginalAttachments doesn't actually cause it to update unless you restart your discord

it's not an issue on my client as it also occurs for other people

@freya022
Copy link
Contributor Author

I am not sure if this is an issue on my code or the library but updating attachments with editOriginalAttachments doesn't actually cause it to update unless you restart your discord

it's not an issue on my client as it also occurs for other people

As you mentioned, restarting the client fixes the issue, so it's not a JDA issue

@Ran-Mewo
Copy link

Ran-Mewo commented May 26, 2024

I really doubt it's not a JDA issue, it works in other discord frameworks
Replying to an interaction using reply and then editing the original hook's attachments just doesn't work on JDA (well it does but discord doesn't update it)

sigh at this point I just give up, I have to resort to putting my image in an embed (by using .setImage("attachment://" + fileName))
I really hate how images in embeds get scaled down but that's a discord problem

the thing that annoys me the most is that it used to work, I don't know what changed nor do I know if it's something to do with your new changes

@freya022
Copy link
Contributor Author

Can't repro with the code below, please share minimal reproduction code if you can

public void onSlashReplyEditAttachment(SlashCommandInteractionEvent event, Message.Attachment attachment, Message.Attachment attachment2) throws Exception {
    final byte[] bytes = getBytes(attachment);
    final byte[] bytes2 = getBytes(attachment2);

    event.replyFiles(FileUpload.fromData(bytes, attachment.getFileName()))
            .setEphemeral(true) // Tried without ephemeral too
            .queue();

    event.getHook()
            .editOriginalAttachments(FileUpload.fromData(bytes2, attachment.getFileName()))
            .queue();
}

private byte[] getBytes(Message.Attachment attachment) throws Exception {
    try (InputStream stream = attachment.getProxy().download().get()) {
        return stream.readAllBytes();
    }
}

@ErfinderLabyrinth
Copy link

Maybe a UserJoinEvent(like GuildJoinEvent for userapps) and a JDA.getInstalledAppUsers()(like JDA.getGuilds() for userapps)

@freya022
Copy link
Contributor Author

Maybe a UserJoinEvent(like GuildJoinEvent for userapps) and a JDA.getInstalledAppUsers()(like JDA.getGuilds() for userapps)

Discord doesn't have a way to get who installed the application on their accounts

As a reminder, JDA adds what Discord documents, if it isn't in the Discord docs, we can't add it

@ErdbeerbaerLP
Copy link

I don't know if it's a limitation from Discord API, however, when trying to use
SlashCommandInteractionEvent#getGuild().getLocale() on a command ran as user-app, it always returns ENGLISH_US, even when the server is a community server set to another locale. Tested on small and large servers

@MrPowerGamerBR
Copy link
Contributor

I have been running this PR in production since 24/07 and I haven't found any issues, thanks freya! pets the freya

@freya022 freya022 force-pushed the feature/user-installable-apps branch from f5840da to e88cfad Compare November 4, 2024 10:51
KingRainbow44 added a commit to KingRainbow44/Complex-Command-Handler that referenced this pull request Nov 17, 2024
this is a PRERELEASE published on JitPack for 'discord-jda/JDA#2633'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants