-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcreateResponse.ts
More file actions
57 lines (51 loc) · 1.85 KB
/
createResponse.ts
File metadata and controls
57 lines (51 loc) · 1.85 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
import { ButtonBuilder, MessageReplyOptions } from 'discord.js';
import { ActionRowBuilder, UserSelectMenuBuilder } from 'discord.js';
import { User, MessagePayload, ButtonStyle } from 'discord.js';
import type { EmbedField, Collection, MessageActionRowComponentBuilder } from 'discord.js';
import { clampLength } from '../../utils/clampStr.js';
import { createEmbed } from '../../utils/discordTools.js';
export function createResponse(
thankedUsers: Collection<string, User>,
authorId: string
): MessageReplyOptions {
const title = `Point${thankedUsers.size === 1 ? '' : 's'} received!`;
const description = `<@!${authorId}> has given a point to ${thankedUsers.size === 1
? `<@!${thankedUsers.first().id}>`
: 'the users mentioned below'
}!`;
const fields: EmbedField[] =
thankedUsers.size > 1
? [...thankedUsers].map(([, u], i) => ({
inline: false,
name: `${(i + 1).toString()}.`,
value: `<@!${u.id}>`,
}))
: [];
const output = createEmbed({
description,
fields,
footerText:
'Thank a helpful member by replying "thanks @username" or saying "thanks" in a reply or thread.',
provider: 'helper',
title,
}).embed;
return {
embeds: [output],
components: [
new ActionRowBuilder<MessageActionRowComponentBuilder>().addComponents(
thankedUsers.size > 1
? new UserSelectMenuBuilder()
.setCustomId(`thanks🤔${authorId}🤔select`)
.setPlaceholder('Accidentally Thank someone? Un-thank them here!')
.setMinValues(1)
.setDefaultUsers(
...thankedUsers.keys()
)
: new ButtonBuilder()
.setCustomId(`thanks🤔${authorId}🤔${thankedUsers.first().id}`)
.setStyle(ButtonStyle.Secondary)
.setLabel('This was an accident, UNDO!')
),
],
}
}