-
Notifications
You must be signed in to change notification settings - Fork 42
/
cats.ts
102 lines (83 loc) · 2.48 KB
/
cats.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { QueryParams } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
import { AppContext } from '../config'
import { AlgoManager } from '../addn/algoManager'
import dotenv from 'dotenv'
import { Post } from '../db/schema'
import dbClient from '../db/dbClient'
dotenv.config()
// max 15 chars
export const shortname = 'cats'
export const handler = async (ctx: AppContext, params: QueryParams) => {
const builder = await dbClient.getLatestPostsForTag({
tag: shortname,
limit: params.limit,
cursor: params.cursor,
mediaOnly: true,
nsfwOnly: false,
excludeNSFW: true,
})
let feed = builder.map((row) => ({
post: row.uri,
}))
let cursor: string | undefined
const last = builder.at(-1)
if (last) {
cursor = `${new Date(last.indexedAt).getTime()}::${last.cid}`
}
return {
cursor,
feed,
}
}
export class manager extends AlgoManager {
public name: string = shortname
public re =
/^(?!.*((\b(cat( |-)girl|cat( |-)ears|cat( |-)suit|fursona|nsfw|cat-like|furryart|doja|dojacat|anthro|anthropomorphic)\b)|#furry|#furryart|fursuit)).*\b(cat|cats|catsofbluesky|kitty|kitten|kitties)\b.*$/ims
public async periodicTask() {
await this.db.removeTagFromOldPosts(
this.name,
new Date().getTime() - 7 * 24 * 60 * 60 * 1000,
)
}
public async filter_post(post: Post): Promise<Boolean> {
if (
[
'did:plc:mcb6n67plnrlx4lg35natk2b',
'did:plc:2rhj4c7tzussdmfcrtlerr7b',
'did:plc:hw7t2navoastix67wjzrmvof',
].includes(post.author)
)
return false
if (post.replyRoot !== null) return false
if (this.agent === null) {
await this.start()
}
if (this.agent === null) return false
let return_value: Boolean | undefined = undefined
let match = false
let matchString = ''
if (post.embed?.images) {
const imagesArr = post.embed.images
imagesArr.forEach((image) => {
matchString = `${matchString} ${image.alt}`.replace('\n', ' ')
})
}
if (post.embed?.alt) {
matchString = `${matchString} ${post.embed.alt}`.replace('\n', ' ')
}
if (post.embed?.media?.alt) {
matchString = `${matchString} ${post.embed?.media?.alt}`.replace(
'\n',
' ',
)
}
if (post.tags) {
matchString = `${post.tags.join(' ')} ${matchString}`
}
matchString = `${post.text} ${matchString}`.replace('\n', ' ')
if (matchString.match(this.re) !== null) {
match = true
}
return match
}
}