Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose all check steps, rename some
Browse files Browse the repository at this point in the history
freya022 committed Nov 15, 2024

Verified

This commit was signed with the committer’s verified signature.
freya022 freya02
1 parent c5512ce commit 4f6ce2f
Showing 4 changed files with 28 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -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);

Original file line number Diff line number Diff line change
@@ -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
@@ -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)
{
@@ -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)

0 comments on commit 4f6ce2f

Please sign in to comment.