File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ const env = z.object({
15
15
discordPrivatePostsChannelId : z . string ( ) ,
16
16
redisHost : z . string ( ) ,
17
17
restorePostsUsername : z . string ( ) . optional ( ) ,
18
+ bannedKeywords : z . array ( z . string ( ) ) . min ( 1 ) ,
18
19
} )
19
20
20
21
export const ENV = env . parse ( {
@@ -24,4 +25,5 @@ export const ENV = env.parse({
24
25
discordPrivatePostsChannelId : process . env . DISCORD_PRIVATE_POSTS_CHANNEL_ID ,
25
26
redisHost : process . env . REDIS_HOST ,
26
27
restorePostsUsername : process . env . RESTORE_POSTS_USERNAME ,
28
+ bannedKeywords : process . env . BANNED_KEYWORDS ?. split ( ',' ) ,
27
29
} )
Original file line number Diff line number Diff line change 10
10
"private:posts" : " pnpm env:copy -e development && ts-node ./scripts/privatePostsOfSpamAccount.mts" ,
11
11
"check:gql" : " pnpm prisma:copy && pnpm env:copy -e development && ts-node ./scripts/checkGql.mts" ,
12
12
"restore:posts" : " pnpm env:copy -e development && pnpm prisma:copy && ts-node ./scripts/restorePosts.mts" ,
13
+ "add:bannedKeyword" : " pnpm env:copy -e development && pnpm prisma:copy && ts-node ./scripts/addBannedKeywords.mts" ,
13
14
"env:copy" : " tsx ./scripts/copyEnv.ts" ,
14
15
"prisma:copy" : " tsx ./scripts/copyPrisma.ts" ,
15
16
"build" : " tsc" ,
Original file line number Diff line number Diff line change
1
+ import 'reflect-metadata'
2
+ import { ENV } from '../env/env.mjs'
3
+ import { DbService } from '../lib/db/DbService.mjs'
4
+ import { container , injectable , singleton } from 'tsyringe'
5
+ import { RedisService } from '../lib/redis/RedisService.mjs'
6
+
7
+ @singleton ( )
8
+ @injectable ( )
9
+ class Runner {
10
+ constructor ( private readonly db : DbService ) { }
11
+ public async run ( bannedKeywords : string [ ] ) {
12
+ const data = bannedKeywords . map ( ( value ) => ( {
13
+ value,
14
+ type : 'banned' ,
15
+ } ) )
16
+
17
+ try {
18
+ await this . db . dynamicConfigItem . createMany ( {
19
+ data,
20
+ } )
21
+ } catch ( error ) {
22
+ console . log ( error )
23
+ }
24
+ }
25
+ }
26
+
27
+ ; ( async function ( ) {
28
+ const bannedKeywords = ENV . bannedKeywords
29
+ if ( ! bannedKeywords ) {
30
+ throw new Error ( 'No banned keywords' )
31
+ }
32
+
33
+ const runner = container . resolve ( Runner )
34
+ runner . run ( bannedKeywords )
35
+ } ) ( )
You can’t perform that action at this time.
0 commit comments