Add some debug logs

This commit is contained in:
Sebastien 2020-04-12 15:01:39 +02:00
parent 5e1feded79
commit 9419169f4e

View File

@ -31,7 +31,6 @@ public class UserStatsUtils {
static double XP_PER_API_COUNT = 1;
private static UserStatsUtils INSTANCE = new UserStatsUtils();
public static UserStatsUtils getINSTANCE() {
@ -50,7 +49,6 @@ public class UserStatsUtils {
private Logger logger = LogManager.getLogger();
private UserStatsUtils() {
ApplicationContext context = SpringContext.getAppContext();
userStatsRepository = (UserStatsRepository) context.getBean("userStatsRepository");
@ -63,30 +61,32 @@ public class UserStatsUtils {
User jdaUser = MainBot.jda.getUserById(userEntity.getJdaId());
//TODO clean database for deleted users
if(jdaUser == null)
if (jdaUser == null){
logger.warn("jdaUser is null, can't find discord user ????");
return null;
}
logger.debug(userEntity);
logger.debug(userEntity.getUserStats());
if (userEntity.getUserStats() == null || userEntity.getUserStats().size() == 0 || userEntity.getUserStats().size() < jdaUser.getMutualGuilds().size()) {
logger.debug("Stats not found for " + userEntity.getName());
User user = MainBot.jda.getUserById(userEntity.getJdaId());
if(user == null)
return null;
List<UserStats> stats;
if (userEntity.getUserStats() == null || userEntity.getUserStats().size() == 0) {
logger.debug("No stats found for user " + jdaUser.getName() + ", use blank.");
logger.debug("Creating stats for guilds: ");
stats = new ArrayList<>();
for(Guild guid : user.getMutualGuilds()){
logger.debug(guid.getName());
for (Guild guid : jdaUser.getMutualGuilds()) {
logger.debug("..." + guid.getName());
stats.add(new UserStats(guid.getId(), userEntity));
}
}
else{
} else {
stats = userEntity.getUserStats();
ArrayList<String> guildStat = new ArrayList<>();
for (UserStats stat : stats) {
guildStat.add(stat.getGuildId());
}
for(Guild guid : user.getMutualGuilds()){
for (Guild guid : jdaUser.getMutualGuilds()) {
logger.debug(guid.getName());
if (!guildStat.contains(guid.getId())) {
logger.debug("Guild " + guid.getName() + " stats don't exist");
@ -114,8 +114,7 @@ public class UserStatsUtils {
if (userList.size() == 0) {
logger.debug("User not registered, generate it. User: " + user.getName() + " " + user.getDiscriminator());
userEntity = genUserEntity(user);
}
else
} else
userEntity = userList.get(0);
return getUserStats(userEntity);
@ -123,17 +122,18 @@ public class UserStatsUtils {
}
public UserStats getGuildUserStats(Member member) {
List<UserEntity> userEntityList = userRepository.findByJdaId(member.getUser().getId());
UserEntity userEntity;
if( userEntityList.size() == 0)
if (userEntityList.size() == 0) {
logger.debug("UserEntity not found for user " + member.getNickname());
userEntity = genUserEntity(member.getUser());
else
} else
userEntity = userEntityList.get(0);
List<UserStats> userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, member.getGuild().getId());
if (userStatsList.size() == 0) {
logger.debug("User stats not found for user " + userEntity.getName() + " guild: " + member.getGuild().getId());
getUserStats(userEntity);
userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, member.getGuild().getId());
}
@ -144,6 +144,7 @@ public class UserStatsUtils {
public UserStats getGuildUserStats(UserEntity userEntity, String guildId) {
List<UserStats> userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, guildId);
if (userStatsRepository.findByUserAndGuildId(userEntity, guildId).size() == 0) {
logger.debug("User stats not found for user " + userEntity.getName() + " guild: " + guildId);
getUserStats(userEntity);
userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, guildId);
}
@ -179,15 +180,12 @@ public class UserStatsUtils {
}
private UserEntity genUserEntity(User user) {
UserEntity userEntity = new UserEntity(user, passwordEncoder);
return userRepository.save(userEntity);
}
public GuildStatsPack getStatPack(UserEntity userEntity, String guildId) {
UserStats userStats = getGuildUserStats(userEntity, guildId);
GuildStats selfGuildStats = null;
@ -206,7 +204,6 @@ public class UserStatsUtils {
}
}
ranked.sort((guildStats, t1) -> (int) (t1.total - guildStats.total));
@ -264,6 +261,7 @@ public class UserStatsUtils {
public static class VoicePresenceCounter extends Thread {
private Member member;
public VoicePresenceCounter(Member member) {
this.member = member;
}
@ -287,5 +285,4 @@ public class UserStatsUtils {
}
}