Skip to content

Commit 05cb5ed

Browse files
committed
feat: update private posts script
1 parent e2c422c commit 05cb5ed

File tree

4 files changed

+38
-10
lines changed

4 files changed

+38
-10
lines changed

packages/velog-scripts/env/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ DATABASE_URL=
22
DISCORD_BOT_TOKEN=
33
DISCORD_PRIVATE_POSTS_CHANNEL_ID=
44
REDIS_HOST=
5-
SPAM_ACCOUNT_DISPLAY_NAME=
5+
SPAM_ACCOUNT_DISPLAY_NAME=
6+
BANNED_KEYWORDS=

packages/velog-scripts/env/env.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const env = z.object({
1515
discordPrivatePostsChannelId: z.string(),
1616
redisHost: z.string(),
1717
restorePostsUsername: z.string().optional(),
18-
bannedKeywords: z.array(z.string()).min(1),
18+
bannedKeywords: z.array(z.string()),
1919
})
2020

2121
export const ENV = env.parse({
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { DbService } from '../db/DbService.mjs'
2+
import { injectable, singleton } from 'tsyringe'
3+
4+
interface Service {
5+
addBlockList: (username: string) => Promise<void>
6+
readBlockList: () => Promise<string[]>
7+
}
8+
9+
@injectable()
10+
@singleton()
11+
export class BlockListService implements Service {
12+
constructor(private readonly db: DbService) {}
13+
public async addBlockList(username: string) {
14+
await this.db.dynamicConfigItem.create({
15+
data: {
16+
value: username,
17+
type: 'username',
18+
},
19+
})
20+
}
21+
public async readBlockList() {
22+
const blockList = await this.db.dynamicConfigItem.findMany({
23+
where: {
24+
type: 'username',
25+
},
26+
})
27+
return blockList.map((item) => item.value)
28+
}
29+
}

packages/velog-scripts/scripts/privatePostsOfSpamAccount.mts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ import { container, injectable } from 'tsyringe'
55
import inquirer from 'inquirer'
66
import { ENV } from '../env/env.mjs'
77
import { DiscordService } from '../lib/discord/DiscordService.mjs'
8-
import { RedisService } from '../lib/redis/RedisService.mjs'
8+
import { BlockListService } from '../lib/blockList/BlockListService.mjs'
99

1010
interface IRunner {}
1111

1212
@injectable()
1313
class Runner implements IRunner {
14-
blockList!: string[]
1514
constructor(
1615
private readonly db: DbService,
1716
private readonly discord: DiscordService,
18-
private readonly redis: RedisService,
17+
private readonly blockList: BlockListService,
1918
) {}
2019
public async run(names: string[]) {
2120
await this.init()
@@ -27,7 +26,7 @@ class Runner implements IRunner {
2726
const posts = await this.findWritenPostsByUserId(user.id)
2827

2928
// add block list
30-
await this.redis.addBlockList(username)
29+
await this.blockList.addBlockList(username)
3130

3231
if (posts.length === 0) {
3332
console.log(`${user.username} 유저의 비공개 처리 할 게시글이 없습니다.`)
@@ -85,9 +84,7 @@ class Runner implements IRunner {
8584
private async init() {
8685
try {
8786
await this.discord.connection()
88-
await this.redis.connection()
89-
90-
this.blockList = await this.redis.readBlockList()
87+
await this.db.$connect()
9188
} catch (error) {
9289
throw error
9390
}
@@ -130,7 +127,8 @@ class Runner implements IRunner {
130127
username: string,
131128
displayName: string | null,
132129
): Promise<AskDeletePostsResult> {
133-
if (this.blockList.includes(username)) {
130+
const blockedList = await this.blockList.readBlockList()
131+
if (blockedList.includes(username)) {
134132
return {
135133
posts,
136134
is_set_private: true,

0 commit comments

Comments
 (0)