no duplicate posts

master
adb 4 years ago
parent ef17b4467c
commit 5f0af3d66f

@ -14,4 +14,11 @@ export function loadData(path) {
console.error(err)
return false
}
}
export function getStat(path) {
fs.stat(path, (err, stat) => {
if(err == null) return true;
else if(err.code === 'ENOENT') return false;
else return err.code;
});
}

@ -1,6 +1,7 @@
import {MastodonHandler} from "./mastodonHandler.js";
import {MastodonTokenHandler} from "./mastodonTokenHandler.js";
import {MemeHandler} from "./memeHandler.js";
import {getStat} from "./JSONdataStore";
const baseUrl = "https://social.cybre.town";
const memeAPI = "http://redditapi.adb.sh/api/v1/";
@ -20,6 +21,7 @@ await tokenHandler.getAccessToken((accessToken) => {
let status = `"${sub.title}"\n${sub.text}\nby ${sub.author}`;
if (allowedMedia.find(type => type === sub.url.split(/[.]+/).pop())){
let filepath = `./media/${sub.url.split(/[/]+/).pop()}`;
if (getStat(filepath)===true){ postRandomMeme(); return; }
memeHandler.downloadMedia(sub.url, filepath, () => {
client.postMedia(status, filepath, 5, () => postRandomMeme());
})

Loading…
Cancel
Save