🚑 Fix cache for stats
This commit is contained in:
parent
922c03f87c
commit
8dd6c760dc
@ -1,15 +1,30 @@
|
|||||||
package net.Broken.Tools;
|
package net.Broken.Tools;
|
||||||
|
|
||||||
|
import net.Broken.DB.Entity.UserEntity;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
|
import net.dv8tion.jda.api.entities.User;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CacheTools {
|
public class CacheTools {
|
||||||
public static void loadAllGuildMembers(){
|
private static Logger logger = LogManager.getLogger();
|
||||||
|
|
||||||
|
public static void loadAllGuildMembers() {
|
||||||
List<Guild> guilds = MainBot.jda.getGuilds();
|
List<Guild> guilds = MainBot.jda.getGuilds();
|
||||||
for(Guild guild : guilds){
|
for (Guild guild : guilds) {
|
||||||
guild.loadMembers().get();
|
guild.loadMembers().get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import net.Broken.DB.Repository.UserRepository;
|
|||||||
import net.Broken.DB.Repository.UserStatsRepository;
|
import net.Broken.DB.Repository.UserStatsRepository;
|
||||||
import net.Broken.MainBot;
|
import net.Broken.MainBot;
|
||||||
import net.Broken.SpringContext;
|
import net.Broken.SpringContext;
|
||||||
|
import net.Broken.Tools.CacheTools;
|
||||||
import net.Broken.Tools.EmbedMessageUtils;
|
import net.Broken.Tools.EmbedMessageUtils;
|
||||||
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
import net.Broken.Tools.UserManager.Exceptions.UnknownTokenException;
|
||||||
import net.Broken.Tools.UserManager.UserUtils;
|
import net.Broken.Tools.UserManager.UserUtils;
|
||||||
@ -58,7 +59,7 @@ public class UserStatsUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<UserStats> getUserStats(UserEntity userEntity) {
|
public List<UserStats> getUserStats(UserEntity userEntity) {
|
||||||
User jdaUser = MainBot.jda.getUserById(userEntity.getJdaId());
|
User jdaUser = CacheTools.getJdaUser(userEntity);
|
||||||
//TODO clean database for deleted users
|
//TODO clean database for deleted users
|
||||||
|
|
||||||
if (jdaUser == null){
|
if (jdaUser == null){
|
||||||
|
Loading…
Reference in New Issue
Block a user