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:
commit
3796364f79
2 changed files with 24 additions and 13 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
21
src/test.ts
21
src/test.ts
|
@ -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"
|
||||
);
|
||||
}
|
||||
})
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue