Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix /leaderboard thanks for non-members #503

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import net.discordjug.javabot.util.Responses;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.UserSnowflake;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;

Expand Down Expand Up @@ -50,30 +50,30 @@ SELECT COUNT(id), helper_id
FROM help_channel_thanks
GROUP BY helper_id""", event.getGuild()).stream()
.limit(3)
.map(p -> String.format(format, p.getSecond(), p.getFirst().getUser().getAsMention()))
.map(p -> String.format(format, p.getSecond(), p.getFirst().getAsMention()))
.collect(collector);
String helpersThisWeek = getCounts("""
SELECT COUNT(id), helper_id
FROM help_channel_thanks
WHERE thanked_at > DATEADD('week', -1, CURRENT_TIMESTAMP(0))
GROUP BY helper_id""", event.getGuild()).stream()
.limit(3)
.map(p -> String.format(format, p.getSecond(), p.getFirst().getUser().getAsMention()))
.map(p -> String.format(format, p.getSecond(), p.getFirst().getAsMention()))
.collect(collector);
String totalHelped = getCounts("""
SELECT COUNT(id) AS count, user_id
FROM help_channel_thanks
GROUP BY user_id""", event.getGuild()).stream()
.limit(3)
.map(p -> String.format(format, p.getSecond(), p.getFirst().getUser().getAsMention()))
.map(p -> String.format(format, p.getSecond(), p.getFirst().getAsMention()))
.collect(collector);
String helpedThisWeek = getCounts("""
SELECT COUNT(id) AS count, user_id
FROM help_channel_thanks
WHERE thanked_at > DATEADD('week', -1, CURRENT_TIMESTAMP(0))
GROUP BY user_id""", event.getGuild()).stream()
.limit(3)
.map(p -> String.format(format, p.getSecond(), p.getFirst().getUser().getAsMention()))
.map(p -> String.format(format, p.getSecond(), p.getFirst().getAsMention()))
.collect(collector);
EmbedBuilder embed = new EmbedBuilder()
.setTitle("Thanks Leaderboard")
Expand All @@ -86,20 +86,18 @@ WHERE thanked_at > DATEADD('week', -1, CURRENT_TIMESTAMP(0))
});
}

private List<Pair<Member, Long>> getCounts(String query, Guild guild) {
private List<Pair<UserSnowflake, Long>> getCounts(String query, Guild guild) {
try {
return dbActions.mapQuery(
query,
s -> {
},
rs -> {
List<Pair<Member, Long>> memberData = new ArrayList<>();
List<Pair<UserSnowflake, Long>> memberData = new ArrayList<>();
while (rs.next()) {
long count = rs.getLong(1);
long userId = rs.getLong(2);
Member member = guild.retrieveMemberById(userId).complete();
if (member == null) continue;
memberData.add(new Pair<>(member, count));
memberData.add(new Pair<>(UserSnowflake.fromId(userId), count));
}
// Sort with high counts first.
memberData.sort((o1, o2) -> Long.compare(o2.getSecond(), o1.getSecond()));
Expand Down