1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-21 12:34:19 +00:00

Add some Filters

This commit is contained in:
Steffo 2021-05-20 19:48:33 +02:00
parent eebedebe5e
commit 98bfb71d00
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -0,0 +1,62 @@
export class Filter {
constructor() {
}
exec(tweet) {
return true
}
}
export class ContainsFilter extends Filter {
word
constructor(word) {
super()
this.word = word.toLowerCase().trim()
}
exec(tweet) {
return tweet.content?.toLowerCase().includes(this.word)
}
}
export class UserFilter extends Filter {
user
constructor(user) {
super()
this.user = user.toLowerCase().trim().replace(/^@/, "")
}
exec(tweet) {
return tweet.poster.toLowerCase() === this.user
}
}
export class HasLocationFilter extends Filter {
hasLocation
constructor(hasLocation) {
super()
this.hasLocation = hasLocation
}
exec(tweet) {
return (tweet["location"] !== null) === this.hasLocation
}
}
export class HasPlaceFilter extends Filter {
hasPlace
constructor(hasPlace) {
super()
this.hasPlace = hasPlace
}
exec(tweet) {
return (tweet["place"] !== null) === this.hasPlace
}
}