-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitch.js
30 lines (23 loc) · 827 Bytes
/
twitch.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
const Twitch = require('twitch-api-v5');
const config = require("./config.json");
Twitch.clientID = config.clientId;
//find stream by userName and create post
module.exports.twitchStreamFunc = (userName) => {
//find channel by name
return new Promise((resolve, reject) => {
Twitch.users.usersByName({users:userName}, (err,data) => {
if(data.error || err) {
return reject(err);
}
user = data.users.shift();
//find channel by userId
Twitch.streams.channel({channelID: user._id}, (err, data) => {
if (data.error || err) {
return reject(err);
}
stream = data.stream;
return resolve(stream);
})
});
});
}