fix optional callback

master
adb 3 years ago
parent 981d62c6f0
commit ac689911ac

@ -11,22 +11,22 @@ export class mastodonMemeBot {
access_token: config.accessToken, access_token: config.accessToken,
}); });
} }
postRandomMeme(callback = undefined) { postRandomMeme(callback = () => {}) {
this.memeHandler.getRandomMeme(sub => { this.memeHandler.getRandomMeme(sub => {
let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`; let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`;
if (!this.allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())) { if (!this.allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())) {
console.log("no valid media, fetching new sub"); console.log("no valid media, fetching new sub");
this.postRandomMeme(callback??undefined); this.postRandomMeme(callback);
return; return;
} }
let filepath = `./media/${sub.url.split(/[/]+/).pop()}`; let filepath = `./media/${sub.url.split(/[/]+/).pop()}`;
if (getStat(filepath) === true) { if (getStat(filepath) === true) {
console.log("post already exists, fetching new sub"); console.log("post already exists, fetching new sub");
this.postRandomMeme(callback??undefined); this.postRandomMeme(callback);
return; return;
} }
this.memeHandler.downloadMedia(sub.url, filepath, () => { this.memeHandler.downloadMedia(sub.url, filepath, () => {
this.client.postMedia(status, filepath, 5, () => this.postRandomMeme(), callback??undefined); this.client.postMedia(status, filepath, 5, () => this.postRandomMeme(), callback);
}) })
}) })
} }

Loading…
Cancel
Save