Skip to content

Conversation

@Arshadul-Monir
Copy link
Collaborator

@Arshadul-Monir Arshadul-Monir commented Feb 7, 2026

697

Description of changes

Checklist before review

  • I have done a thorough self-review of the PR
  • Copilot has reviewed my latest changes, and all comments have been fixed and/or closed.
  • If I have made database changes, I have made sure I followed all the db repo rules listed in the wiki here. (check if no db changes)
  • All tests have passed
  • I have successfully deployed this PR to staging
  • I have done manual QA in both dev (and staging if possible) and attached screenshots below.

Screenshots

Dev

Staging

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Available PR Commands

  • /ai - Triggers all AI review commands at once
  • /review - AI review of the PR changes
  • /describe - AI-powered description of the PR
  • /improve - AI-powered suggestions
  • /deploy - Deploy to staging

See: https://github.com/tahminator/codebloom/wiki/CI-Commands

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

Title

697


PR Type

Enhancement


Description

  • Add /leaderboard Discord slash command

  • Post weekly leaderboard embed per guild

  • Lookup DiscordClub by guildId in repo

  • Register command on bot ready event


Diagram Walkthrough

flowchart LR
  A["JDA ReadyEvent"] --> B["Upsert /leaderboard command on all guilds"]
  C["SlashCommandInteraction: /leaderboard"] --> D["DiscordClubManager.sendWeeklyLeaderboardUpdateDiscordMessageForClub(guildId)"]
  D --> E["DiscordClubRepository.getDiscordClubByGuildId(guildId)"]
  D --> F["LeaderboardRepository fetch latest + users"]
  D --> G["Build embed: top 3, time left"]
  G --> H["jdaClient.sendEmbedWithImages to club channel"]
Loading

File Walkthrough

Relevant files
Enhancement
DiscordClubManager.java
Guild-scoped weekly leaderboard embed sender                         

src/main/java/org/patinanetwork/codebloom/common/components/DiscordClubManager.java

  • Add method to send leaderboard by guildId.
  • Fetch club, leaderboard, and top users.
  • Build description with time remaining and links.
  • Send embed to configured leaderboard channel.
+89/-0   
DiscordClubRepository.java
Repository interface adds guildId lookup                                 

src/main/java/org/patinanetwork/codebloom/common/db/repos/discord/club/DiscordClubRepository.java

  • Add repository method getDiscordClubByGuildId.
  • Minor interface formatting updates.
+3/-0     
DiscordClubSqlRepository.java
SQL repo implements guildId-based club retrieval                 

src/main/java/org/patinanetwork/codebloom/common/db/repos/discord/club/DiscordClubSqlRepository.java

  • Implement getDiscordClubByGuildId with SQL join.
  • Map result to DiscordClub; handle absence.
  • Throw runtime on SQL errors.
+28/-0   
JDAEventListener.java
JDA listener adds /leaderboard command handling                   

src/main/java/org/patinanetwork/codebloom/jda/JDAEventListener.java

  • Inject DiscordClubManager into listener.
  • Register /leaderboard on ReadyEvent.
  • Handle /leaderboard by invoking manager.
+23/-0   

@github-actions
Copy link
Contributor

github-actions bot commented Feb 7, 2026

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Rate Limit

The /leaderboard slash command has no per-guild 60-minute rate limiting and no ephemeral rate-limit response; add a per-guild cooldown store and reply ephemerally when throttled to meet AC.

@Override
public void onSlashCommandInteraction(final SlashCommandInteractionEvent event) {
    if (event.getName().equals("leaderboard")) {
        discordClubManager.sendWeeklyLeaderboardUpdateDiscordMessageForClub(event.getGuild().getId());
    }
}
Interaction Handling

The slash command handler does not acknowledge the interaction (reply/deferReply), risking "interaction failed" and offering no user feedback on success or failure; add event.deferReply(true) or appropriate ephemeral replies.

@Override
public void onSlashCommandInteraction(final SlashCommandInteractionEvent event) {
    if (event.getName().equals("leaderboard")) {
        discordClubManager.sendWeeklyLeaderboardUpdateDiscordMessageForClub(event.getGuild().getId());
    }
}
Possible Issue

getDiscordClubByGuildId(...).get() may throw if the guild is not configured; handle the empty Optional and provide a safe path (and user-visible ephemeral message) instead of throwing.

public void sendWeeklyLeaderboardUpdateDiscordMessageForClub(String guildId) {
    System.out.println("working");
    DiscordClub club = discordClubRepository.getDiscordClubByGuildId(guildId).get();
    var latestLeaderboard = leaderboardRepository.getRecentLeaderboardMetadata();

        LeaderboardFilterOptions options = LeaderboardFilterGenerator.builderWithTag(club.getTag())
                .page(1)
                .pageSize(5)

@Arshadul-Monir Arshadul-Monir force-pushed the 697 branch 6 times, most recently from 5a3f2e8 to 6dd795f Compare February 10, 2026 20:28
@Arshadul-Monir Arshadul-Monir changed the title 697 697: Add /leaderboard discord bot command Feb 10, 2026
@Arshadul-Monir Arshadul-Monir self-assigned this Feb 10, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a Discord /leaderboard slash command and refactors Discord bot initialization so the JDA client is created via a central manager and reused across the app.

Changes:

  • Introduces /leaderboard command registration + handling via JDAEventListener.
  • Refactors JDA lifecycle: removes connect() flow from JDAClient and initializes JDA in JDAClientManager.
  • Adds DB lookup for Discord clubs by guild ID and a message builder for weekly leaderboard embeds.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/test/java/org/patinanetwork/codebloom/config/NoJdaRequired.java Updates test-time JDA mocking to match the new JDA manager class.
src/test/java/org/patinanetwork/codebloom/common/db/repos/BaseRepositoryTest.java Updates repository test base to mock the new JDA manager class.
src/test/java/org/patinanetwork/codebloom/common/components/DiscordClubManagerTest.java Updates tests to reflect removal of jdaClient.connect() calls.
src/main/java/org/patinanetwork/codebloom/jda/client/JDAClient.java Removes explicit connect/ready checks; uses a pre-initialized JDA instance from the manager.
src/main/java/org/patinanetwork/codebloom/jda/JDAEventListener.java Adds slash command upsert + interaction handling for /leaderboard.
src/main/java/org/patinanetwork/codebloom/jda/JDAClientManager.java Replaces JDAInitializer with a component-managed JDA client initializer/holder.
src/main/java/org/patinanetwork/codebloom/common/db/repos/discord/club/DiscordClubSqlRepository.java Adds SQL query to fetch a club by Discord guild ID.
src/main/java/org/patinanetwork/codebloom/common/db/repos/discord/club/DiscordClubRepository.java Adds repository API for lookup by guild ID.
src/main/java/org/patinanetwork/codebloom/common/components/DiscordClubManager.java Adds message builder for weekly leaderboard embed used by the slash command.
src/main/java/org/patinanetwork/codebloom/api/auth/security/CustomAuthenticationSuccessHandler.java Stops calling jdaClient.connect() during auth success handling.
Comments suppressed due to low confidence (1)

src/main/java/org/patinanetwork/codebloom/jda/JDAClientManager.java:29

  • This constructor calls initializeJda() and awaitReady() during Spring bean creation. That blocks application startup on Discord connectivity and will fail the entire app context if Discord is down or the token is invalid. Consider lazy initialization (connect on first use), or gating JDA startup behind a feature flag/property so non-bot deployments and local/dev/test startup aren’t hard-dependent on Discord availability.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Arshadul-Monir Arshadul-Monir force-pushed the 697 branch 6 times, most recently from 752aeae to 5978d82 Compare February 11, 2026 20:15
@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@Arshadul-Monir Arshadul-Monir force-pushed the 697 branch 2 times, most recently from 65de9d4 to c10bc71 Compare February 12, 2026 02:24
@Arshadul-Monir
Copy link
Collaborator Author

/deploy

@Arshadul-Monir
Copy link
Collaborator Author

/improve

@Arshadul-Monir Arshadul-Monir force-pushed the 697 branch 3 times, most recently from 45b19ca to 380c563 Compare February 13, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants