-
Notifications
You must be signed in to change notification settings - Fork 18
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
Preventing Bots from having Top 10 coin holder role #470
base: main
Are you sure you want to change the base?
Preventing Bots from having Top 10 coin holder role #470
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the description in the issue:
There should still be ten people with the
Top 10 Coin Holder
role, though they should all be non-bot users.
This code looks like less than ten people would have the role.
@@ -137,7 +137,8 @@ export const createCoffeeChatCron = (client: Client): CronJob => | |||
// Gives Codey coin role to those on the leaderboard list everyday | |||
export const assignCodeyRoleForLeaderboard = (client: Client): CronJob => | |||
new CronJob('0 0 0 */1 * *', async function () { | |||
const leaderboard = await getCoinLeaderboard(NUMBER_USERS_TO_ASSIGN_ROLE); | |||
// extra 5 members in case there are 5 bots in the leaderboard (as per the production environment) | |||
const leaderboard = await getCoinLeaderboard(NUMBER_USERS_TO_ASSIGN_ROLE + 5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might give more users than 10 if there are less than 5 bots that are in the top 10 codey coin users. I would make sure that in the code that is responsible for displaying the leaderboard, you only display the top ten people (right now it displays everyone in the leaderboard).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcpenguin So the code for getCoinLeaderboard uses a SQL query and I am not sure how I can change the SQL query itself to remove the bots.
What I can do is something like this -
let users = 0;
while (users < 10) {
const leaderboard = await getCointLeaderboard(NUMBER_USERS_TO_ASSIGN_ROLE + 5);
... // the rest of the code
if (memberToUpdate && !memberToUpdate.user?.bot) {
await updateMemberRole(memberToUpdate, await getRoleName(CODEY_COIN_ROLE_ID), true);
users++; // add that we have added 1 user
}
}
This can ensure that only 10 users get the role. Let me know your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should get the leaderboard before the while loop, but yeah, that was how I was thinking we could proceed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh okay cool, yeah I will do that and update the pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@Picowchew Please confirm :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code seems to give an infinite loop. Since you have asynchronous code inside the forEach
loop, the forEach
loop finishes iterating before the code inside an iteration finishes executing. Then, the users
variable remains to be 0, so you get an infinite loop because the condition of the while
loop is always satisfied.
I would recommend iterating through leaderboardIds
with a for
loop, and then break out of this loop once 10 non-bot users have the role.
To test your code, I would recommend having more than 10 users in the user_coin
table (e.g. you can give coins to more than 10 users), assigning less than 10 users the role, and shortening the time interval of the cron job. Then, ensure that the result is that only the top 10 non-bot users have the role.
Summary of Changes
Added a check in cron job to see if the member being assigned the role is a bot.
Related Issues
resolves #467
Steps to Reproduce
Check if a bot is in leaderboard but does not get the role.
Demonstration of Changes
Cannot demonstrate since my bot for some reason is not getting added to the leaderboard.
Further Information and Comments