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

Add top-helpers command #282

Merged
merged 6 commits into from
Feb 2, 2022
Merged

Add top-helpers command #282

merged 6 commits into from
Feb 2, 2022

Conversation

marko-radosavljevic
Copy link
Contributor

@marko-radosavljevic marko-radosavljevic commented Nov 26, 2021

Overview

Implements and closes #65. Originally based on #117.

Adds the /top-helpers command that computes and displays the top helpers from the last month.

example

Also has a fallback message if there is no data in the time range yet:

no data

For now the command has no options but it was designed with optionally picking a time range (start and end) in mind. This can be done once Discord/JDA add date-pickers (currently in progress). A TODO in the class keeps track of this.

Details

The code is divided into three classes:

  • TopHelpersCommand - the slash command itself, will read the database, compute the message and display it
  • TopHelpersMessageListener - the listener that receives all help messages and adjusts the database accordingly
  • TopHelpersPurgeMessagesRoutine - the routine that deletes old messages from the database

Slash command

The TopHelpersCommand class is pretty straightforward:

  1. Check author permissions, needs "soft moderation role"
  2. Compute the time range (last month, this is properly computed with java.time and not just last 30 days)
  3. Fetch the top helpers from the database (some groupBy with count and orderBy, nothing fancy)
  4. Extra logic if there is no data in the time range
  5. Retrieve Member information about those users async
  6. Error handler if it fails
  7. Success handler that basically stringifies the user data using an external AsciiTable library

Message listener

The TopHelpersMessageListener class has one simple jobs right now:

  1. any incoming message will be added to the database table (just ids and timestamps, no content)

latter should in the near future be replaced with #346 , a TODO keeps track of it already.

Help messages are identified by channel name regex (as per MessageReceiverAdapter), the regex is:

"helpChannelPattern": "([a-zA-Z_]+_)?help(_\\d+)?"

In the future, FreeCommand could be changed to utilize this config entry as well, instead of the channel ids.

Message purging

The class TopHelpersPurgeMessagesRoutine is a simple Routine which is executed once every 4 hours and deletes all top-helper message entries in the database that are older than 90 days.

Database

The database table that supports all the magic is quite simple, its just:

CREATE TABLE help_channel_messages
(
    message_id BIGINT    NOT NULL PRIMARY KEY,
    guild_id   BIGINT    NOT NULL,
    channel_id BIGINT    NOT NULL,
    author_id  BIGINT    NOT NULL,
    sent_at    TIMESTAMP NOT NULL
)

Remarks for release

The config has changed, the following has been added:

"helpChannelPattern": "([a-zA-Z_]+_)?help(_\\d+)?"

(see the config.json.template file in the code diff)

@marko-radosavljevic marko-radosavljevic added new command Add a new command or group of commands to the bot priority: major labels Nov 26, 2021
@github-actions
Copy link

This pull request is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Dec 27, 2021
@Zabuzard Zabuzard removed the stale label Dec 29, 2021
@Zabuzard
Copy link
Member

Valid but parked, will be picked up by someone soonish (january maybe).

@Zabuzard Zabuzard self-assigned this Jan 21, 2022
@Zabuzard Zabuzard added the blocked This issue is currently blocked by another issue (see comments) label Jan 21, 2022
@Zabuzard
Copy link
Member

Zabuzard commented Jan 21, 2022

Will take this over but for the moment blocked by #345.

@Zabuzard Zabuzard removed the blocked This issue is currently blocked by another issue (see comments) label Jan 27, 2022
@Zabuzard Zabuzard force-pushed the feature/top-helpers branch 2 times, most recently from e83c4f8 to 306f674 Compare January 27, 2022 11:44
@Zabuzard
Copy link
Member

Zabuzard commented Jan 27, 2022

Revived it. It is working again now:

example

Will polish it now.

Zabuzard
Zabuzard previously approved these changes Jan 27, 2022
d3vel0per and others added 4 commits February 2, 2022 12:25
* changed the layout of the methods
* fixed style issues
* fixed various design issues
* streamlined the code more

the logic itself merely changed
* with proper java.time computation instead of just "last 30 days"
@sonarcloud
Copy link

sonarcloud bot commented Feb 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@Zabuzard
Copy link
Member

Zabuzard commented Feb 2, 2022

No changes since a week, merging.

@Zabuzard Zabuzard merged commit 33a280d into develop Feb 2, 2022
@Zabuzard Zabuzard deleted the feature/top-helpers branch February 2, 2022 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new command Add a new command or group of commands to the bot priority: major
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate TopHelper system
3 participants