From c36a842035656d31a866c27acac45036ca23ddee Mon Sep 17 00:00:00 2001 From: coinmoles Date: Fri, 9 Feb 2024 11:26:27 +0900 Subject: [PATCH] Fixed missionPrint format --- roleIds.json | 6 +- .../missionCheck/viewList/operations.ts | 6 +- .../missionGive/printMission/operations.ts | 12 +-- .../missionGive/viewMissionList/operations.ts | 15 ++-- .../viewMissionStatus/operations.ts | 2 +- src/commands/utils/checks/checkDeveloper.ts | 2 +- .../createString/createMissionPrintString.ts | 2 +- src/db/actions/missionActions.ts | 76 +++++++++---------- 8 files changed, 55 insertions(+), 66 deletions(-) diff --git a/roleIds.json b/roleIds.json index 839a77f..3edcdd5 100644 --- a/roleIds.json +++ b/roleIds.json @@ -1,5 +1 @@ -{ - "chiefRole": "1057988415657877585", - "regularRole": "1057988446267908167", - "associateRole": "1057988449757577246" -} \ No newline at end of file +{"chiefRole":"1169598738445119608","regularRole":"1169598823958593587","associateRole":"1169598789351395409"} \ No newline at end of file diff --git a/src/commands/missionCheck/viewList/operations.ts b/src/commands/missionCheck/viewList/operations.ts index a7e88d2..ee6f4dc 100644 --- a/src/commands/missionCheck/viewList/operations.ts +++ b/src/commands/missionCheck/viewList/operations.ts @@ -56,12 +56,12 @@ export const doReply = async (interaction: ChatInputCommandInteraction, giver: U } const progress = await getMissionProgress(giver.id, interaction.user.id) - const missions = await getMissionAll(giver.id, interaction.user.id) - if (missions === undefined || progress === undefined) { + const missionUniversal = await getMissionAll(giver.id, giver.id) + const missionSpecific = await getMissionAll(giver.id, interaction.user.id) + if (missionUniversal === undefined || missionSpecific === undefined || progress === undefined) { await interaction.editReply({ embeds: [errorEmbed] }) return } - const [missionUniversal, missionSpecific] = missions const reply = await interaction.editReply({ embeds: [EmbedBuilder.from(viewListEmbedPrototype) diff --git a/src/commands/missionGive/printMission/operations.ts b/src/commands/missionGive/printMission/operations.ts index 404ffa8..51559ba 100644 --- a/src/commands/missionGive/printMission/operations.ts +++ b/src/commands/missionGive/printMission/operations.ts @@ -17,17 +17,17 @@ export const doReply = async (interaction: ChatInputCommandInteraction, target: return const progress = await getMissionProgress(interaction.user.id, target.id) - const missions = await getMissionAll(interaction.user.id, target.id) - if (missions === undefined || progress === undefined) { + const missionUniversal = await getMissionAll(interaction.user.id, interaction.user.id) + const missionSpecific = await getMissionAll(interaction.user.id, target.id) + if (missionUniversal === undefined || missionSpecific === undefined || progress === undefined) { await interaction.editReply({ embeds: [errorEmbed] }) return } - const [missionUniversal, missionSpecific] = missions const replyString = "```markdown\n" + - `# ${target.displayName}의 승격 조건 : ${interaction.user.displayName}\n` + - `## 달성 현황\n${createProgressPrintString(progress.currentScore, progress.goalScore)}\n` + - `## 공통 조건\n${createMissionMapPrintString(missionUniversal, target.id)}\n` + + `# ${target.displayName}의 승격 조건 : ${interaction.user.displayName}\n\n` + + `## 달성 현황\n${createProgressPrintString(progress.currentScore, progress.goalScore)}\n\n` + + `## 공통 조건\n${createMissionMapPrintString(missionUniversal, target.id)}\n\n` + `## 개인 조건\n${createMissionMapPrintString(missionSpecific, target.id)}` + "```" diff --git a/src/commands/missionGive/viewMissionList/operations.ts b/src/commands/missionGive/viewMissionList/operations.ts index fcf93c5..84533bf 100644 --- a/src/commands/missionGive/viewMissionList/operations.ts +++ b/src/commands/missionGive/viewMissionList/operations.ts @@ -50,15 +50,12 @@ export const doReply = async (interaction: ChatInputCommandInteraction, target: let replyEmbed: EmbedBuilder; if (target.id === interaction.user.id) { - const missions = await getMissionAll(interaction.user.id, target.id) - - if (missions === undefined) { + const missionUniversal = await getMissionAll(interaction.user.id, interaction.user.id) + if (missionUniversal === undefined) { await interaction.editReply({ embeds: [errorEmbed] }) - return; + return } - const [missionUniversal, _] = missions - replyEmbed = new EmbedBuilder(viewMissionListEmbedPrototype.toJSON()) .setTitle(`공통 승격 조건: ${interaction.user.displayName}`) .addFields({ name: "공통 조건", value: createMissionMapString(missionUniversal, interaction.user.id), inline: false }) @@ -71,12 +68,12 @@ export const doReply = async (interaction: ChatInputCommandInteraction, target: } const progress = await getMissionProgress(interaction.user.id, target.id) - const missions = await getMissionAll(interaction.user.id, target.id) - if (missions === undefined || progress === undefined) { + const missionUniversal = await getMissionAll(interaction.user.id, interaction.user.id) + const missionSpecific = await getMissionAll(interaction.user.id, target.id) + if (missionUniversal === undefined || missionSpecific === undefined || progress === undefined) { await interaction.editReply({ embeds: [errorEmbed] }) return } - const [missionUniversal, missionSpecific] = missions replyEmbed = new EmbedBuilder(viewMissionListEmbedPrototype.toJSON()) .setTitle(`${target.displayName}의 승격 조건 : ${interaction.user.displayName}`) diff --git a/src/commands/missionGive/viewMissionStatus/operations.ts b/src/commands/missionGive/viewMissionStatus/operations.ts index db67a96..f949b23 100644 --- a/src/commands/missionGive/viewMissionStatus/operations.ts +++ b/src/commands/missionGive/viewMissionStatus/operations.ts @@ -4,7 +4,7 @@ import { getQuarterDataFooter } from "../../utils/quarterData/getQuarterData.js" import builders from "./builders.js" import { getAllAssociateIds } from "../../../db/actions/memberActions.js" import { getMissionProgress } from "../../../db/actions/missionProgressActions.js" -import { getMissionAll, getMissionCount } from "../../../db/actions/missionActions.js" +import { getMissionCount } from "../../../db/actions/missionActions.js" import assert from "assert" const { diff --git a/src/commands/utils/checks/checkDeveloper.ts b/src/commands/utils/checks/checkDeveloper.ts index e0a5d7c..775bc8b 100644 --- a/src/commands/utils/checks/checkDeveloper.ts +++ b/src/commands/utils/checks/checkDeveloper.ts @@ -4,7 +4,7 @@ import { testEmbed } from "../errorEmbeds.js"; import { editOrReply } from "../editOrReply.js"; export const checkDeveloper = async (interaction: ChatInputCommandInteraction, components?: ReplyComponents[]) => { - if (interaction.user.id !== "772050469430099989") { + if (interaction.user.id !== process.env.DEV_ID && interaction.user.id !== process.env.DEV_ID2) { await editOrReply(interaction, { embeds: [testEmbed], components, ephemeral: true }) return false } diff --git a/src/commands/utils/createString/createMissionPrintString.ts b/src/commands/utils/createString/createMissionPrintString.ts index ad2652b..8bccf94 100644 --- a/src/commands/utils/createString/createMissionPrintString.ts +++ b/src/commands/utils/createString/createMissionPrintString.ts @@ -17,4 +17,4 @@ export const createMissionMapPrintString = (missionMap: Map, export const createProgressPrintString = (currentScore: number, goalScore: number) => `- 목표: ${goalScore}점\n` + - `- 현재: ${currentScore}점\n` \ No newline at end of file + `- 현재: ${currentScore}점` \ No newline at end of file diff --git a/src/db/actions/missionActions.ts b/src/db/actions/missionActions.ts index 125f44f..6aefa81 100644 --- a/src/db/actions/missionActions.ts +++ b/src/db/actions/missionActions.ts @@ -72,62 +72,58 @@ export const getMission = async (giverId: string, targetId: string, category: st } export const getMissionCount = async (giverId: string, targetId: string) => { - const missionMap = await firebaseDb - .collection(QUARTER).doc(await getQuarterDataString()) - .collection(REGULAR).doc(giverId) - .collection(MISSION).doc(targetId) - .withConverter(missionMapConverter) - .get().then(snapshot => snapshot.data()) - - if (missionMap === undefined) - return 0 - else - return [...missionMap.data.values()].reduce((prev, curr) => prev + curr.length, 0) -} - -export const getMissionAll = async (giverId: string, targetId: string): Promise<[Map, Map] | undefined> => { try { - const missionMapSpecific = await firebaseDb + const missionMap = await firebaseDb .collection(QUARTER).doc(await getQuarterDataString()) .collection(REGULAR).doc(giverId) .collection(MISSION).doc(targetId) .withConverter(missionMapConverter) .get().then(snapshot => snapshot.data()) - const missionMapUniversal = await firebaseDb + if (missionMap === undefined) + return 0 + else + return [...missionMap.data.values()].reduce((prev, curr) => prev + curr.length, 0) + } + catch (e) { + console.error(e) + + return + } +} + +export const getMissionAll = async (giverId: string, targetId: string) => { + try { + const missionMap = await firebaseDb .collection(QUARTER).doc(await getQuarterDataString()) .collection(REGULAR).doc(giverId) - .collection(MISSION).doc(giverId) + .collection(MISSION).doc(targetId) .withConverter(missionMapConverter) .get().then(snapshot => snapshot.data()) - const missionMapToMissions = async (missionMap: MissionMap | undefined) => { - const missions = new Map() - - if (missionMap === undefined) - return missions - - for (const [category, missionIds] of missionMap.data) { - const missionsInCategory: Mission[] = [] - missions.set(category, missionsInCategory) - - for (const missionId of missionIds) { - const mission = await firebaseDb - .collection(QUARTER).doc(await getQuarterDataString()) - .collection(MISSION).doc(missionId) - .withConverter(missionConverter) - .get().then(snapshot => snapshot.data()) - - if (mission === undefined) - continue - missionsInCategory.push(mission) - } - } + const missions = new Map() + if (missionMap === undefined) return missions + + for (const [category, missionIds] of missionMap.data) { + const missionsInCategory: Mission[] = [] + missions.set(category, missionsInCategory) + + for (const missionId of missionIds) { + const mission = await firebaseDb + .collection(QUARTER).doc(await getQuarterDataString()) + .collection(MISSION).doc(missionId) + .withConverter(missionConverter) + .get().then(snapshot => snapshot.data()) + + if (mission === undefined) + continue + missionsInCategory.push(mission) + } } - return [await missionMapToMissions(missionMapUniversal), await missionMapToMissions(missionMapSpecific)] + return missions } catch (e) { console.error(e)