Skip to content
Open
Show file tree
Hide file tree
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 @@ -10,15 +10,16 @@ public class PopularHandler {
public static int ratio;

public static void calculate() {
new SingleQueryBuilder().query("SELECT (COUNT(*) * 0.5) AS ratio FROM suggestions WHERE popular_message > 0 " +
"AND date > CURRENT_TIMESTAMP - INTERVAL 1 WEEK ORDER BY (upvotes - downvotes) LIMIT 10;")

// The algorithm works by counting how many popular suggestions were made in the past 2 weeks,
// Then adds them to a base minimum value. The value is then clamped.
new SingleQueryBuilder().query("SELECT COUNT(*) AS recents FROM suggestions WHERE popular_message > 0 " +
"AND date > CURRENT_TIMESTAMP - INTERVAL 2 WEEK;")
.onQuery((set) -> {
ratio = (int) Math.ceil(set.getInt("ratio")) + BotConstants.RATIO;
if (ratio < BotConstants.RATIO) {
ratio = BotConstants.RATIO;
}
ratio = BotConstants.MIN_RATIO + (int) set.getInt("recents"));
ratio = Math.max(BotConstants.MIN_RATIO, Math.min(ratio, BotConstants.MAX_RATIO));
}).execute();
BotInstance.getJda().getPresence().setActivity(Activity.watching("for " + PopularHandler.ratio + " net upvotes"));

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public interface BotConstants {

String PREFIX = "?";

// The ratio cannot go lower than this.
int RATIO = 18;
// The upvote ratio cannot go lower than MIN or higher than MAX.
int MIN_RATIO = 20;
int MAX_RATIO = 35;

long UPVOTE = 612568094962876416L;
long DOWNVOTE = 612568084414201856L;
Expand Down