Skip to content

Commit

Permalink
50/m rate limit delay
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Jun 14, 2024
1 parent 17e07d7 commit 5865d59
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions utils/joinall.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,35 @@ module.exports = async function ({ app, client }) {
limit: 999,
cursor,
});
let joinPromises = convos.channels.map((channel) => {
return new Promise(async (resolve) => {
for (const channel of convos.channels) {
await new Promise(async (resolve, reject) => {
const channelRecord = await prisma.channel.findFirst({
where: {
id: channel.id,
},
});
if (channelRecord && channelRecord.optout) return;
if (channel.is_member || channel.is_archived || channel.is_private)
if (channelRecord && channelRecord.optout) {
resolve();
return;
setTimeout(async () => {
try {
await app.client.conversations.join({
channel: channel.id,
});
console.log(`Joined ${channel.name_normalized} (${channel.id})`);
} catch (e) {
console.warn(
`Failed to join ${channel.name_normalized} (${channel.id})`,
);
}
}
if (channel.is_member || channel.is_archived || channel.is_private) {
resolve();
}, 1000);
});
});
return;
}
try {
await app.client.conversations.join({
channel: channel.id,
});
console.log(`Joined ${channel.name_normalized} (${channel.id})`);
setTimeout(resolve, 1200);
} catch (e) {
console.warn(`Failed to join ${channel.name_normalized} (${channel.id})`);
setTimeout(resolve, 1200);

}

await Promise.all(joinPromises);
});
}
if (convos.response_metadata.next_cursor)
setTimeout(async function () {
await rake(convos.response_metadata.next_cursor);
Expand Down

0 comments on commit 5865d59

Please sign in to comment.