-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus-note-button.ts
More file actions
48 lines (40 loc) · 2 KB
/
Copy pathstatus-note-button.ts
File metadata and controls
48 lines (40 loc) · 2 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
44
45
46
47
48
import type { TextChannel } from 'discord.js'
import { CheckinStatus } from '@commands/checkin/validators/checkin-status'
import { EVENT_PATH } from '@events/index'
import { registerInteractionHandler } from '@events/interaction-create/registry'
import { generateCustomId } from '@utils/component'
import { sendReply } from '@utils/discord'
import { DiscordBaseError } from '@utils/discord/error'
import { getModuleName } from '@utils/io'
import { messageLink } from 'discord.js'
import { Checkin } from '../validators'
export class CheckinStatusNoteButtonError extends DiscordBaseError {
constructor(message: string, options?: { cause?: unknown }) {
super('CheckinStatusNoteButtonError', message, options)
}
}
const moduleName = getModuleName(EVENT_PATH, __filename)
export const CHECKIN_STATUS_NOTE_BUTTON_ID = `${generateCustomId(EVENT_PATH, __filename)}`
registerInteractionHandler({
desc: 'Opens a note about how to request clarification for the last check-in if the streak was broken and did not reviewed.',
id: CHECKIN_STATUS_NOTE_BUTTON_ID,
errorTag: () => `${moduleName}: ${Checkin.ERR.UnexpectedButton}`,
async exec(_, interaction) {
if (!interaction.isButton())
return
try {
if (!interaction.inCachedGuild())
throw new CheckinStatusNoteButtonError(Checkin.ERR.NotGuild)
const { checkinLink } = CheckinStatus.getButtonId(interaction, interaction.customId)
const channel = interaction.channel as TextChannel
Checkin.assertMissPerms(interaction.client.user, channel)
const statusMessageLink = messageLink(interaction.channelId, interaction.message.id, interaction.guildId)
await sendReply(interaction, CheckinStatus.MSG.LastCheckinNote(interaction.guild.name, checkinLink, statusMessageLink))
}
catch (err: any) {
if (err instanceof DiscordBaseError)
await sendReply(interaction, err.message)
else throw err
}
},
})