-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainWork.js
40 lines (38 loc) · 1.46 KB
/
mainWork.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/* eslint-disable no-await-in-loop */
/* eslint-disable no-restricted-syntax */
import { getStats, getDb, sendMessage, isValidTrigger, MESSAGE_TYPE } from './util';
export const mainWork = async (client, interaction) => {
const db = getDb();
const collections = db.getData('/collections') || [];
const pQueue = [];
const alertOriginIndex = [];
const alertCollections = collections.filter((collection, index) => {
const now = new Date().getTime();
const { lastAlertStamp='', name } = collection;
const isValid = isValidTrigger(lastAlertStamp, now);
if (isValid) {
pQueue.push(getStats(name));
alertOriginIndex.push(index);
}
return isValid;
});
const alertCollectionsStats = await Promise.all(pQueue);
for (const [index, stats] of alertCollectionsStats.entries()) {
const { name, price } = alertCollections[index];
const now = new Date().getTime();
const { floor_price: floorPrice } = stats;
db.push(`/collections[${alertOriginIndex[index]}]`, {
...alertCollections[index],
lastAlertStamp: now,
});
if (floorPrice <= price) {
sendMessage(
client,
interaction,
`@everyone ${name} just hit a floor price of ${price}! \n https://opensea.io/collection/${name}`,
MESSAGE_TYPE.INFO,
'Wow! Wow! Wow!',
);
}
}
};