only post media content

master
adb 4 years ago
parent 50d1dd7e17
commit c9bc576a15

@ -15,7 +15,7 @@ tokenHandler.getAccessToken((accessToken) => {
access_token: accessToken,
});
let memeHandler = new MemeHandler(memeAPI, subreddits, allowedMedia);
executeAndSetInterval(() => {
executeAndSetInterval(function postRandomMeme(){
memeHandler.getRandomMeme(sub => {
let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`;
if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){
@ -24,7 +24,8 @@ tokenHandler.getAccessToken((accessToken) => {
client.postMedia(status, filepath);
})
}else{
client.postStatus(status);
console.log("no valid media, fetching new sub")
postRandomMeme();
}
})
}, interval);

@ -11,6 +11,8 @@ export class MemeHandler{
getRandomMeme(callback){
this.request(this.memeAPI+this.randomFromArray(this.subreddits), (res) => {
let sub = this.randomFromArray(res.subs);
console.log("got sub => ");
console.log(sub)
callback(sub);
});
}
@ -18,6 +20,7 @@ export class MemeHandler{
const request = https.get(url, (res) => {
res.pipe(fs.createWriteStream(filepath));
res.on('end', () => {
console.log(`downloaded media => ${filepath}`);
callback();
})
});

Loading…
Cancel
Save