wholeword instead of include
This commit is contained in:
parent
df406d2a52
commit
d6d83eea4a
1 changed files with 7 additions and 13 deletions
|
@ -11,27 +11,21 @@ export class FirehoseSubscription extends FirehoseSubscriptionBase {
|
||||||
|
|
||||||
const ops = await getOpsByType(evt)
|
const ops = await getOpsByType(evt)
|
||||||
|
|
||||||
// Test only
|
|
||||||
// for (const post of ops.posts.creates) {
|
|
||||||
// console.log('DEBUG: New Post')
|
|
||||||
// console.log('DEBUG: Author', post.author)
|
|
||||||
// console.log('DEBUG: Text', post.record.text)
|
|
||||||
// console.log('DEBUG: Tags', post.record.tags)
|
|
||||||
// }
|
|
||||||
|
|
||||||
const postsToDelete = ops.posts.deletes.map((del) => del.uri)
|
const postsToDelete = ops.posts.deletes.map((del) => del.uri)
|
||||||
const postsToCreate = ops.posts.creates
|
const postsToCreate = ops.posts.creates
|
||||||
.filter((create) => {
|
.filter((create) => {
|
||||||
const text = create.record.text.toLowerCase()
|
const text = create.record.text.toLowerCase()
|
||||||
const tags = create.record.tags?.map(tag => tag.toLowerCase()) || []
|
|
||||||
const author = create.author || ''
|
const author = create.author || ''
|
||||||
|
|
||||||
|
const wordBoundaryRegex = (word: string) => new RegExp(`\\b${word}\\b`, 'i')
|
||||||
|
|
||||||
return (
|
return (
|
||||||
keywords.some(keyword => text.includes(keyword)) ||
|
keywords.some(keyword => wordBoundaryRegex(keyword).test(text)) ||
|
||||||
|
keywords.some(keyword => text.includes('#' + keyword)) ||
|
||||||
users.includes(author) ||
|
users.includes(author) ||
|
||||||
bandMembers.some(member => text.includes(member)) ||
|
bandMembers.some(member => wordBoundaryRegex(member).test(text)) ||
|
||||||
albums.some(album => text.includes(album)) ||
|
albums.some(album => wordBoundaryRegex(album).test(text)) ||
|
||||||
songs.some(song => text.includes(song))
|
songs.some(song => wordBoundaryRegex(song).test(text))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.map((create) => {
|
.map((create) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue