Skip to content
This repository was archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Add daily rate limit handling to notifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Brycey92 committed Apr 29, 2023
1 parent 9b99a02 commit e8cd993
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/util/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ export async function startNotifier(database: Database, domain: string, apiKey:
await insertRow(database, 'private_users', users[i].user_id, users[i].username);
statusMessage(MessageType.Process, `Skipping ${users[i].user_id} ${users[i].username} [(++${userCount[0]}/${totalUsers})]`);
} else {
const match = pmRequest.error.message.match(/Please wait (\d+) (\w+) before sending another message\./)
const match = pmRequest.error.message.match(/Please wait (\d+) (\w+) before sending another message\./);
const dailyLimitMatch = pmRequest.error.message.match(/You have reached your daily message limit, please try again tomorrow\./);
if (match) {
const time = parseInt(match[1]);
const unit = match[2];
Expand All @@ -125,6 +126,14 @@ export async function startNotifier(database: Database, domain: string, apiKey:
i--;

continue;
} else if (dailyLimitMatch) {
statusMessage(MessageType.Process, `Auth ${authId} rate-limited for the day. Setting a 1-hour cooldown. Trying ${users[i].user_id} ${users[i].username} again...`);

// Add the rate-limit to the auth
rateLimits[authId] = new Date(Date.now() + 60 * 60 * 1000);

// Retry the user.
i--;
} else {
process.kill(process.pid, 'SIGINT');
}
Expand Down

0 comments on commit e8cd993

Please sign in to comment.