Skip to content

Commit

Permalink
Remove Interaction#getUserPermissions
Browse files Browse the repository at this point in the history
This will be handled seamlessly when using the usual permission checks
  • Loading branch information
freya022 committed Mar 26, 2024
1 parent e544d33 commit 5bc36cb
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ public InteractionContextType getContext()
return interaction.getContext();
}

@Nonnull
@Override
public Set<Permission> getUserPermissions()
{
return interaction.getUserPermissions();
}

@Nonnull
@Override
public Set<Permission> getApplicationPermissions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,7 @@ default DiscordLocale getGuildLocale()
@Nullable
InteractionContextType getContext();

//TODO see ~ net/dv8tion/jda/internal/interactions/InteractionImpl.java:86
@Nonnull
Set<Permission> getUserPermissions();

//TODO see ~ net/dv8tion/jda/internal/interactions/InteractionImpl.java:86
//TODO document
@Nonnull
Set<Permission> getApplicationPermissions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class InteractionImpl implements Interaction
protected final DiscordLocale userLocale;
protected final InteractionContextType context;
protected final IntegrationOwners integrationOwners;
protected final Set<Permission> userPermissions, appPermissions;
protected final Set<Permission> appPermissions;
protected final JDAImpl api;

//This is used to give a proper error when an interaction is ack'd twice
Expand All @@ -79,16 +79,6 @@ public InteractionImpl(JDAImpl jda, DataObject data)
this.context = InteractionContextType.fromKey(data.getString("context"));
else
this.context = null;
//TODO The bot and user permissions could be added in the temporary GuildChannel
// Meaning that you can still use (Self)Member#hasPermission(GuildChannel, Permission...) transparently
// The drawback is that the user might see the permission overrides and think they have them (document it)
// The code calculating the effective/explicit permissions uses the guild, which doesn't exist
// The user might also mistakenly use (Self)Member#hasPermission(Permission...) which will give unexpected results,
// should it throw if the guild is unknown?
// PermissionUtil.getEffectivePermission/getExplicitPermission(Member) would throw if the guild is unknown
// While the overload using the channel would ignore unknown guilds as it can use the channel overrides
//TODO should the default value really be 0?
this.userPermissions = Collections.unmodifiableSet(Permission.getPermissions(data.getObject("channel").getLong("permissions", 0L)));
this.appPermissions = Collections.unmodifiableSet(Permission.getPermissions(data.getLong("app_permissions")));
this.integrationOwners = new IntegrationOwnersImpl(data.getObject("authorizing_integration_owners"));

Expand Down Expand Up @@ -205,13 +195,6 @@ public InteractionContextType getContext()
return context;
}

@Nonnull
@Override
public Set<Permission> getUserPermissions()
{
return userPermissions;
}

@Nonnull
@Override
public Set<Permission> getApplicationPermissions()
Expand Down

0 comments on commit 5bc36cb

Please sign in to comment.