Skip to content

Commit 0d9e000

Browse files
committed
981236741297802654
1 parent 0d9e000 commit 0d9e000

File tree

1 file changed

+29
-16
lines changed

1 file changed

+29
-16
lines changed

tgbot.deno.ts

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ const MIN_REQUEST_INTERVAL = 100; // Minimum 100ms between requests
3535
async function rateLimitedDelay() {
3636
const now = Date.now();
3737
const timeSinceLastRequest = now - lastRequestTime;
38-
38+
3939
if (timeSinceLastRequest < MIN_REQUEST_INTERVAL) {
4040
const delay = MIN_REQUEST_INTERVAL - timeSinceLastRequest;
41-
await new Promise(resolve => setTimeout(resolve, delay));
41+
await new Promise((resolve) => setTimeout(resolve, delay));
4242
}
43-
43+
4444
lastRequestTime = Date.now();
4545
}
4646

@@ -64,21 +64,29 @@ async function tgCall(
6464
},
6565
body: JSON.stringify(options),
6666
});
67-
67+
6868
try {
6969
let resp = await req.json();
70-
70+
7171
// Handle rate limiting with exponential backoff
7272
if (!resp.ok && resp.error_code === 429 && retryCount < maxRetries) {
73-
const retryAfter = resp.parameters?.retry_after || Math.pow(2, retryCount);
74-
const delay = Math.min(baseDelay * Math.pow(2, retryCount), retryAfter * 1000);
75-
76-
console.log(`Rate limited on ${endpoint}. Retrying in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})`);
77-
78-
await new Promise(resolve => setTimeout(resolve, delay));
73+
const retryAfter = resp.parameters?.retry_after ||
74+
Math.pow(2, retryCount);
75+
const delay = Math.min(
76+
baseDelay * Math.pow(2, retryCount),
77+
retryAfter * 1000,
78+
);
79+
80+
console.log(
81+
`Rate limited on ${endpoint}. Retrying in ${delay}ms (attempt ${
82+
retryCount + 1
83+
}/${maxRetries})`,
84+
);
85+
86+
await new Promise((resolve) => setTimeout(resolve, delay));
7987
return tgCall(options, endpoint, retryCount + 1);
8088
}
81-
89+
8290
if (!resp.ok) {
8391
console.log("Req to", endpoint, "with", options, "failed:", resp);
8492
}
@@ -87,9 +95,13 @@ async function tgCall(
8795
// Handle network errors with exponential backoff
8896
if (retryCount < maxRetries) {
8997
const delay = baseDelay * Math.pow(2, retryCount);
90-
console.log(`Network error on ${endpoint}. Retrying in ${delay}ms (attempt ${retryCount + 1}/${maxRetries})`);
91-
92-
await new Promise(resolve => setTimeout(resolve, delay));
98+
console.log(
99+
`Network error on ${endpoint}. Retrying in ${delay}ms (attempt ${
100+
retryCount + 1
101+
}/${maxRetries})`,
102+
);
103+
104+
await new Promise((resolve) => setTimeout(resolve, delay));
93105
return tgCall(options, endpoint, retryCount + 1);
94106
}
95107
}
@@ -110,7 +122,8 @@ async function domeny() {
110122
.map((x) => x.item_title);
111123
list.sort();
112124
list.sort((a, b) => a.length - b.length);
113-
list = list.filter((x) => x.length <= 8).concat(list.slice(-20));
125+
list = list.filter((x) => x.length <= 8 && !(/^[0-9]{4,8}\.cz$/.test(x)))
126+
.concat(list.slice(-20));
114127
console.log(list);
115128
while (list.length > 0) {
116129
const chunk = list.splice(0, 50);

0 commit comments

Comments
 (0)