Skip to content

Commit

Permalink
fix(guess): check if user has enable dm before sending join request
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanddd committed Sep 11, 2023
1 parent 7e3941e commit c278a2d
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/commands/guess/new/slash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
TokenEmojiKey,
} from "utils/common"
import { announceResult, cleanupAfterEndGame } from "../end/slash"
import { composeEmbedMessage } from "../../../ui/discord/embed"
import { composeEmbedMessage, enableDMMessage } from "../../../ui/discord/embed"
import { truncate } from "lodash"
import moment, { now } from "moment-timezone"
import { formatTokenDigit } from "utils/defi"
Expand All @@ -31,26 +31,34 @@ function collectPlayerChoice(data: any, referee: User) {
})
return
}
const optionCode = i.customId

const { ok, error } = await mochiGuess.joinGame(
data.code,
i.user.id,
optionCode,
)
if (!ok) {
await i.editReply({
content: capitalizeFirst(error),
})
return
}
i.user
.send("A join request should open up shortly...")
.then(async () => {
const optionCode = i.customId

const dmChannel = await i.user.createDM(true).catch(() => null)
await i.editReply({
content: `A join request has been sent to you. Please check your DM${
dmChannel ? `, <#${dmChannel.id}>` : ""
}.`,
})
const { ok, error } = await mochiGuess.joinGame(
data.code,
i.user.id,
optionCode,
)
if (!ok) {
await i.editReply({
content: capitalizeFirst(error),
})
return
}

const dmChannel = await i.user.createDM(true).catch(() => null)
await i.editReply({
content: `A join request has been sent to you. Please check your DM${
dmChannel ? `, <#${dmChannel.id}>` : ""
}.`,
})
})
.catch(() => {
i.editReply({ embeds: [enableDMMessage()] })
})
}
}

Expand Down Expand Up @@ -168,6 +176,7 @@ const slashCmd: SlashCommand = {
},
}
}

const yesLabel = `${
i.options.getString("yes_label", false) || "🐮 Bullish"
}`
Expand Down

0 comments on commit c278a2d

Please sign in to comment.