-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheckin-status.ts
More file actions
92 lines (82 loc) · 3.3 KB
/
Copy pathcheckin-status.ts
File metadata and controls
92 lines (82 loc) · 3.3 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import type { PrismaClient } from '@generatedDB/client'
import type { Checkin as CheckinType } from '@type/checkin'
import type { User } from '@type/user'
import type { EmbedBuilder, Guild } from 'discord.js'
import { FLAMEWARDEN_ROLE } from '@config/discord'
import { Checkin } from '@events/interaction-create/checkin/validators'
import { createEmbed } from '@utils/component'
import { DiscordAssert } from '@utils/discord'
import { DUMMY } from '@utils/placeholder'
import { PermissionsBitField } from 'discord.js'
import { CheckinStatusMessage } from '../messages/checkin-status'
export class CheckinStatus extends CheckinStatusMessage {
static override BASE_PERMS = [
...DiscordAssert.BASE_PERMS,
PermissionsBitField.Flags.UseApplicationCommands,
]
static async getEmbedStatusContent(guild: Guild, userDiscordId: string, checkin: CheckinType | undefined) {
let content = ''
let embed: EmbedBuilder
const checkinStreak = checkin?.checkin_streak
const hasCheckedInToday = Checkin.hasCheckinToday(checkinStreak, checkin)
if (hasCheckedInToday && checkin) {
const flamewarden = await guild.members.fetch(checkin.reviewed_by!)
switch (checkin.status) {
case 'WAITING':
content = `<@&${FLAMEWARDEN_ROLE}>`
embed = createEmbed(
`🧭 Check-In #${checkin.public_id}`,
CheckinStatus.MSG.WaitingCheckin(userDiscordId, checkin),
DUMMY.COLOR,
{ text: DUMMY.FOOTER },
)
break
case 'APPROVED':
embed = createEmbed(
`🔥 Check-In #${checkin.public_id}`,
CheckinStatus.MSG.ApprovedCheckin(userDiscordId, flamewarden, checkin),
DUMMY.COLOR,
{ text: DUMMY.FOOTER },
)
break
default:
embed = createEmbed(
`❌ Check-In #${checkin.public_id}`,
CheckinStatus.MSG.RejectedCheckin(userDiscordId, flamewarden, checkin),
DUMMY.COLOR,
{ text: DUMMY.FOOTER },
)
break
}
}
else {
embed = createEmbed(
`🧐 Check-In`,
CheckinStatus.MSG.NoCheckin(userDiscordId, checkinStreak),
DUMMY.COLOR,
{ text: DUMMY.FOOTER },
)
}
return { content, embed }
}
static async getUser(prisma: PrismaClient, userDiscordId: string): Promise<User> {
const user = await prisma.user.findFirst({
where: {
discord_id: userDiscordId,
},
select: {
id: true,
discord_id: true,
created_at: true,
updated_at: true,
checkins: {
orderBy: { created_at: 'desc' },
take: 1,
include: { checkin_streak: true },
},
},
}) as User
await Checkin.setAttachments(prisma, user?.checkins?.[0])
return user
}
}