-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
75 lines (62 loc) · 2.79 KB
/
index.js
File metadata and controls
75 lines (62 loc) · 2.79 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
const http = require('http');
const PORT = 3000;
const checker = require('ikea-availability-checker');
const https = require('request');
var lastStockChange = null;
var lastProbabilityChange = null;
var lastRestockChange = null;
var stockInterval = null;
var lastCheckedAt = null;
var runOnce = false;
async function checkStock() {
const result = await checker.availability('004', '79017837');
if (lastStockChange === null) lastStockChange = result.stock;
if (lastProbabilityChange === null) lastProbabilityChange = result.probability;
if (lastRestockChange === null) lastRestockChange = result.restockDate;
lastCheckedAt = new Date().toLocaleString('en-US', { timeZone: 'America/New_York' });
if (result.stock !== lastStockChange || result.probability !== lastProbabilityChange) {
let daMessage = `stock chang from ${lastStockChange} to ${result.stock}, probability change from ${lastProbabilityChange} to ${result.probability}, restock from ${lastRestockChange} to ${result.restockDate}`;
lastStockChange = result.stock;
lastProbabilityChange = result.probability;
lastRestockChange = result.restockDate;
sendDaMessage(daMessage);
console.log(daMessage);
if (runOnce) clearInterval(stockInterval);
return;
}
console.log(result.stock, result.probability, result.restockDate);
//console.log('RESULT', result);
//setTimeout(checkStock, 1000*10);
}
function sendDaMessage(daChanges) {
https.post(
'https://discord.com/api/webhooks/1151708354650054708/ugxYceuJrLyZTBF5MkXrxhy1DDdRKKWAW9khdTJaw-_kVDo7Q8ory3s-Ccl4-4_sy6GR',
{ json: { content: 'somethin in da stock change <@&878330216156631071> : ' + daChanges, username: 'hyper x furniture x naruto' } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
function startup() {
https.post(
'https://discord.com/api/webhooks/1151708354650054708/ugxYceuJrLyZTBF5MkXrxhy1DDdRKKWAW9khdTJaw-_kVDo7Q8ory3s-Ccl4-4_sy6GR',
{ json: { content: 'YO WAT UP NARUTO B HERE', username: 'hyper x furniture x naruto' } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
}
);
}
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end(`stock: ${lastStockChange} probability: ${lastProbabilityChange} restock: ${lastRestockChange}, as of ${lastCheckedAt}`);
});
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}/`);
});
startup();
stockInterval = setInterval(checkStock, 1000*30);