Skip to content

Commit 4f6ce2f

Browse files
committed
Expose all check steps, rename some
1 parent c5512ce commit 4f6ce2f

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

src/main/java/net/dv8tion/jda/internal/utils/interactions/commands/AppLevelChannelPermissionChecks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
3737
return false;
3838
}
3939
else
40-
return isAppAllowedInAllChannels(config, channel, member, command);
40+
return isAllowedInAllChannels(config, channel, member, command);
4141
}
4242

43-
private static boolean isAppAllowedInAllChannels(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
43+
public static boolean isAllowedInAllChannels(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
4444
{
4545
final IntegrationPrivilege appChannelPermissions = findPrivilege(config.getApplicationPrivileges(), IntegrationPrivilege::targetsAllChannels);
4646
if (appChannelPermissions != null)

src/main/java/net/dv8tion/jda/internal/utils/interactions/commands/AppLevelUserOrRolePermissionChecks.java

+20-14
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,34 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
3838
{
3939
if (appUserPermissions.isEnabled())
4040
return DefaultMemberPermissionsChecks.canMemberRun(channel, member, command);
41+
return false;
4142
}
4243
else
4344
{
44-
// If there's a role override, then at least one needs to be enabled
45-
// If there's no role override, check @everyone
46-
final List<IntegrationPrivilege> commandRolePermissionList = member.getRoles().stream()
47-
.map(r -> findPrivilege(applicationPrivileges, matchingRole(r)))
48-
.filter(Objects::nonNull)
49-
.collect(Collectors.toList());
50-
if (commandRolePermissionList.isEmpty())
51-
return isAppAllowingEveryone(config, channel, member, command);
45+
return hasAtLeastOneConfiguredRole(config, channel, member, command);
46+
}
47+
}
5248

53-
for (IntegrationPrivilege integrationPrivilege : commandRolePermissionList)
54-
{
55-
if (integrationPrivilege.isEnabled())
56-
return DefaultMemberPermissionsChecks.canMemberRun(channel, member, command);
57-
}
49+
public static boolean hasAtLeastOneConfiguredRole(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
50+
{
51+
// If there's a role override, then at least one needs to be enabled
52+
// If there's no role override, check @everyone
53+
final List<IntegrationPrivilege> commandRolePermissionList = member.getRoles().stream()
54+
.map(r -> findPrivilege(config.getApplicationPrivileges(), matchingRole(r)))
55+
.filter(Objects::nonNull)
56+
.collect(Collectors.toList());
57+
if (commandRolePermissionList.isEmpty())
58+
return isEveryoneAllowed(config, channel, member, command);
59+
60+
for (IntegrationPrivilege integrationPrivilege : commandRolePermissionList)
61+
{
62+
if (integrationPrivilege.isEnabled())
63+
return DefaultMemberPermissionsChecks.canMemberRun(channel, member, command);
5864
}
5965
return false;
6066
}
6167

62-
private static boolean isAppAllowingEveryone(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
68+
public static boolean isEveryoneAllowed(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
6369
{
6470
final IntegrationPrivilege commandEveryonePermissions = findPrivilege(config.getApplicationPrivileges(), matchingRole(channel.getGuild().getPublicRole()));
6571
if (commandEveryonePermissions != null)

src/main/java/net/dv8tion/jda/internal/utils/interactions/commands/CommandLevelChannelPermissionChecks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
3737
return CommandLevelUserOrRolePermissionChecks.canMemberRun(config, channel, member, command);
3838
}
3939
else
40-
return isCommandAllowedInAllChannels(config, channel, member, command);
40+
return isAllowedInAllChannels(config, channel, member, command);
4141
}
4242

43-
private static boolean isCommandAllowedInAllChannels(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
43+
public static boolean isAllowedInAllChannels(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
4444
{
4545
final IntegrationPrivilege commandAllChannelsPermissions = findPrivilege(config.getCommandPrivileges(command), IntegrationPrivilege::targetsAllChannels);
4646

src/main/java/net/dv8tion/jda/internal/utils/interactions/commands/CommandLevelUserOrRolePermissionChecks.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
3636
if (commandUserPermissions != null)
3737
return commandUserPermissions.isEnabled();
3838
else
39-
return commandAtLeastOneRole(config, channel, member, command);
39+
return hasAtLeastOneConfiguredRole(config, channel, member, command);
4040
}
4141

42-
private static boolean commandAtLeastOneRole(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
42+
public static boolean hasAtLeastOneConfiguredRole(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
4343
{
4444
// If there's a role override, then at least one needs to be enabled
4545
// If there's no role override, check @everyone
@@ -48,7 +48,7 @@ private static boolean commandAtLeastOneRole(PrivilegeConfig config, GuildChanne
4848
.filter(Objects::nonNull)
4949
.collect(Collectors.toList());
5050
if (commandRolePermissionList.isEmpty())
51-
return commandEveryonePermission(config, channel, member, command);
51+
return isEveryoneAllowed(config, channel, member, command);
5252

5353
for (IntegrationPrivilege integrationPrivilege : commandRolePermissionList)
5454
{
@@ -58,7 +58,7 @@ private static boolean commandAtLeastOneRole(PrivilegeConfig config, GuildChanne
5858
return false;
5959
}
6060

61-
private static boolean commandEveryonePermission(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
61+
public static boolean isEveryoneAllowed(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
6262
{
6363
final IntegrationPrivilege commandEveryonePermissions = findPrivilege(config.getCommandPrivileges(command), matchingRole(channel.getGuild().getPublicRole()));
6464
if (commandEveryonePermissions != null)

0 commit comments

Comments
 (0)