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

### 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: #3
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #3.
This commit is contained in:
2025-08-14 23:14:08 -07:00
committed by Naomi Carrigan
parent f67291b8da
commit c9ec681471
35 changed files with 6265 additions and 0 deletions
+102
View File
@@ -0,0 +1,102 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { MessageFlags } from "discord.js";
import { checkGuildEntitlement } from "../modules/checkEntitlement.js";
import { generateScore } from "../modules/generateScore.js";
import { getCachedCount } from "../modules/getCachedCount.js";
import { getConfig } from "../modules/getConfig.js";
import { getTarget } from "../modules/getTarget.js";
import { getThrowComponents } from "../modules/getThrowComponents.js";
import { sendUnentitledResponse } from "../modules/sendUnentitledResponse.js";
import { errorHandler } from "../utils/errorHandler.js";
import type { Command } from "../interfaces/command.js";
/**
* Handles the `/throw` command interaction.
* @param pavelle - Pavelle's Discord instance.
* @param interaction - The command interaction payload from Discord.
*/
// eslint-disable-next-line max-lines-per-function -- Big logic, but lotsa components
export const throwCmd: Command = async(pavelle, interaction) => {
try {
const { member, guild } = interaction;
const count = getCachedCount(pavelle, `${guild.id}-${member.id}`);
if (count <= 0) {
await interaction.editReply({
components: [
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API convention.
accent_color: null,
components: [
{
content:
// eslint-disable-next-line stylistic/max-len -- long string.
"Oopsie! You are out of throws! Your count resets at the top of every hour.",
type: 10,
},
],
spoiler: false,
type: 17,
},
],
flags: [ MessageFlags.IsComponentsV2 ],
});
return;
}
const isEntitled = await checkGuildEntitlement(pavelle, guild);
if (!isEntitled) {
await sendUnentitledResponse(interaction);
return;
}
pavelle.throwCache.set(`${guild.id}-${member.id}`, count - 1);
const target = await getTarget(interaction);
const score = generateScore();
const { theme, spoiler } = await getConfig(pavelle, guild.id);
const updated = await pavelle.db.users.upsert({
create: {
points: score,
serverId: guild.id,
userId: member.id,
},
update: {
points: {
increment: score,
},
},
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention -- Prisma index convention.
serverId_userId: {
serverId: guild.id,
userId: member.id,
},
},
});
const components = getThrowComponents(
pavelle,
member.id,
target.id,
guild.id,
theme,
score,
spoiler,
updated.points,
);
await interaction.editReply({
allowedMentions: {
parse: [ "users" ],
},
components: components,
flags: [ MessageFlags.IsComponentsV2 ],
});
} catch (error) {
const id = await errorHandler(error, "throw command");
await interaction.editReply({
content:
`An error occurred while processing your request. Please try again later, or join our support server and provide this ID: ${id}`,
});
}
};