Skip to content

Commit

Permalink
Fix recycle v2 (#16)
Browse files Browse the repository at this point in the history
* chore: fix channel message

* chore: add one more break point

---------

Co-authored-by: Can Sirin <[email protected]>
  • Loading branch information
cansirin and cansirin authored Mar 30, 2024
1 parent 0bb4b2e commit 72072e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/commands/recycle-v2-roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,8 @@ const recycleV2Roles = {
}
});

const removedUsersList =
removedUsers.length > 0
? `These are returned users: ${removedUsers.map((user) => {
return `\n${user}`;
})}`
: "";
const removedUserListNames = removedUsers.join(", ");


let message = dryRun
? `[DRYRUN] Done. ${count} members will be purged from v2 role.`
Expand All @@ -61,7 +57,7 @@ const recycleV2Roles = {
process.env.GIDENLER_CHANNEL_ID
) as TextChannel;
if (!channel) return;
await channel.send(`${message} ${removedUsersList}`);
await channel.send(`${message} ${removedUserListNames}`);
},
};

Expand Down
11 changes: 10 additions & 1 deletion src/features/fetch-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export async function fetchMessages(client: Client, channelID: string, days = 7,

if (messages.size === 0) break;

const countOfOldMessages = messagesCollected.length;

messages.forEach((m) => {
if (m.createdTimestamp > nDaysAgo) {
messagesCollected.push({
Expand All @@ -51,11 +53,18 @@ export async function fetchMessages(client: Client, channelID: string, days = 7,
}
});

const countOfNewMessages = messagesCollected.length - countOfOldMessages;
if(countOfNewMessages === 0){
console.log("No new messages found. Breaking the loop.");
break;
}

// Update lastId for the next iteration
lastId = messages.lastKey();
console.log("Last ID:", lastId);
console.log(messagesCollected.length, " messages collected so far.");

await setTimeout(1000); // Respect rate limits
await setTimeout(3000);
}

console.log("Done. Messages collected:", messagesCollected.length);
Expand Down

0 comments on commit 72072e4

Please sign in to comment.