-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcreateResponse.ts
More file actions
65 lines (57 loc) · 1.91 KB
/
createResponse.ts
File metadata and controls
65 lines (57 loc) · 1.91 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
import { MessageButton } from 'discord.js';
import { MessageActionRow, MessageSelectMenu } from 'discord.js';
import type { User, MessageOptions, Client } from 'discord.js';
import type { EmbedField, Collection } from 'discord.js';
import { clampLength } from '../../utils/clampStr.js';
import { createEmbed } from '../../utils/discordTools.js';
export function createResponse(
thankedUsers: Collection<string, User>,
authorId: string,
client: Client
): MessageOptions {
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;
const clientId = client.user.id;
const components = authorId === clientId ? [
new MessageActionRow().addComponents(
thankedUsers.size > 1
? new MessageSelectMenu()
.setCustomId(`thanks🤔${authorId}🤔select`)
.setPlaceholder('Accidentally Thank someone? Un-thank them here!')
.setMinValues(1)
.setOptions(
thankedUsers.map(user => ({
label: clampLength(user.username, 25),
value: user.id,
}))
)
: new MessageButton()
.setCustomId(`thanks🤔${authorId}🤔${thankedUsers.first().id}`)
.setStyle('SECONDARY')
.setLabel('This was an accident, UNDO!')
),
] : [];
return {
embeds: [output],
components,
};
}