Skip to content

Commit 1d1cf5f

Browse files
authored
Convert /contact to components v2 (#53)
* Convert /contact to components v2 * Add RANews, format * fix writing team * cleanup and abstract messy component building to simple objects
1 parent 675efb9 commit 1d1cf5f

3 files changed

Lines changed: 155 additions & 77 deletions

File tree

src/commands/contact.command.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Command } from "../models";
22
import { buildContactEmbed } from "../utils/build-contact-embed";
33
import { logError } from "../utils/logger";
4+
import { MessageFlags } from "discord.js";
45

56
const contactCommand: Command = {
67
name: "contact",
@@ -14,15 +15,15 @@ const contactCommand: Command = {
1415

1516
try {
1617
await message.react("\u{1F4E7}");
17-
await message.reply({ embeds: [embed] });
18+
await message.reply({ components: [embed], flags: MessageFlags.IsComponentsV2 });
1819
} catch (error) {
1920
logError(error, {
2021
event: "contact_command_react_error",
2122
userId: message.author.id,
2223
guildId: message.guildId,
2324
channelId: message.channelId,
2425
});
25-
await message.reply({ embeds: [embed] });
26+
await message.reply({ components: [embed], flags: MessageFlags.IsComponentsV2 });
2627
}
2728
},
2829
};

src/slash-commands/contact.command.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SlashCommandBuilder } from "discord.js";
1+
import { MessageFlags, SlashCommandBuilder } from "discord.js";
22

33
import type { SlashCommand } from "../models";
44
import { buildContactEmbed } from "../utils/build-contact-embed";
@@ -13,7 +13,10 @@ const contactSlashCommand: SlashCommand = {
1313
async execute(interaction, _client) {
1414
const embed = buildContactEmbed();
1515

16-
await interaction.reply({ embeds: [embed] });
16+
await interaction.reply({
17+
components: [embed],
18+
flags: [MessageFlags.IsComponentsV2, MessageFlags.Ephemeral],
19+
});
1720
},
1821
};
1922

src/utils/build-contact-embed.ts

Lines changed: 147 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,151 @@
1-
import { EmbedBuilder } from "discord.js";
2-
31
import { COLORS } from "../config/constants";
2+
import {
3+
ButtonBuilder,
4+
ButtonStyle,
5+
ContainerBuilder,
6+
SectionBuilder,
7+
SeparatorBuilder,
8+
SeparatorSpacingSize,
9+
TextDisplayBuilder,
10+
} from "discord.js";
11+
12+
type Team = {
13+
name: string;
14+
// username to message on RA
15+
username: string;
16+
reasons: string[];
17+
};
18+
19+
const buildContactButton = (account: string): ButtonBuilder => {
20+
return new ButtonBuilder()
21+
.setStyle(ButtonStyle.Link)
22+
.setLabel("Message " + account)
23+
.setURL("https://retroachievements.org/messages/create?to=" + account);
24+
};
25+
26+
const buildTeamSection = (team: Team): SectionBuilder => {
27+
const reasons = team.reasons.map((reason: string) => "- " + reason).join("\n");
28+
29+
return new SectionBuilder()
30+
.setButtonAccessory(buildContactButton(team.username))
31+
.addTextDisplayComponents(
32+
new TextDisplayBuilder().setContent("## :e_mail: " + team.name + "\n" + reasons),
33+
);
34+
};
35+
36+
const separator = new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Small).setDivider(true);
437

5-
export const buildContactEmbed = (): EmbedBuilder => {
6-
return new EmbedBuilder()
7-
.setColor(COLORS.PRIMARY)
8-
.setTitle("Contact Us")
9-
.setDescription(
10-
"If you would like to contact us, please send a site message to the appropriate team below.",
38+
export const buildContactEmbed = (): ContainerBuilder => {
39+
return new ContainerBuilder()
40+
.setAccentColor(COLORS.PRIMARY)
41+
.addTextDisplayComponents(
42+
new TextDisplayBuilder().setContent(
43+
"# Contact Us\n" +
44+
"If you would like to contact us, please send a site message to the appropriate team below.",
45+
),
46+
)
47+
.addSeparatorComponents(separator)
48+
.addSectionComponents(
49+
buildTeamSection({
50+
name: "Admins and Moderators",
51+
username: "RAdmin",
52+
reasons: [
53+
"Reporting offensive behavior.",
54+
"Reporting copyrighted material.",
55+
"Requesting to be untracked.",
56+
],
57+
}),
58+
)
59+
.addSeparatorComponents(separator)
60+
.addSectionComponents(
61+
buildTeamSection({
62+
name: "Developer Compliance",
63+
username: "DevCompliance",
64+
reasons: [
65+
"Requesting set approval or early set release.",
66+
"Reporting achievements or sets with unwelcome concepts.",
67+
"Reporting sets failing to cover basic progression.",
68+
],
69+
}),
70+
)
71+
.addSeparatorComponents(separator)
72+
.addSectionComponents(
73+
buildTeamSection({
74+
name: "Quality Assurance",
75+
username: "QATeam",
76+
reasons: [
77+
"Reporting a broken set, leaderboard, or rich presence.",
78+
"Reporting achievements with grammatical mistakes.",
79+
"Requesting a set be playtested.",
80+
"Hash compatibility questions.",
81+
"Hub organizational questions.",
82+
"Getting involved in a QA sub-team.",
83+
],
84+
}),
85+
)
86+
.addSeparatorComponents(separator)
87+
.addSectionComponents(
88+
buildTeamSection({
89+
name: "Art Team",
90+
username: "RAArtTeam",
91+
reasons: [
92+
"Icon Gauntlets and how to start one.",
93+
"Proposing art updates.",
94+
"Questions about art-related rule changes.",
95+
"Requests for help with creating a new badge or badge set.",
96+
],
97+
}),
98+
)
99+
.addSeparatorComponents(separator)
100+
.addSectionComponents(
101+
buildTeamSection({
102+
name: "Writing Team",
103+
username: "WritingTeam",
104+
reasons: [
105+
"Reporting achievements with grammatical mistakes.",
106+
"Reporting achievements with unclear or confusing descriptions.",
107+
"Requesting help from the team with proofreading achievement sets.",
108+
"Requesting help for coming up with original titles for achievements.",
109+
],
110+
}),
111+
)
112+
.addSeparatorComponents(separator)
113+
.addSectionComponents(
114+
buildTeamSection({
115+
name: "RANews",
116+
username: "RANews",
117+
reasons: [
118+
"Submitting a Play This Set, Wish This Set, or RAdvantage entry.",
119+
"Submitting a retrogaming article.",
120+
"Proposing a new article idea.",
121+
"Getting involved with RANews.",
122+
],
123+
}),
124+
)
125+
.addSeparatorComponents(separator)
126+
.addSectionComponents(
127+
buildTeamSection({
128+
name: "RAEvents",
129+
username: "RAEvents",
130+
reasons: ["Submissions, questions, ideas, or reporting issues related to events."],
131+
}),
132+
)
133+
.addSeparatorComponents(separator)
134+
.addSectionComponents(
135+
buildTeamSection({
136+
name: "DevQuest",
137+
username: "DevQuest",
138+
reasons: ["Submissions, questions, ideas, or reporting issues related to DevQuest."],
139+
}),
11140
)
12-
.addFields([
13-
{
14-
name: ":e_mail: Admins and Moderators",
15-
value: `[Send a message to RAdmin](https://retroachievements.org/createmessage.php?t=RAdmin)
16-
- Reporting offensive behavior.
17-
- Reporting copyrighted material.
18-
- Requesting to be untracked.`,
19-
},
20-
{
21-
name: ":e_mail: Developer Compliance",
22-
value: `[Send a message to Developer Compliance](https://retroachievements.org/createmessage.php?t=DevCompliance)
23-
- Requesting set approval or early set release.
24-
- Reporting achievements or sets with unwelcome concepts.
25-
- Reporting sets failing to cover basic progression.`,
26-
},
27-
{
28-
name: ":e_mail: Quality Assurance",
29-
value: `[Send a message to Quality Assurance](https://retroachievements.org/createmessage.php?t=QATeam)
30-
- Reporting a broken set, leaderboard, or rich presence.
31-
- Reporting achievements with grammatical mistakes.
32-
- Requesting a set be playtested.
33-
- Hash compatibility questions.
34-
- Hub organizational questions.
35-
- Getting involved in a QA sub-team.`,
36-
},
37-
{
38-
name: ":e_mail: RAArtTeam",
39-
value: `[Send a message to RAArtTeam](https://retroachievements.org/messages/create?to=RAArtTeam)
40-
- Icon Gauntlets and how to start one.
41-
- Proposing art updates.
42-
- Questions about art-related rule changes.
43-
- Requests for help with creating a new badge or badge set.`,
44-
},
45-
{
46-
name: ":e_mail: WritingTeam",
47-
value: `[Send a message to WritingTeam](https://retroachievements.org/messages/create?to=WritingTeam)
48-
- Reporting achievements with grammatical mistakes.
49-
- Reporting achievements with unclear or confusing descriptions.
50-
- Requesting help from the team with proofreading achievement sets.
51-
- Requesting help for coming up with original titles for achievements.`,
52-
},
53-
{
54-
name: ":e_mail: RANews",
55-
value: `[Send a message to RANews](https://retroachievements.org/createmessage.php?t=RANews)
56-
- Submitting a Play This Set, Wish This Set, or RAdvantage entry.
57-
- Submitting a retrogaming article.
58-
- Proposing a new article idea.
59-
- Getting involved with RANews.`,
60-
},
61-
{
62-
name: ":e_mail: RAEvents",
63-
value: `[Send a message to RAEvents](https://retroachievements.org/createmessage.php?t=RAEvents)
64-
- Submissions, questions, ideas, or reporting issues related to events.`,
65-
},
66-
{
67-
name: ":e_mail: DevQuest",
68-
value: `[Send a message to DevQuest](https://retroachievements.org/createmessage.php?t=DevQuest)
69-
- Submissions, questions, ideas, or reporting issues related to DevQuest.`,
70-
},
71-
{
72-
name: ":e_mail: RACheats",
73-
value: `[Send a message to RACheats](https://retroachievements.org/createmessage.php?t=RACheats)
74-
- If you believe someone is in violation of our [Global Leaderboard and Achievement Hunting Rules](https://docs.retroachievements.org/guidelines/users/global-leaderboard-and-achievement-hunting-rules.html#not-allowed).`,
75-
},
76-
]);
141+
.addSeparatorComponents(separator)
142+
.addSectionComponents(
143+
buildTeamSection({
144+
name: "RACheats",
145+
username: "RACheats",
146+
reasons: [
147+
"If you believe someone is in violation of our [Global Leaderboard and Achievement Hunting Rules](https://docs.retroachievements.org/guidelines/users/global-leaderboard-and-achievement-hunting-rules.html#not-allowed).",
148+
],
149+
}),
150+
);
77151
};

0 commit comments

Comments
 (0)