Handle replies
This commit is contained in:
parent
756193c021
commit
db6bf23fb5
12
index.mjs
12
index.mjs
@ -152,7 +152,7 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
text = text.replace(/@([^ ]+) \(http[s]?:\/\/([^\/]+)[^\)]+\)/g, '@$1@$2');
|
text = text.replace(/@([^ ]+) \(http[s]?:\/\/([^\/]+)[^\)]+\)/g, '@$1@$2');
|
||||||
// TODO: Strip hashtag urls #tag (http://url)
|
text = text.replace(/(#[^ #]+) \(http[s]?:\/\/[^\)]+\)/g, '$1');
|
||||||
text = await replaceAsync(text, /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g, async (url) => {
|
text = await replaceAsync(text, /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/g, async (url) => {
|
||||||
if (url.length < 40){
|
if (url.length < 40){
|
||||||
return url;
|
return url;
|
||||||
@ -160,7 +160,14 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|||||||
let r = await axios.get(`https://ulvis.net/api.php?url=${url}`);
|
let r = await axios.get(`https://ulvis.net/api.php?url=${url}`);
|
||||||
return r.data?r.data:url;
|
return r.data?r.data:url;
|
||||||
|
|
||||||
})
|
});
|
||||||
|
if (status.mentions > 0 && status.in_reply_to_id !== null){
|
||||||
|
// Post is a reply
|
||||||
|
const replyTo = [...status.mentions].filter((mention) => mention.id === status.in_reply_to_account_id);
|
||||||
|
if (replyTo.length > 0){
|
||||||
|
text = `Reply to: ${replyTo[0].url}/@${replyTo[0].acct}/${status.in_reply_to_id}\n${text}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (text.length > 300 && status.url.length < 300){
|
if (text.length > 300 && status.url.length < 300){
|
||||||
text = `${text.slice(0, -1 * (status.url.length + 4))}...\n${status.url}`;
|
text = `${text.slice(0, -1 * (status.url.length + 4))}...\n${status.url}`;
|
||||||
}
|
}
|
||||||
@ -179,7 +186,6 @@ client.get(`/accounts/${process.env.MASTODON_ID}/statuses`, {
|
|||||||
}
|
}
|
||||||
bskyPost(text, medias);
|
bskyPost(text, medias);
|
||||||
appendFileSync(historyFile, `\n${status.id}`);
|
appendFileSync(historyFile, `\n${status.id}`);
|
||||||
// TODO: Rempve temp files
|
|
||||||
} else {
|
} else {
|
||||||
console.log(`ERROR: ${status.url} is too long and unable to be reposted`);
|
console.log(`ERROR: ${status.url} is too long and unable to be reposted`);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user