This should also fix some more errors with getting users/roles

This commit is contained in:
NovaFox161
2020-05-05 19:59:59 -05:00
parent b2075210c4
commit 48c34263a1
3 changed files with 23 additions and 7 deletions
@@ -21,6 +21,14 @@ public class RoleUtils {
.next();
}
public static Mono<Role> getRoleFromID(String id, Guild guild) {
return Mono.just(id)
.filter(s -> !s.isEmpty())
.filter(s -> s.matches("[0-9]+"))
.flatMap(s -> guild.getRoleById(Snowflake.of(id))
.onErrorResume(e -> Mono.empty()));
}
public static Mono<Boolean> roleExists(String id, MessageCreateEvent event) {
return getRoleFromID(id, event).hasElement();
}
@@ -27,6 +27,9 @@ public class UserUtils {
}
public static Mono<Member> getUser(String toLookFor, Guild guild) {
if (toLookFor.isEmpty())
return Mono.empty();
toLookFor = GeneralUtils.trim(toLookFor);
final String lower = toLookFor.toLowerCase();
if (lower.matches("@!?[0-9]+") || lower.matches("[0-9]+")) {
@@ -47,9 +50,12 @@ public class UserUtils {
.onErrorResume(e -> Mono.empty()); //User not found, we don't care about the error in this case.
}
private static Mono<Member> getUserFromID(String id, Guild guild) {
return guild.getMemberById(Snowflake.of(id))
.onErrorResume(e -> Mono.empty());
public static Mono<Member> getUserFromID(String id, Guild guild) {
return Mono.just(id)
.filter(s -> !s.isEmpty())
.filter(s -> s.matches("[0-9]+"))
.flatMap(s -> guild.getMemberById(Snowflake.of(s))
.onErrorResume(e -> Mono.empty()));
}
public static Mono<List<Member>> getUsers(ArrayList<String> userIds, Guild guild) {