Skip to content

Commit

Permalink
Fixed missionPrint format
Browse files Browse the repository at this point in the history
  • Loading branch information
coinmoles committed Feb 9, 2024
1 parent 83201d0 commit c36a842
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 66 deletions.
6 changes: 1 addition & 5 deletions roleIds.json
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
{
"chiefRole": "1057988415657877585",
"regularRole": "1057988446267908167",
"associateRole": "1057988449757577246"
}
{"chiefRole":"1169598738445119608","regularRole":"1169598823958593587","associateRole":"1169598789351395409"}
6 changes: 3 additions & 3 deletions src/commands/missionCheck/viewList/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/commands/missionGive/printMission/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}` +
"```"

Expand Down
15 changes: 6 additions & 9 deletions src/commands/missionGive/viewMissionList/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
Expand All @@ -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}`)
Expand Down
2 changes: 1 addition & 1 deletion src/commands/missionGive/viewMissionStatus/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/utils/checks/checkDeveloper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export const createMissionMapPrintString = (missionMap: Map<string, Mission[]>,

export const createProgressPrintString = (currentScore: number, goalScore: number) =>
`- 목표: ${goalScore}점\n` +
`- 현재: ${currentScore}\n`
`- 현재: ${currentScore}점`
76 changes: 36 additions & 40 deletions src/db/actions/missionActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, Mission[]>, Map<string, Mission[]>] | 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<string, Mission[]>()

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<string, Mission[]>()

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)
Expand Down

0 comments on commit c36a842

Please sign in to comment.