All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 40s
46 lines
1.2 KiB
Java
46 lines
1.2 KiB
Java
package cc.fascinated.bat.common;
|
|
|
|
import cc.fascinated.bat.service.DiscordService;
|
|
import lombok.experimental.UtilityClass;
|
|
import lombok.extern.log4j.Log4j2;
|
|
import net.dv8tion.jda.api.entities.User;
|
|
|
|
/**
|
|
* @author Fascinated (fascinated7)
|
|
*/
|
|
@UtilityClass
|
|
@Log4j2
|
|
public class UserUtils {
|
|
/**
|
|
* Gets the user with the given id
|
|
*
|
|
* @param id the id of the user
|
|
* @param retries the amount of retries
|
|
* @return the user with the given id
|
|
*/
|
|
private static User getUser(String id, int retries) {
|
|
if (retries >= 25) {
|
|
log.error("Failed to find user \"{}\" after {} retries.", id, retries);
|
|
return null;
|
|
}
|
|
User user = DiscordService.JDA.getUserById(id);
|
|
if (user == null) {
|
|
return getUser(id, retries + 1);
|
|
}
|
|
if (retries >= 5) {
|
|
log.info("Found user \"{}\" after {} retries.", user.getGlobalName(), retries);
|
|
}
|
|
return user;
|
|
}
|
|
|
|
/**
|
|
* Gets the user with the given id
|
|
*
|
|
* @param id the id of the user
|
|
* @return the user with the given id
|
|
*/
|
|
public static User getUser(String id) {
|
|
return getUser(id, 0);
|
|
}
|
|
}
|