-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
47 lines (42 loc) · 1.47 KB
/
bot.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
const twit = require('twit')
const axios = require('axios')
const config = require('./config.js')
const fs = require('fs')
const he = require('he')
const T = new twit(config)
function postPlugged() {
const b64content = fs.readFileSync('./img/plugged.jpg', { encoding: 'base64' })
axios({
method: 'get',
url: config.quotes_api
}).then((response) => {
let quote = he.decode(response.data[0].content.replace('<p>','').replace('</p>','').replace('\n',''))
T.post('media/upload', { media_data: b64content }, (err, data, response) => {
let mediaIdStr = data.media_id_string
let meta_params = { media_id: mediaIdStr, alt_text: { text: "Plugged." }}
if (err) {
console.error(err);
} else {
T.post('media/metadata/create', meta_params, (err, data, response) => {
if (!err) {
let params = { status: quote, media_ids: [mediaIdStr] }
T.post('statuses/update', params, (err, data, response) => {
console.log(`[${new Date}]: Succes !`)
})
} else {
console.error(err);
}
})
}
})
}).catch((err) => {
console.error(err)
})
}
setTimeout(() => {
let d = new Date()
let h = d.getHours()
if (h === 13) {
postPlugged()
}
}, 3600000)