only post media content

master
adb 4 years ago
parent 50d1dd7e17
commit c9bc576a15

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

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

Loading…
Cancel
Save