|
3 | 3 | import lombok.RequiredArgsConstructor; |
4 | 4 | import net.dv8tion.jda.api.entities.Guild; |
5 | 5 | import net.dv8tion.jda.api.entities.Member; |
6 | | -import net.dv8tion.jda.api.entities.Role; |
7 | | -import net.javadiscord.javabot.data.config.BotConfig; |
8 | 6 | import net.javadiscord.javabot.systems.qotw.dao.QuestionPointsRepository; |
9 | 7 | import net.javadiscord.javabot.systems.qotw.model.QOTWAccount; |
10 | 8 | import net.javadiscord.javabot.util.ExceptionLogger; |
|
26 | 24 | @Service |
27 | 25 | public class QOTWPointsService { |
28 | 26 | private final QuestionPointsRepository pointsRepository; |
29 | | - private final BotConfig botConfig; |
30 | 27 |
|
31 | 28 | /** |
32 | 29 | * Creates a new QOTW Account if none exists. |
@@ -124,33 +121,16 @@ public List<QOTWAccount> getTopAccounts(int amount, int page) { |
124 | 121 | /** |
125 | 122 | * Increments a single user's QOTW-Points. |
126 | 123 | * |
127 | | - * @param member The {@link Member} whose points shall be incremented |
| 124 | + * @param userId The ID of the user whose points shall be incremented |
128 | 125 | * @return The total points after the update. |
129 | 126 | */ |
130 | | - public long increment(Member member) { |
131 | | - long userId = member.getIdLong(); |
| 127 | + public long increment(long userId) { |
132 | 128 | try { |
133 | 129 | LocalDate date=LocalDate.now(); |
134 | 130 | int points = pointsRepository.getPointsAtDate(userId, date)+1; |
135 | 131 | pointsRepository.setPointsAtDate(userId, date, points); |
136 | | - Role qotwChampionRole = botConfig.get(member.getGuild()).getQotwConfig().getQOTWChampionRole(); |
137 | 132 | LocalDate month = getCurrentMonth(); |
138 | 133 | long newScore = pointsRepository.getByUserId(userId, month).map(QOTWAccount::getPoints).orElse(0L); |
139 | | - if (qotwChampionRole != null) { |
140 | | - pointsRepository.getTopAccounts(month, 0, 1) |
141 | | - .stream() |
142 | | - .findFirst() |
143 | | - .ifPresent(best -> { |
144 | | - if (newScore >= best.getPoints()) { |
145 | | - member.getGuild().addRoleToMember(member, qotwChampionRole).queue(); |
146 | | - for (Member m : member.getGuild().getMembersWithRoles(qotwChampionRole)) { |
147 | | - if (getOrCreateAccount(m.getIdLong()).getPoints() < best.getPoints()) { |
148 | | - m.getGuild().removeRoleFromMember(m, qotwChampionRole).queue(); |
149 | | - } |
150 | | - } |
151 | | - } |
152 | | - }); |
153 | | - } |
154 | 134 | return newScore; |
155 | 135 | } catch (DataAccessException e) { |
156 | 136 | ExceptionLogger.capture(e, getClass().getSimpleName()); |
|
0 commit comments