Skip to content

Commit

Permalink
Expose all check steps, rename some
Browse files Browse the repository at this point in the history
  • Loading branch information
freya022 committed Nov 15, 2024
1 parent c5512ce commit 4f6ce2f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
return false;
}
else
return isAppAllowedInAllChannels(config, channel, member, command);
return isAllowedInAllChannels(config, channel, member, command);
}

private static boolean isAppAllowedInAllChannels(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
public static boolean isAllowedInAllChannels(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
{
final IntegrationPrivilege appChannelPermissions = findPrivilege(config.getApplicationPrivileges(), IntegrationPrivilege::targetsAllChannels);
if (appChannelPermissions != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,34 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
{
if (appUserPermissions.isEnabled())
return DefaultMemberPermissionsChecks.canMemberRun(channel, member, command);
return false;
}
else
{
// If there's a role override, then at least one needs to be enabled
// If there's no role override, check @everyone
final List<IntegrationPrivilege> commandRolePermissionList = member.getRoles().stream()
.map(r -> findPrivilege(applicationPrivileges, matchingRole(r)))
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (commandRolePermissionList.isEmpty())
return isAppAllowingEveryone(config, channel, member, command);
return hasAtLeastOneConfiguredRole(config, channel, member, command);
}
}

for (IntegrationPrivilege integrationPrivilege : commandRolePermissionList)
{
if (integrationPrivilege.isEnabled())
return DefaultMemberPermissionsChecks.canMemberRun(channel, member, command);
}
public static boolean hasAtLeastOneConfiguredRole(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
{
// If there's a role override, then at least one needs to be enabled
// If there's no role override, check @everyone
final List<IntegrationPrivilege> commandRolePermissionList = member.getRoles().stream()
.map(r -> findPrivilege(config.getApplicationPrivileges(), matchingRole(r)))
.filter(Objects::nonNull)
.collect(Collectors.toList());
if (commandRolePermissionList.isEmpty())
return isEveryoneAllowed(config, channel, member, command);

for (IntegrationPrivilege integrationPrivilege : commandRolePermissionList)
{
if (integrationPrivilege.isEnabled())
return DefaultMemberPermissionsChecks.canMemberRun(channel, member, command);
}
return false;
}

private static boolean isAppAllowingEveryone(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
public static boolean isEveryoneAllowed(PrivilegeConfig config, GuildChannel channel, Member member, Command command)
{
final IntegrationPrivilege commandEveryonePermissions = findPrivilege(config.getApplicationPrivileges(), matchingRole(channel.getGuild().getPublicRole()));
if (commandEveryonePermissions != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
return CommandLevelUserOrRolePermissionChecks.canMemberRun(config, channel, member, command);
}
else
return isCommandAllowedInAllChannels(config, channel, member, command);
return isAllowedInAllChannels(config, channel, member, command);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public static boolean canMemberRun(PrivilegeConfig config, GuildChannel channel,
if (commandUserPermissions != null)
return commandUserPermissions.isEnabled();
else
return commandAtLeastOneRole(config, channel, member, command);
return hasAtLeastOneConfiguredRole(config, channel, member, command);
}

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

for (IntegrationPrivilege integrationPrivilege : commandRolePermissionList)
{
Expand All @@ -58,7 +58,7 @@ private static boolean commandAtLeastOneRole(PrivilegeConfig config, GuildChanne
return false;
}

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

0 comments on commit 4f6ce2f

Please sign in to comment.