feat: add button to clear reminder (#3)
Node.js CI / Lint and Test (push) Successful in 38s

### Explanation

### added button to clear the reminder also added logic to not let anyone click that button if it  does it reply  him with warning message that auto deletes after 2sec

### Issue

issue number 2 add button to clear reminder

### 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

- [x] My contribution adds new code, and I have added tests to cover it.
- [x] My contribution modifies existing code, and I have updated the tests to reflect these changes.
- [x] All new and existing tests pass locally with my changes.
- [x] Code coverage remains at or above the configured threshold.

### Documentation

n/a

### Versioning

Minor - My pull request introduces a new non-breaking feature.

Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-authored-by: GURKIRAT SINGH <mr.gurkirat.singh.no1@gmail.com>
Reviewed-on: #3
Co-authored-by: gurkirat <contact.here.gurkirat.singh@gmail.com>
Co-committed-by: gurkirat <contact.here.gurkirat.singh@gmail.com>
This commit was merged in pull request #3.
This commit is contained in:
2025-11-02 09:23:29 -08:00
committed by Naomi Carrigan
parent 2058dfb82f
commit cba2a8027b
3 changed files with 62 additions and 6 deletions
+9 -6
View File
@@ -8,6 +8,7 @@ import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js"; import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js";
import { blocks } from "./config/blocks.js"; import { blocks } from "./config/blocks.js";
import { checkAltText } from "./modules/checkAltText.js"; import { checkAltText } from "./modules/checkAltText.js";
import { processButton } from "./modules/processButton.js";
import { instantiateServer } from "./server/serve.js"; import { instantiateServer } from "./server/serve.js";
import { logger } from "./utils/logger.js"; import { logger } from "./utils/logger.js";
@@ -35,13 +36,15 @@ client.on(Events.MessageCreate, (message) => {
client.on(Events.InteractionCreate, (interaction) => { client.on(Events.InteractionCreate, (interaction) => {
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction }); void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
if (!interaction.isChatInputCommand()) { if (interaction.isChatInputCommand()) {
return; void interaction.reply({
components: blocks,
flags: MessageFlags.IsComponentsV2,
});
}
if (interaction.isButton()) {
void processButton(interaction);
} }
void interaction.reply({
components: blocks,
flags: MessageFlags.IsComponentsV2,
});
}); });
await client.login(process.env.BOT_TOKEN); await client.login(process.env.BOT_TOKEN);
+13
View File
@@ -33,6 +33,19 @@ export const checkAltText = async(message: Message): Promise<void> => {
if (noDescription.size > 0) { if (noDescription.size > 0) {
const reminder = getRandomValue(reminders); const reminder = getRandomValue(reminders);
await message.reply({ await message.reply({
components: [ {
components: [
{
// eslint-disable-next-line @typescript-eslint/naming-convention -- Discord API requires this.
custom_id: message.author.id,
disabled: false,
label: "Okie Dokie!",
style: 3,
type: 2,
},
],
type: 1,
} ],
content: `${reminder}\n-# If you do not know how to do this, check [Discord's help article](<https://support.discord.com/hc/en-us/articles/211866427-How-do-I-upload-images-and-GIFs>)!\n-# Need help writing descriptive text? Our bot [Cordelia](<https://cordelia.nhcarrigan.com>) can do it for you!`, content: `${reminder}\n-# If you do not know how to do this, check [Discord's help article](<https://support.discord.com/hc/en-us/articles/211866427-How-do-I-upload-images-and-GIFs>)!\n-# Need help writing descriptive text? Our bot [Cordelia](<https://cordelia.nhcarrigan.com>) can do it for you!`,
}).catch(() => { }).catch(() => {
return null; return null;
+40
View File
@@ -0,0 +1,40 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { logger } from "../utils/logger.js";
import type {
ButtonInteraction,
} from "discord.js";
/**
* Handles a button interaction. If the user is not the author of the reminder,
* they cannot acknowledge it.
* @param interaction - The interaction payload from Discord.
*/
export const processButton = async(
interaction: ButtonInteraction,
): Promise<void> => {
try {
await interaction.deferReply({ ephemeral: true });
const { customId, user, message } = interaction;
if (customId !== user.id) {
await interaction.editReply({
content: "You cannot acknowledge someone else's reminder.",
});
}
await message.delete();
await interaction.editReply({
content: "Acknowledged!",
});
} catch (error) {
if (error instanceof Error) {
await logger.error("process interaction module", error);
}
await interaction.editReply({
content: "Oh dear, something went wrong.",
});
}
};