Skip to content

Commit 7868e26

Browse files
committed
feat: 인증 내역 명령어 추가
1 parent 9c1cbb2 commit 7868e26

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/commands/my-history.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { EntityRepository } from '@mikro-orm/core';
2+
import dayjs from 'dayjs';
3+
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
4+
5+
import { ErrorReply } from '@susc/common/reply';
6+
import { BaseDiscordCommandHandler } from '@susc/discord/base-discord-command-handler';
7+
import { GetRepository } from '@susc/discord/get-repository.decorator';
8+
import { ConfirmHistoryEntity } from '@susc/entities/confirm-history.entity';
9+
import { UserEntity } from '@susc/entities/user.entity';
10+
11+
export class MyHistoryCommandHandler extends BaseDiscordCommandHandler {
12+
@GetRepository(UserEntity)
13+
private readonly userRepository!: EntityRepository<UserEntity>;
14+
15+
@GetRepository(ConfirmHistoryEntity)
16+
private readonly confirmHistoryRepository!: EntityRepository<ConfirmHistoryEntity>;
17+
18+
constructor() {
19+
super('인증내역');
20+
}
21+
22+
async handle(
23+
interaction: ChatInputCommandInteraction<CacheType>,
24+
): Promise<void> {
25+
const user = await this.userRepository.findOne({
26+
discordId: interaction.user.id,
27+
});
28+
29+
if (!user) {
30+
await interaction.reply(
31+
ErrorReply(
32+
'아직 깃허브 계정을 등록하지 않았어요. **/등록** 명령어를 사용해서 깃허브 계정을 등록해주세요!',
33+
),
34+
);
35+
return;
36+
}
37+
38+
const [confirmHistories, count] =
39+
await this.confirmHistoryRepository.findAndCount(
40+
{ userId: user.id },
41+
{ limit: 10, orderBy: { createdAt: 'desc' } },
42+
);
43+
44+
if (confirmHistories.length === 0) {
45+
await interaction.reply(
46+
ErrorReply(
47+
'아직 인증한 내역이 없어요.',
48+
'📜 아직 인증한 내역이 없어요!',
49+
),
50+
);
51+
return;
52+
}
53+
54+
const confirmHistoryList = confirmHistories
55+
.map((confirmHistory) => {
56+
const date = dayjs(confirmHistory.createdAt)
57+
.tz('Asia/Seoul')
58+
.format('YYYY년 MM월 DD일 HH시 mm분');
59+
return `- ${date}`;
60+
})
61+
.join('\n');
62+
63+
const description = [
64+
`📌 총 인증 횟수: **${count}회**`,
65+
confirmHistoryList,
66+
].join('\n\n');
67+
68+
await interaction.reply({
69+
embeds: [{ color: 0x57ad68, title: '📜 내 인증 내역', description }],
70+
});
71+
}
72+
}

src/init.ts

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ async function init() {
2626
'최대 연속 잔디 랭킹을 확인해요. 최소 한 번 이상 인증한 사람들 중 상위 10명이 나와요.',
2727
)
2828
.toJSON(),
29+
new SlashCommandBuilder()
30+
.setName('인증내역')
31+
.setDescription(
32+
'여러분이 심은 잔디 인증 내역을 확인해요. 최근 10개의 인증 일시와 총 인증 횟수가 나와요.',
33+
)
34+
.toJSON(),
2935
];
3036

3137
const rest = new REST().setToken(config.discord.token);

src/main.ts

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import timezone from 'dayjs/plugin/timezone';
33
import utc from 'dayjs/plugin/utc';
44

55
import { ConfirmCommandHandler } from '@susc/commands/confirm';
6+
import { MyHistoryCommandHandler } from '@susc/commands/my-history';
67
import { RankingCommandHandler } from '@susc/commands/ranking';
78
import { RegisterCommandHandler } from '@susc/commands/register';
89
import { DiscordBot } from '@susc/discord/discord-bot';
@@ -17,6 +18,7 @@ async function bootstrap() {
1718
client.registerHandler(RegisterCommandHandler);
1819
client.registerHandler(ConfirmCommandHandler);
1920
client.registerHandler(RankingCommandHandler);
21+
client.registerHandler(MyHistoryCommandHandler);
2022

2123
await client.listen();
2224
}

0 commit comments

Comments
 (0)