ClaptrapBot/src/main/java/net/Broken/Tools/CacheTools.java

31 lines
944 B
Java
Raw Normal View History

package net.Broken.Tools;
2020-11-23 14:29:44 +01:00
import net.Broken.DB.Entity.UserEntity;
import net.Broken.MainBot;
import net.dv8tion.jda.api.entities.Guild;
2020-11-23 14:29:44 +01:00
import net.dv8tion.jda.api.entities.User;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List;
public class CacheTools {
2020-11-23 14:29:44 +01:00
private static Logger logger = LogManager.getLogger();
public static void loadAllGuildMembers() {
List<Guild> guilds = MainBot.jda.getGuilds();
2020-11-23 14:29:44 +01:00
for (Guild guild : guilds) {
guild.loadMembers().get();
}
}
2020-11-23 14:29:44 +01:00
public static User getJdaUser(UserEntity userEntity) {
User user = MainBot.jda.getUserById(userEntity.getJdaId());
if (user == null) {
logger.debug("User cache not found for " + userEntity.getName() + ", fetching user.");
user = MainBot.jda.retrieveUserById(userEntity.getJdaId()).complete();
}
return user;
}
}