Prevent role snowflakes from resolving roles with ids as names (#4983)

Fixes #4981.
This commit is contained in:
Josh Roy 2022-07-09 19:24:04 -04:00 committed by GitHub
parent 2bba577567
commit 4a53cfe7ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -120,6 +120,15 @@ public final class NumberUtil {
return Integer.parseInt(sInt) > 0;
}
public static boolean isNumeric(final String sNum) {
for (final char sChar : sNum.toCharArray()) {
if (!Character.isDigit(sChar)) {
return false;
}
}
return true;
}
/**
* Backport from Guava.
*/

View File

@ -5,6 +5,7 @@ import club.minnced.discord.webhook.WebhookClientBuilder;
import club.minnced.discord.webhook.send.AllowedMentions;
import com.earth2me.essentials.utils.DownsampleUtil;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.earth2me.essentials.utils.VersionUtil;
import com.google.common.collect.ImmutableList;
import net.dv8tion.jda.api.Permission;
@ -181,13 +182,14 @@ public final class DiscordUtil {
final List<Role> roles = member.getRoles();
for (String roleDefinition : roleDefinitions) {
roleDefinition = roleDefinition.trim();
final boolean id = NumberUtil.isNumeric(roleDefinition);
if (roleDefinition.equals("*") || member.getId().equals(roleDefinition)) {
return true;
}
for (final Role role : roles) {
if (role.getId().equals(roleDefinition) || role.getName().equalsIgnoreCase(roleDefinition)) {
if (role.getId().equals(roleDefinition) || (!id && role.getName().equalsIgnoreCase(roleDefinition))) {
return true;
}
}