generated from nhcarrigan/template
### Explanation _No response_ ### Issue _No response_ ### Attestations - [x] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/) - [x] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/). - [x] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/). ### Dependencies - [x] I have pinned the dependencies to a specific patch version. ### Style - [x] I have run the linter and resolved any errors. - [x] My pull request uses an appropriate title, matching the conventional commit standards. - [x] 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 Major - My pull request introduces a breaking change. Reviewed-on: #1 Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com> Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { EmbedBuilder, type ColorResolvable } from "discord.js";
|
||||
import { priorityNames } from "../config/priorityNames.js";
|
||||
import { statusNames } from "../config/statusNames.js";
|
||||
import type { Priority } from "../interfaces/priority.js";
|
||||
import type { Status } from "../interfaces/status.js";
|
||||
import type { Tasks } from "@prisma/client";
|
||||
|
||||
const colours: Record<Status, ColorResolvable> = {
|
||||
"complete": 0x00_FF_00,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- matching the status names.
|
||||
"in-progress": 0xFF_77_00,
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention -- matching the status names.
|
||||
"in-review": 0xFF_FF_00,
|
||||
"todo": 0xFF_00_00,
|
||||
};
|
||||
|
||||
/**
|
||||
* Generates a Discord embed for a task.
|
||||
* @param task -- The task record from the database.
|
||||
* @returns An EmbedBuilder.
|
||||
*/
|
||||
export const generateTaskEmbed = (task: Tasks): EmbedBuilder => {
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTitle(task.title);
|
||||
embed.setDescription(task.description);
|
||||
embed.addFields(
|
||||
{
|
||||
inline: true,
|
||||
name: "Category",
|
||||
value: task.category,
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "Status",
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Totally being lazy here.
|
||||
value: statusNames[task.status as Status],
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "Priority",
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Totally being lazy here.
|
||||
value: priorityNames[task.priority as Priority],
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "Due Date",
|
||||
value: task.dueAt.toLocaleDateString("en-GB"),
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "Created At",
|
||||
value: task.createdAt.toLocaleDateString("en-GB"),
|
||||
},
|
||||
{
|
||||
inline: true,
|
||||
name: "Updated At",
|
||||
value: task.updatedAt.toLocaleDateString("en-GB"),
|
||||
},
|
||||
);
|
||||
embed.setFooter({
|
||||
text: `Task #${task.number.toString()}`,
|
||||
});
|
||||
embed.setColor(task.status in colours
|
||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We narrowed it smh.
|
||||
? colours[task.status as Status]
|
||||
: 0x00_00_00);
|
||||
return embed;
|
||||
};
|
||||
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
type ChatInputCommandInteraction,
|
||||
} from "discord.js";
|
||||
|
||||
/**
|
||||
* Checks if a user has an active entitlement (subscription) for the bot.
|
||||
* If they do not, it responds to the interaction with a button to subscribe.
|
||||
* @param interaction -- The interaction payload from Discord.
|
||||
* @returns A boolean indicating whether the user is subscribed.
|
||||
*/
|
||||
export const isSubscribed = async(
|
||||
interaction: ChatInputCommandInteraction,
|
||||
): Promise<boolean> => {
|
||||
const isEntitled = interaction.entitlements.find((entitlement) => {
|
||||
return entitlement.userId === interaction.user.id && entitlement.isActive();
|
||||
});
|
||||
|
||||
if (!isEntitled && interaction.user.id !== "465650873650118659") {
|
||||
const subscribeButton = new ButtonBuilder().
|
||||
setStyle(ButtonStyle.Premium).
|
||||
setSKUId("1338755540397985873");
|
||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
subscribeButton,
|
||||
);
|
||||
await interaction.editReply({
|
||||
components: [ row ],
|
||||
content: "You must be subscribed to use this feature.",
|
||||
});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { Logger } from "@nhcarrigan/logger";
|
||||
|
||||
export const logger = new Logger(
|
||||
"Melody Iuvo",
|
||||
process.env.LOG_TOKEN ?? "",
|
||||
);
|
||||
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
type ChatInputCommandInteraction,
|
||||
type MessageContextMenuCommandInteraction,
|
||||
} from "discord.js";
|
||||
|
||||
/**
|
||||
* Responds to an interaction with a generic error message.
|
||||
* @param interaction -- The interaction payload from Discord.
|
||||
*/
|
||||
export const replyToError = async(
|
||||
interaction:
|
||||
| ChatInputCommandInteraction
|
||||
| MessageContextMenuCommandInteraction,
|
||||
): Promise<void> => {
|
||||
const button = new ButtonBuilder().setLabel("Need help?").
|
||||
setStyle(ButtonStyle.Link).
|
||||
setURL("https://chat.nhcarrigan.com");
|
||||
const row = new ActionRowBuilder<ButtonBuilder>().addComponents(button);
|
||||
if (interaction.deferred || interaction.replied) {
|
||||
await interaction.editReply({
|
||||
components: [ row ],
|
||||
content: "An error occurred while running this command.",
|
||||
});
|
||||
return;
|
||||
}
|
||||
await interaction.reply({
|
||||
components: [ row ],
|
||||
content: "An error occurred while running this command.",
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user