generated from nhcarrigan/template
925f740370
Node.js CI / Lint and Test (push) Successful in 41s
### Explanation _No response_ ### Issue _No response_ ### Attestations - [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [ ] I have pinned the dependencies to a specific patch version. ### Style - [ ] I have run the linter and resolved any errors. - [ ] My pull request uses an appropriate title, matching the conventional commit standards. - [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request. ### Tests - [ ] My contribution adds new code, and I have added tests to cover it. - [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes. - [ ] All new and existing tests pass locally with my changes. - [ ] Code coverage remains at or above the configured threshold. ### Documentation _No response_ ### Versioning _No response_ Reviewed-on: #6 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
93 lines
3.0 KiB
TypeScript
93 lines
3.0 KiB
TypeScript
/**
|
|
* @copyright nhcarrigan
|
|
* @license Naomi's Public License
|
|
* @author Naomi Carrigan
|
|
*/
|
|
import {
|
|
TextDisplayBuilder,
|
|
ContainerBuilder,
|
|
ButtonBuilder,
|
|
ButtonStyle,
|
|
ActionRowBuilder,
|
|
MessageFlags,
|
|
} from "discord.js";
|
|
import { sendUnentitledResponse } from "../modules/sendUnentitledResponse.js";
|
|
import { checkGuildEntitlement } from "../utils/checkEntitlement.js";
|
|
import { errorHandler } from "../utils/errorHandler.js";
|
|
import type { Command } from "../interfaces/command.js";
|
|
|
|
/**
|
|
* Handles the `/dm` command interaction.
|
|
* @param liora - Liora's Discord instance.
|
|
* @param interaction - The command interaction payload from Discord.
|
|
*/
|
|
// eslint-disable-next-line max-lines-per-function -- It's mostly components.
|
|
export const dm: Command = async(liora, interaction) => {
|
|
try {
|
|
await interaction.deferReply({
|
|
flags: [ MessageFlags.Ephemeral ],
|
|
});
|
|
const isEntitled = await checkGuildEntitlement(liora, interaction.guild);
|
|
if (!isEntitled) {
|
|
await sendUnentitledResponse(interaction);
|
|
}
|
|
const sentDm = await interaction.user.send({
|
|
content: "Hello! This is a test DM from Liora.",
|
|
}).catch(() => {
|
|
return null;
|
|
});
|
|
|
|
if (!sentDm) {
|
|
await interaction.editReply({
|
|
components: [
|
|
new ContainerBuilder().addTextDisplayComponents(
|
|
new TextDisplayBuilder().setContent(
|
|
`Oopsie! It looks like I am unable to send you a DM. Please check your privacy settings and try again.`,
|
|
),
|
|
),
|
|
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
|
new ButtonBuilder().
|
|
setStyle(ButtonStyle.Link).
|
|
setLabel("Discord Server").
|
|
setURL("https://chat.nhcarrigan.com"),
|
|
new ButtonBuilder().
|
|
setStyle(ButtonStyle.Link).
|
|
setLabel("Forum").
|
|
setURL("https://forum.nhcarrigan.com"),
|
|
),
|
|
],
|
|
flags: [ MessageFlags.IsComponentsV2 ],
|
|
});
|
|
return;
|
|
}
|
|
|
|
await interaction.editReply({
|
|
components: [
|
|
new ContainerBuilder().addTextDisplayComponents(
|
|
new TextDisplayBuilder().setContent(
|
|
`Neato! You should have received a DM from me. If you did not, please let us know in our support channels.`,
|
|
),
|
|
),
|
|
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
|
new ButtonBuilder().
|
|
setStyle(ButtonStyle.Link).
|
|
setLabel("Discord Server").
|
|
setURL("https://chat.nhcarrigan.com"),
|
|
new ButtonBuilder().
|
|
setStyle(ButtonStyle.Link).
|
|
setLabel("Forum").
|
|
setURL("https://forum.nhcarrigan.com"),
|
|
),
|
|
],
|
|
flags: [ MessageFlags.IsComponentsV2 ],
|
|
});
|
|
} catch (error) {
|
|
await errorHandler(error, "dm command");
|
|
await interaction.editReply({
|
|
content:
|
|
// eslint-disable-next-line stylistic/max-len -- Big boi string.
|
|
"An error occurred while processing your request. Please try again later.",
|
|
});
|
|
}
|
|
};
|