-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (44 loc) · 1.28 KB
/
index.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
41
42
43
44
45
46
47
48
// Get packages and register secrets
const Twit = require('twit');
const T = new Twit({
consumer_key: process.env['consumer_key'],
consumer_secret: process.env['consumer_secret'],
access_token: process.env['access_token'],
access_token_secret: process.env['access_token_secret']
});
// Make tweet function (so you can set it at an interval)
function tweet() {
// Add current time to workaround duplicate status error
let t = new Date();
T.post('statuses/update', { status:
`As of ${("0" + t.getHours()).slice(-2)}:00 UTC:
MOON: Still there
SUN: Still there
STARS: Still there
PLANETS: Still there
GALAXIES: Still there`
}, callback);
}
// Set to tweet every 3 hours
setInterval(tweet, 3*60*60*1000);
// Do the first tweet
tweet();
// Make callback function
function callback(err, data, response) {
if (err) {
console.log(err);
} else {
// Get date and time
let t = new Date();
let o = {
m: ("0" + (t.getMonth() + 1)).slice(-2),
d: ("0" + t.getDate()).slice(-2),
y: t.getFullYear(),
h: ("0" + t.getHours()).slice(-2),
mi: ("0" + t.getMinutes()).slice(-2),
s: ("0" + t.getSeconds()).slice(-2)
}
let s = `${o.m}/${o.d}/${o.y} ${o.h}:${o.mi}:${o.s}`;
console.log(`Updated board at ${s}`);
}
};