forked from bluesky-social/feed-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubscription.ts
213 lines (199 loc) · 5.43 KB
/
subscription.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import {
OutputSchema as RepoEvent,
isCommit,
} from './lexicon/types/com/atproto/sync/subscribeRepos'
import { FirehoseSubscriptionBase, getOpsByType } from './util/subscription'
// main problem to get around: the slang use of 'speedrun' to denote doing something unrelated to speedrunning fast
// ex. Lowtax speedrun, christmas shopping speedrun, etc
const matchText: string[] = [
// obvious
' #speedrun',
' #speedrunner',
// events
' agdq',
'arpgme',
'benelux speedrunner gathering',
'bsg annual',
'esa winter',
'esa summer',
'fastest furs',
'finnruns',
'games done quick',
'gamesdonequick',
' #gdq',
' gdq',
'interglitches',
'lady arcaders',
'midspring speedfling',
'midwest speedfest',
'obscurathon',
'power up with pride',
'prevent a thon',
'really really long a thon',
'really really lots of lore',
'rtainjapan',
'#rtain',
' sgdq',
'soaringspeedfest',
'speedfest',
'speedons',
// speedrun + 'word'
'speedrun marathon',
'speedrun mode',
'speedrun practice',
'speedrun training',
'speedrun routing',
'speedrun stream',
// 'word' + speedrun
'first speedrun',
// bluesky (test; disable in release)
//'bluesky',
]
const bannedText: string[] = [
// obvious
' nsfw ',
'#nsfw',
' anal ',
' anus ',
' ballsack ',
' biatch ',
' blowjob ',
' blow job ',
' bollock ',
' bollok ',
' boner ',
' boob ',
' bum ',
' butt ',
' buttplug ',
' clitoris ',
' cock ',
' coon ',
' cunt ',
' dick ',
' dildo ',
' dyke',
' fag ',
' feck ',
' fellate ',
' fellatio ',
' felching ',
' fudgepacker ',
' fudge packer ',
' hell ',
' homo ',
' jizz ',
' knobend ',
' knob end ',
' labia ',
' muff ',
' nigger ',
' nigga ',
' penis ',
' piss ',
' poop ',
' prick ',
' pube ',
' pussy ',
' scrotum ',
' slut ',
' smegma ',
' spunk ',
' tosser ',
' turd ',
' twat ',
' vagina ',
' wank ',
' whore ',
]
const matchPatterns: RegExp[] = [
//SRC
/(^|[\s\W])speedrun\.com($|[\W\s])/im,
//oengus
/(^|[\s\W])oengus\.io($|[\W\s])/im,
//oengus short urls
/(^|[\s\W])oengus\.fun($|[\W\s])/im,
//horaro
/(^|[\s\W])horaro\.org($|[\W\s])/im,
//'speedrun' AND a link to twitch.tv
/speedrun[\s\S]*?twitch.tv/im,
//'speedrun' AND a link to youtube
/speedrun($|.*)youtu.be/im,
//'speedrun' AND 'pb'
/(^|[\s\W])speedrun($|.*)pb($|[\W\s])/im,
//'pb' AND 'speedrun'
/(^|[\s\W])pb($|.*)speedrun($|[\W\s])/im,
//twitch.tv/gamesdonequick
/twitch\.tv\/gamesdonequick/im,
//'really really' AND a link to twitch.tv
/really really($|.*)twitch.tv/im,
]
// these users ONLY talk about speedrunning - scheduler bots, etc
const matchUsers: string[] = [
'did:plc:rqbyxmhdeyjsygglwxkhwnlb', // bigbadgameathon.bsky.social
'did:plc:sucjrnduu3iytwhtt36g2d54', // gamesdonequick.bsky.social
'did:plc:i52rffe5ktfyfgiunsirz7ge', // ladyarcaders.com
'did:plc:zsk2ehpsgci254k3r3czqcpe', // pixelperfectevents.bsky.social
'did:plc:q7ecflq2zteowyqgysmstb2e', // powerupwithpride.bsky.social
'did:plc:yggbmd27ii4z3cpgpabaa2gn', // preventathon.bsky.social
'did:plc:x6b5kfl6bnrgplbentbei6mg', // therpgvalkyries.bsky.social
'did:plc:pz54re7np33stvrgz4bj6nbl', // rtajapan.bsky.social
'did:plc:mfmbxqdlvkunpb2i2rwdtvhn', // therun.bsky.social
'did:plc:275rmae3bc63ib5pcsmmtw5d', // fastestfurs.com
'did:plc:5f3tjhknxvpmjt2mazg7n57g', // bsgmarathon.bsky.social
]
// Exclude posts from these users
const bannedUsers: string[] = [
'did:plc:23thhiqwpowmlelje4ft76br', // gam1ng.bsky.social (bot content)
'did:plc:25vwhhzdpnaujzookpsqxlns', // lpx.bsky.social (low effort content)
]
export class FirehoseSubscription extends FirehoseSubscriptionBase {
async handleEvent(evt: RepoEvent) {
if (!isCommit(evt)) return
const ops = await getOpsByType(evt)
const postsToDelete = ops.posts.deletes.map((del) => del.uri)
const postsToCreate = ops.posts.creates
.filter((create) => {
const txt = create.record.text.replace('-', ' ').toLowerCase()
// cannot get TS to work with create.record.labels - fix later
const plainTextLabels = JSON.stringify(create.record.labels ?? '{}')
const postIsNsfw =
plainTextLabels.includes('porn') ||
plainTextLabels.includes('nudity') ||
plainTextLabels.includes('sexual')
return (
(matchText.some((term) => txt.includes(term)) ||
matchPatterns.some((pattern) => pattern.test(txt)) ||
matchUsers.includes(create.author)) &&
!bannedUsers.includes(create.author) &&
!bannedText.some((term) => txt.includes(term)) &&
!postIsNsfw
)
}) // validation function
.map((create) => {
// map speedrun related posts to a db row
console.log(`Found post by ${create?.author}: ${create?.record?.text}`)
//console.log(JSON.stringify(create))
return {
uri: create.uri,
cid: create.cid,
replyParent: create.record?.reply?.parent.uri ?? null,
replyRoot: create.record?.reply?.root.uri ?? null,
indexedAt: new Date().toISOString(),
}
})
if (postsToDelete.length > 0) {
await this.db
.deleteFrom('post')
.where('uri', 'in', postsToDelete)
.execute()
}
if (postsToCreate.length > 0) {
await this.db
.insertInto('post')
.values(postsToCreate)
.onConflict((oc) => oc.doNothing())
.execute()
}
}
}