refactor: make botEnforcements more maintainable

This commit is contained in:
skinmaker1345 2025-07-03 21:41:31 +09:00
parent baeef4fd16
commit 3e1e357802
5 changed files with 23 additions and 12 deletions

View File

@ -368,8 +368,8 @@ const AddBot: NextPage<AddBotProps> = ({ logged, user, csrfToken, theme }) => {
>
<Selects
options={Object.entries(botEnforcements).map(([k, v]) => ({
label: k,
value: v,
label: v.label,
value: k,
}))}
handleChange={(value) => {
setFieldValue(

View File

@ -78,7 +78,6 @@ const ManageBotPage: NextPage<ManageBotProps> = ({ bot, user, csrfToken, theme }
)
return <Forbidden />
const isPerkAvailable = checkBotFlag(bot.flags, 'trusted') || checkBotFlag(bot.flags, 'partnered')
console.log(bot.enforcements)
return (
<Container paddingTop className='pb-10 pt-5'>
<NextSeo title={`${bot.name} 수정하기`} description='봇의 정보를 수정합니다.' />
@ -341,8 +340,8 @@ const ManageBotPage: NextPage<ManageBotProps> = ({ bot, user, csrfToken, theme }
>
<Selects
options={Object.entries(botEnforcements).map(([k, v]) => ({
label: k,
value: v,
label: v.label,
value: k,
}))}
handleChange={(value) => {
setFieldValue(

View File

@ -34,7 +34,7 @@ export interface Bot {
owners: User[] | string[]
}
export type BotEnforcementKeys = ValueOf<typeof botEnforcements>
export type BotEnforcementKeys = keyof typeof botEnforcements
export interface RawGuild {
id: string

View File

@ -121,10 +121,22 @@ export const botCategoryDescription = {
}
export const botEnforcements = {
'서버 참여가 필요한 기능이 있습니다': 'JOIN_PARTIALLY_ENFORCED',
'서버 참여 없이는 봇의 핵심 기능을 사용할 수 없습니다': 'JOIN_ENFORCED',
'유료 구매가 필요한 기능이 있습니다': 'LICENSE_PARTIALLY_ENFORCED',
'유료 구매 없이는 봇의 핵심 기능을 사용할 수 없습니다': 'LICENSE_ENFORCED',
JOIN_PARTIALLY_ENFORCED: {
label: '서버 참여가 필요한 기능이 있습니다',
description: '봇의 일부 명령어는 봇의 디스코드 서버에 참여해야 사용할 수 있습니다.',
},
JOIN_ENFORCED: {
label: '서버 참여 없이는 봇의 핵심 기능을 사용할 수 없습니다',
description: '봇의 핵심 기능은 봇의 디스코드 서버에 참여해야 사용할 수 있습니다.',
},
LICENSE_PARTIALLY_ENFORCED: {
label: '유료 구매가 필요한 기능이 있습니다',
description: '봇의 일부 명령어는 유료 구매가 필요합니다.',
},
LICENSE_ENFORCED: {
label: '유료 구매 없이는 봇의 핵심 기능을 사용할 수 없습니다',
description: '유료 구매 없이는 봇의 핵심 기능을 사용할 수 없습니다.',
},
} as const
export const botCategoryIcon = {

View File

@ -175,7 +175,7 @@ export const AddBotSubmitSchema: Yup.SchemaOf<AddBotSubmit> = Yup.object({
.min(100, '봇 설명은 최소 100자여야합니다.')
.max(1500, '봇 설명은 최대 1500자여야합니다.')
.required('봇 설명은 필수 항목입니다.'),
enforcements: Yup.array(Yup.string().oneOf(Object.values(botEnforcements))),
enforcements: Yup.array(Yup.string().oneOf(Object.keys(botEnforcements))),
_csrf: Yup.string().required(),
_captcha: Yup.string().required(),
})
@ -306,7 +306,7 @@ export function getManageBotSchema(perkAvailable = false) {
.min(100, '봇 설명은 최소 100자여야합니다.')
.max(1500, '봇 설명은 최대 1500자여야합니다.')
.required('봇 설명은 필수 항목입니다.'),
enforcements: Yup.array(Yup.string().oneOf(Object.values(botEnforcements))),
enforcements: Yup.array(Yup.string().oneOf(Object.keys(botEnforcements))),
_csrf: Yup.string().required(),
}