-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrandomStake.ts
More file actions
43 lines (39 loc) · 1.38 KB
/
randomStake.ts
File metadata and controls
43 lines (39 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { ChatInputCommandInteraction, MessageFlags } from 'discord.js'
import { getRandomStake } from '../../utils/matchHelpers'
import {
getMatchData,
getMatchIdFromChannel,
setPickedMatchStake,
} from '../../utils/queryDB'
export default {
async execute(interaction: ChatInputCommandInteraction) {
try {
const customStake =
interaction.options.getString('custom-stake', false) ?? false
const custom = customStake == 'yes'
const matchId = await getMatchIdFromChannel(interaction.channelId)
const stakeChoice = await getRandomStake(custom)
if (matchId) {
// In a match channel
const matchData = await getMatchData(matchId)
if (!matchData.stake_vote_ended)
await setPickedMatchStake(matchId, stakeChoice.stake_name)
}
const stakeStr = `${stakeChoice.stake_emote} ${stakeChoice.stake_name}`
await interaction.reply({ content: stakeStr })
} catch (err: any) {
console.error(err)
const errorMsg = err.detail || err.message || 'Unknown'
if (interaction.deferred || interaction.replied) {
await interaction.editReply({
content: `Failed to send message. Reason: ${errorMsg}`,
})
} else {
await interaction.reply({
content: `Failed to send message. Reason: ${errorMsg}`,
flags: MessageFlags.Ephemeral,
})
}
}
},
}