Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
48 lines (40 loc) · 1.47 KB
/
Copy pathindex.js
File metadata and controls
48 lines (40 loc) · 1.47 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
const Twit = require('twit');
const config = require('./config.json');
const axios = require('axios');
const T = new Twit(config);
const stream = T.stream('user', { stringify_friend_ids: true });
stream.on('tweet', tweet => {
if(tweet.user.id_str === config.account_id) return;
if(tweet.retweeted_status) return;
if (tweet.entities.media) {
const media = tweet.entities.media
.filter(m => m.type === 'photo');
const body = media.map(m => ([
{type: 'panorama', src :`${m.media_url_https}:large`},
{type: 'duration', value: media.length === 1 ? 5000 : 10},
]));
if (body.length) {
axios.post('https://gurivr.com/api/stories', {
title: 'GuriVR - Twitter',
body: body
}).then(res => {
T.post('statuses/update', {in_reply_to_status_id: tweet.id_str , status: `@${tweet.user.screen_name} your scene is here https://s3.amazonaws.com/gurivr/s/${res.data._id}.html` }, function(err, data, response) {});
});
}
} else {
axios.post('https://gurivr.com/api/stories', {
title: 'GuriVR - Twitter',
text: tweet.text,
store: false
}).then(res => {
if (res.data.length) {
axios.post('https://gurivr.com/api/stories', {
title: 'GuriVR - Twitter',
text: tweet.text
}).then(res => {
T.post('statuses/update', {in_reply_to_status_id: tweet.id_str , status: `@${tweet.user.screen_name} your scene is here https://s3.amazonaws.com/gurivr/s/${res.data._id}.html` }, function(err, data, response) {});
});
}
});
}
});