feat: initial prototype (#6)
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>
This commit was merged in pull request #6.
This commit is contained in:
2025-07-21 16:53:48 -07:00
committed by Naomi Carrigan
parent da76bb5327
commit 925f740370
26 changed files with 5887 additions and 0 deletions
+117
View File
@@ -0,0 +1,117 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import {
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
ContainerBuilder,
MessageFlags,
SeparatorBuilder,
SeparatorSpacingSize,
TextDisplayBuilder,
type Message,
} from "discord.js";
import { checkGuildEntitlement } from "../utils/checkEntitlement.js";
import type { Liora } from "../interfaces/liora.js";
/**
* Processes a slash command.
* @param liora - Liora's Discord instance.
* @param message - The message payload from Discord.
*/
// eslint-disable-next-line max-lines-per-function -- It's mostly components.
const messageCreate = async(
liora: Liora,
message: Message<true>,
): Promise<void> => {
const isEntitled = await checkGuildEntitlement(liora, message.guild);
if (!isEntitled) {
return;
}
const highlights = await liora.database.highlights.findMany({
where: {
serverId: message.guild.id,
},
});
if (highlights.length <= 0) {
return;
}
await Promise.all(
// eslint-disable-next-line max-lines-per-function -- It's mostly components.
highlights.map(async(record) => {
// No need to notify the user if they are the one who sent the message.
if (record.userId === message.author.id) {
return;
}
if (record.words.length <= 0) {
return;
}
const foundWords = record.words.filter((word) => {
return message.content.toLowerCase().includes(word.toLowerCase());
});
if (foundWords.length <= 0) {
return;
}
const dm = await message.client.users.fetch(record.userId).catch(() => {
return null;
});
if (!dm) {
return;
}
await dm.send({
components: [
new ContainerBuilder().
addTextDisplayComponents(
new TextDisplayBuilder().setContent(
"One of your highlights was mentioned in a message!",
),
).
addSeparatorComponents(
new SeparatorBuilder().
setSpacing(SeparatorSpacingSize.Small).
setDivider(true),
).
addTextDisplayComponents(
new TextDisplayBuilder().setContent(
`The word(s) \`${foundWords.join(
", ",
)}\` were mentioned in the server \`${
message.guild.name
}\` by ${message.author.displayName}.`,
),
).
addTextDisplayComponents(
new TextDisplayBuilder().setContent(
`You can view the message here: ${message.url}`,
),
),
new ActionRowBuilder<ButtonBuilder>().addComponents(
new ButtonBuilder().
setStyle(ButtonStyle.Link).
setLabel("Jump to Message").
setURL(message.url),
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(() => {
// If we cannot send the DM, we do not want to throw an error.
return null;
});
}),
);
};
export { messageCreate };