alpha
Login
or
Join now
ewancroft.uk
/
bluesky-awoo-bot
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
This repository has no description
Star
0
Fork
0
Atom
Configure Feed
Issues
Pull Requests
Commits
Tags
Feed URL
Select the types of activity you want to include in your feed.
Overview
Issues
Pulls
Pipelines
adjusted the time logic
author
Ewan Croft
date
2 years ago
(May 23, 2024, 8:26 PM +0100)
commit
1e916059
1e916059b82e965763ff9af48f88fc14ca3c2155
parent
6aaf7a9a
6aaf7a9aee083093e4f24541321e1eafba17934a
+20
-7
1 changed file
Expand all
Collapse all
Unified
Split
src
index.ts
+20
-7
src/index.ts
Reviewed
···
67
67
const minDelaySeconds = minHours * 60 * 60;
68
68
const maxDelaySeconds = maxHours * 60 * 60;
69
69
70
70
-
// Generate a random number within the desired range (inclusive)
71
71
-
const randomDelay =
72
72
-
Math.floor(Math.random() * (maxDelaySeconds - minDelaySeconds + 1)) +
73
73
-
minDelaySeconds;
70
70
+
let randomDelay;
71
71
+
do {
72
72
+
// Generate a random number within the desired range (inclusive)
73
73
+
randomDelay =
74
74
+
Math.floor(Math.random() * (maxDelaySeconds - minDelaySeconds + 1)) +
75
75
+
minDelaySeconds;
76
76
+
} while (randomDelay < minDelaySeconds || randomDelay > maxDelaySeconds);
74
77
75
78
return randomDelay;
76
79
}
···
82
85
83
86
// Calculate a random delay before the next iteration
84
87
const delay = getRandomDelay();
85
85
-
console.log(
86
86
-
`Next post scheduled in approximately ${(delay / 3600).toFixed(2)} hours.`
87
87
-
);
88
88
+
89
89
+
// Calculate delay in whole hours and minutes
90
90
+
const hours = Math.floor(delay / 3600); // Use 3600 for hours
91
91
+
const minutes = Math.floor((delay % 3600) / 60); // Calculate remaining minutes
92
92
+
93
93
+
// Format the delay string with hours and minutes (no decimals)
94
94
+
const formattedDelay = `${
95
95
+
hours > 0 ? hours + " hour" + (hours > 1 ? "s" : "") : ""
96
96
+
}${hours > 0 && minutes > 0 ? " " : ""}${
97
97
+
minutes > 0 ? minutes + " minute" + (minutes > 1 ? "s" : "") : ""
98
98
+
}`;
99
99
+
100
100
+
console.log(`Next post scheduled in approximately ${formattedDelay}.`);
88
101
89
102
// Wait for the random delay
90
103
await new Promise((resolve) => setTimeout(resolve, delay * 1000));