-
Notifications
You must be signed in to change notification settings - Fork 42
/
18-plus-nd.ts
76 lines (61 loc) · 1.75 KB
/
18-plus-nd.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
import { QueryParams } from '../lexicon/types/app/bsky/feed/getFeedSkeleton'
import { AppContext } from '../config'
import { AlgoManager } from '../addn/algoManager'
import { BskyAgent } from '@atproto/api'
import dotenv from 'dotenv'
import { Post } from '../db/schema'
import dbClient from '../db/dbClient'
import getUserDetails from '../addn/getUserDetails'
dotenv.config()
// max 15 chars
export const shortname = '18-plus-nd'
export const handler = async (ctx: AppContext, params: QueryParams) => {
const builder = await dbClient.getLatestPostsForTag(
shortname,
params.limit,
params.cursor,
)
const 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 =
/(?=.*(🔞|18\+|nsfw|mdni|minors dni))(?=.*\b(autistic|autism|nd|neurodivergent|adhd|audhd|autigender|bpd|neurodistinct)\b)/ims
public async periodicTask() {
await this.db.removeTagFromOldPosts(
this.name,
new Date().getTime() - 7 * 24 * 60 * 1000,
)
}
public async filter_post(post: Post): Promise<Boolean> {
if (this.agent === null) {
await this.start()
}
if (this.agent === null) return false
let return_value: Boolean | undefined = undefined
let match = false
const details = await getUserDetails(post.author, this.agent)
if (
`${details.displayName} ${details.description}`.match(this.re) !== null
) {
match = true
}
if (match) {
return_value = true
} else {
return_value = false
}
return return_value
}
}