|
10 | 10 | import net.discordjug.javabot.util.Pair; |
11 | 11 | import net.dv8tion.jda.api.JDA; |
12 | 12 | import net.dv8tion.jda.api.entities.Guild; |
| 13 | +import net.dv8tion.jda.api.entities.User; |
13 | 14 |
|
14 | 15 | import org.springframework.beans.factory.annotation.Autowired; |
15 | 16 | import org.springframework.http.HttpStatus; |
@@ -68,15 +69,21 @@ public ResponseEntity<List<QOTWUserData>> getQOTWLeaderboard( |
68 | 69 | if (members == null || members.isEmpty()) { |
69 | 70 | List<QOTWAccount> topAccounts = pointsService.getTopAccounts(PAGE_AMOUNT, page); |
70 | 71 | members = topAccounts.stream() |
71 | | - .map(account -> QOTWUserData.of( |
72 | | - account, |
73 | | - jda.retrieveUserById(account.getUserId()).complete(), |
74 | | - //this can be inaccurate for later pages with multiple users having the same score on the previous page |
75 | | - //specifically, it counts all users on previous pages as strictly higher in the leaderboard |
76 | | - pointsService.getQOTWRank(account.getUserId(), topAccounts)+(page-1)*PAGE_AMOUNT)) |
| 72 | + .map(account -> new Pair<>(account, jda.retrieveUserById(account.getUserId()).complete())) |
| 73 | + .filter(pair -> guild.isMember(pair.second())) |
| 74 | + .map(pair -> createAPIAccount(pair.first(), pair.second(), topAccounts, page)) |
77 | 75 | .toList(); |
78 | 76 | getCache().put(new Pair<>(guild.getIdLong(), page), members); |
79 | 77 | } |
80 | 78 | return new ResponseEntity<>(members, HttpStatus.OK); |
81 | 79 | } |
| 80 | + |
| 81 | + private QOTWUserData createAPIAccount(QOTWAccount account, User user, List<QOTWAccount> topAccounts, int page) { |
| 82 | + return QOTWUserData.of( |
| 83 | + account, |
| 84 | + user, |
| 85 | + //this can be inaccurate for later pages with multiple users having the same score on the previous page |
| 86 | + //specifically, it counts all users on previous pages as strictly higher in the leaderboard |
| 87 | + pointsService.getQOTWRank(account.getUserId(), topAccounts)+(page-1)*PAGE_AMOUNT); |
| 88 | + } |
82 | 89 | } |
0 commit comments