feat: initial prototype (#7)
Node.js CI / Lint and Test (push) Successful in 54s

### 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: #7
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #7.
This commit is contained in:
2025-09-27 16:58:54 -07:00
committed by Naomi Carrigan
parent ad449e50a4
commit 64d5d4a9b5
21 changed files with 5618 additions and 0 deletions
+163
View File
@@ -0,0 +1,163 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { MessageFlags, type ModalSubmitInteraction } from "discord.js";
import type { Veluna } from "../interfaces/veluna.js";
/**
* Handles modal submissions.
* @param veluna - Veluna's instance.
* @param interaction - The modal submit interaction payload from Discord.
*/
// eslint-disable-next-line max-lines-per-function, complexity, max-statements -- Big boi function.
export const handleModalSubmit = async(
veluna: Veluna,
interaction: ModalSubmitInteraction,
): Promise<void> => {
await interaction.deferReply({ flags: [ MessageFlags.Ephemeral ] });
if (!interaction.inCachedGuild()) {
await interaction.editReply({
content: "This interaction can only be used in a server.",
});
return;
}
const record = await veluna.db.servers.findUnique({
where: {
serverId: interaction.guildId,
},
});
if (!record) {
await interaction.editReply({
content:
// eslint-disable-next-line stylistic/max-len -- Big boi string.
"This server is not registered in the database. Please configure your settings.",
});
return;
}
if (interaction.customId === "ask") {
if (record.questionChannelId === "") {
await interaction.editReply({
content: "This server has not set a question channel.",
});
return;
}
const question = interaction.fields.getTextInputValue("textinput");
const channel
= veluna.discord.channels.cache.get(record.questionChannelId)
?? await veluna.discord.channels.fetch(record.questionChannelId).
catch(() => {
return null;
});
if (channel?.isSendable() !== true) {
await interaction.editReply({
content: "The question channel set is not a text-based channel.",
});
return;
}
await channel.send({
components: [
{
components: [
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API.
custom_id: "answer",
label: "Answer this question",
style: 3,
type: 2,
},
],
type: 1,
},
],
content: question,
});
}
if (interaction.customId === "answer") {
if (record.answerChannelId === "") {
await interaction.editReply({
content: "This server has not set an answer channel.",
});
return;
}
const { message, fields } = interaction;
if (!message) {
await interaction.editReply({
content: "An error occurred while fetching the message.",
});
return;
}
const { content: question } = message;
const answer = fields.getTextInputValue("textinput");
if (question === "") {
await interaction.editReply({
content: "An error occurred while fetching the question.",
});
}
const channel
= veluna.discord.channels.cache.get(record.answerChannelId)
?? await veluna.discord.channels.fetch(record.answerChannelId).
catch(() => {
return null;
});
if (channel?.isSendable() !== true) {
await interaction.editReply({
content: "The answer channel set is not a text-based channel.",
});
return;
}
await channel.send({
components: [
{
components: [
{
content: `# ${question}`,
type: 10,
},
{
divider: true,
spacing: 1,
type: 14,
},
{
content: answer,
type: 10,
},
{
divider: true,
spacing: 1,
type: 14,
},
{
content: `-# Brought to you by [NHCarrigan](<https://chat.nhcarrigan.com>)`,
type: 10,
},
],
spoiler: false,
type: 17,
},
{
components: [
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API.
custom_id: "ask",
disabled: false,
label: "Ask your own?",
style: 3,
type: 2,
},
],
type: 1,
},
],
});
}
};