Remove quick fix and fix the stats error

This commit is contained in:
Sebastien 2018-12-14 09:59:15 +02:00
parent 352a87a1f3
commit e6f6372d66
2 changed files with 6 additions and 12 deletions

View File

@ -159,12 +159,9 @@ public class MusicWebAPIController {
logger.info("Receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName() + " GUILD: " + guild.getName()); logger.info("Receive command " + data.command + " from " + request.getRemoteAddr() + " USER: " + user.getName() + " GUILD: " + guild.getName());
if (ApiCommandLoader.apiCommands.containsKey(data.command)) { if (ApiCommandLoader.apiCommands.containsKey(data.command)) {
try {
UserStatsUtils.getINSTANCE().addApiCount(user, guildId); UserStatsUtils.getINSTANCE().addApiCount(user, guildId);
}catch (IndexOutOfBoundsException e){
logger.catching(e);
}
return ApiCommandLoader.apiCommands.get(data.command).action(data, MainBot.jda.getUserById(user.getJdaId()), guild); return ApiCommandLoader.apiCommands.get(data.command).action(data, MainBot.jda.getUserById(user.getJdaId()), guild);
} }
else else

View File

@ -12,7 +12,6 @@ import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.entities.User;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.Hibernate;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
@ -45,15 +44,15 @@ public class UserStatsUtils {
} }
public List<UserStats> getUserStats(UserEntity userEntity){ public List<UserStats> getUserStats(UserEntity userEntity){
logger.debug(userEntity.getUserStats()); User jdaUser = MainBot.jda.getUserById(userEntity.getJdaId());
logger.debug(userEntity.getUserStats().size()); if(userEntity.getUserStats() == null || userEntity.getUserStats().size() == 0 || userEntity.getUserStats().size() != jdaUser.getMutualGuilds().size()){
if(userEntity.getUserStats() == null || userEntity.getUserStats().size() == 0){
logger.debug("Stats not found for " + userEntity.getName()); logger.debug("Stats not found for " + userEntity.getName());
User user = MainBot.jda.getUserById(userEntity.getJdaId()); User user = MainBot.jda.getUserById(userEntity.getJdaId());
if(user == null) if(user == null)
return null; return null;
List<UserStats> stats = new ArrayList<>(); List<UserStats> stats = new ArrayList<>();
for(Guild guid : user.getMutualGuilds()){ for(Guild guid : user.getMutualGuilds()){
logger.debug(guid.getName());
stats.add(new UserStats(guid.getId(), userEntity)); stats.add(new UserStats(guid.getId(), userEntity));
} }
stats = (List<UserStats>) userStatsRepository.save(stats); stats = (List<UserStats>) userStatsRepository.save(stats);
@ -92,7 +91,6 @@ public class UserStatsUtils {
userEntity = userEntityList.get(0); userEntity = userEntityList.get(0);
List<UserStats> userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, member.getGuild().getId()); List<UserStats> userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, member.getGuild().getId());
logger.debug("First: " + userStatsList.size());
if(userStatsList.size() == 0){ if(userStatsList.size() == 0){
getUserStats(userEntity); getUserStats(userEntity);
userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, member.getGuild().getId()); userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, member.getGuild().getId());
@ -109,8 +107,7 @@ public class UserStatsUtils {
List<UserStats> userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, guildId); List<UserStats> userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, guildId);
logger.debug("First: " + userStatsList.size()); if(userStatsRepository.findByUserAndGuildId(userEntity, guildId).size() == 0){
if(userStatsList.size() == 0){
getUserStats(userEntity); getUserStats(userEntity);
userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, guildId); userStatsList = userStatsRepository.findByUserAndGuildId(userEntity, guildId);
} }