Merge pull request 'Improve Mastodon profile link detection' (#11) from rompe/MastodonBot:10-improve_mastodon_profile_link_detection into main

Reviewed-on: #11
Reviewed-by: Pieter Vander Vennet <pietervdvn@posteo.net>
This commit is contained in:
Pieter Vander Vennet 2025-08-25 22:45:06 +00:00
commit 3796364f79
2 changed files with 24 additions and 13 deletions

View file

@ -187,15 +187,13 @@ ${text.split("\n").map(txt => " > " + txt).join("\n")}`)
}
private static notMastodon = ["wiki.openstreetmap.org", "hdyc.neis-one.org", "matrix.to","facebook.com","github", "tasks.hotosm.org","community.openstreetmap.org","mapillary.com","wikimedia.org","wikipedia.org","wikidata.org"]
private static isMastodon = ["en.osm.town", ".social", "mstdn", "mastodon", "mapstodon","masto"]
// Fediverse profiles look like this:
// Mastodon, Akkoma, etc.: https://foo.bar/@user
// Friendica: https://foo.bar/profile/user
// Pixelfed, Pleroma: https://foo.bar/user
private static isProbablyMastodon = new RegExp(`^https?://(?!.*(?:${MastodonPoster.notMastodon.join('|')}))[a-zA-Z0-9.-]+/(profile/|@?)[a-zA-Z0-9_.-]+/?$`)
static isProbablyMastodonLink(link: string) {
if (this.isMastodon.some(white => link.indexOf(white) >= 0)) {
return true
}
if (this.notMastodon.some(black => link.indexOf(black) >= 0)) {
return false
}
return true; // probably?
return this.isProbablyMastodon.test(link)
}
}
}

View file

@ -3,10 +3,23 @@ import MastodonPoster from "./Mastodon";
console.log("Hello world")
const uids = [
1214300, // tornooc
4685130, // contrapunctus
8404193, // queerthoughts
153277, // rompe
393359, // hector
14124839, // ilja has a Pleroma link
]
new OsmUserInfo(1214300).getMeLinks().then(links => {
console.log("Got links:", links);
for (const uid of uids) {
new OsmUserInfo(uid).getMeLinks().then((links) => {
console.log("Got links for uid", uid, ":", links);
for (const link of links) {
console.log(link, MastodonPoster.isProbablyMastodonLink(link) ? "Mastodon" : "NOT mastodon")
console.log(
link,
MastodonPoster.isProbablyMastodonLink(link) ? "Mastodon" : "NOT mastodon"
);
}
})
});
}