MessagePinReactionHandler.ts #1

Open
Harry wants to merge 6 commits from Harry/crv2-MessagePinReactionHandler.ts:master into master

/**

  • Handles both 'messageReactionAdd' and 'messageReactionRemove' events.
  • When a reaction is added or removed:
    • If the reaction matches the specified emoji and the user has the required role,
  • the message will be pinned or unpinned in the channel accordingly.
    */

Signed-off-by: Harry harry@staff.libraryofcode.org

/** * Handles both 'messageReactionAdd' and 'messageReactionRemove' events. * When a reaction is added or removed: * - If the reaction matches the specified emoji and the user has the required role, * the message will be pinned or unpinned in the channel accordingly. */ Signed-off-by: Harry <harry@staff.libraryofcode.org>
Harry added 1 commit 2024-12-20 02:15:12 -05:00
6f561f3b44 MessagePinReactionHandler.ts
/**
 * Handles both 'messageReactionAdd' and 'messageReactionRemove' events.
 * When a reaction is added or removed:
 * - If the reaction matches the specified emoji and the user has the required role,
 *   the message will be pinned or unpinned in the channel accordingly.
 */

Signed-off-by: Harry <harry@harryrosestudios.com>
Harry changed title from WIP: MessagePinReactionHandler.ts to MessagePinReactionHandler.ts 2024-12-20 16:04:41 -05:00

I think we need to discuss how we want to handle the hierarchy and architecture. Are we going to want to reuse the message react event with different functionality or is the only intended functionality the message pinning? If the former, we probably should segment all of the handlers in a separate file than the event handler. Something like: discord/event-handlers/<handler name>.

I think we need to discuss how we want to handle the hierarchy and architecture. Are we going to want to reuse the message react event with different functionality or is the only intended functionality the message pinning? If the former, we probably should segment all of the handlers in a separate file than the event handler. Something like: `discord/event-handlers/<handler name>`.

I think we need to discuss how we want to handle the hierarchy and architecture. Are we going to want to reuse the message react event with different functionality or is the only intended functionality the message pinning? If the former, we probably should segment all of the handlers in a separate file than the event handler. Something like: discord/event-handlers/<handler name>.

Do you have anything in mind for other uses? Personally, my current intention is only to pin. Regarding hierarchy, It's currently hardcoded for staff, though, this can be changed.

> I think we need to discuss how we want to handle the hierarchy and architecture. Are we going to want to reuse the message react event with different functionality or is the only intended functionality the message pinning? If the former, we probably should segment all of the handlers in a separate file than the event handler. Something like: `discord/event-handlers/<handler name>`. > > Do you have anything in mind for other uses? Personally, my current intention is only to pin. Regarding hierarchy, It's currently hardcoded for staff, though, this can be changed.
matthew requested changes 2024-12-20 16:15:36 -05:00
matthew left a comment
Owner

Please see my review, if you have any questions please let me know. Review should be addressed before approval.

Please see my review, if you have any questions please let me know. Review should be addressed before approval.
@ -0,0 +1,66 @@
import DiscordEvent from "../../util/DiscordEvent";
import { Client, MessageReaction, PartialMessageReaction, PartialUser, User, Events } from "discord.js";
const ROLE_ID = '446104438969466890'; // Allowed role ID

Maybe we should have this pulled from utils/MemberUtils/'s partner role maps or maybe a discussion of permission management?

Please also use double quotes per string styling.

Maybe we should have this pulled from `utils/MemberUtils/`'s partner role maps or maybe a discussion of permission management? Please also use double quotes per string styling.
@ -0,0 +7,4 @@
export default class MessageReactionHandler extends DiscordEvent {
constructor(client: Client) {
super(Events.MessageReactionAdd, client); // Register the "messageReactionAdd" event
client.on(Events.MessageReactionRemove, this.handleRemove.bind(this)); // Register "messageReactionRemove" within the same class

This client.on I believe is redundant, as the application's index main function handles this initialization.

This `client.on` I believe is redundant, as the application's index main function handles this initialization.
@ -0,0 +16,4 @@
try {
await reaction.fetch();
} catch (error) {
console.error('Error fetching reaction:', error);

Avoid using console.error. I'd either:

  • Add a TODO: command emphasizing the need for an error handler (since we don't have one implemented yet), or;
  • Send the error to the channel.
Avoid using console.error. I'd either: - Add a `TODO:` command emphasizing the need for an error handler (since we don't have one implemented yet), or; - Send the error to the channel.
@ -0,0 +24,4 @@
if (reaction.emoji.name !== PUSH_PIN_EMOJI) return;
const guild = reaction.message.guild;
if (!guild) return;

This could be condensed into one-line for readability.:

if (!reaction.message.guild) return;.

This could be condensed into one-line for readability.: `if (!reaction.message.guild) return;`.
@ -0,0 +31,4 @@
try {
await reaction.message.pin();
console.log(`Pinned message: ${reaction.message.id}`);

Avoid console.log()

Avoid `console.log()`
@ -0,0 +33,4 @@
await reaction.message.pin();
console.log(`Pinned message: ${reaction.message.id}`);
} catch (error) {
console.error('Failed to pin message:', error);

See previous review regarding logging errors.

See previous review regarding logging errors.
@ -0,0 +37,4 @@
}
}
private async handleRemove(reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser): Promise<void> {

Please place this method into its own event handler class to maintain structure.

Please place this method into its own event handler class to maintain structure.

I don't believe there are currently plans.
For now, I believe the best option is to assume that will be the only functionality.
Therefore, maybe determine permissions from the Discord Partner Role Map I mentioned earlier. Please reach out to me if you need help with integrations or have development questions.

I don't believe there are currently plans. For now, I believe the best option is to assume that will be the only functionality. Therefore, maybe determine permissions from the Discord Partner Role Map I mentioned earlier. Please reach out to me if you need help with integrations or have development questions.

I don't believe there are currently plans.
For now, I believe the best option is to assume that will be the only functionality.
Therefore, maybe determine permissions from the Discord Partner Role Map I mentioned earlier. Please reach out to me if you need help with integrations or have development questions.

'Aight. I'll get on it. My bad. I used Perplexity to convert it to ts and match it to work as a module here, so that's why there are some redundancies.

> I don't believe there are currently plans. > For now, I believe the best option is to assume that will be the only functionality. > Therefore, maybe determine permissions from the Discord Partner Role Map I mentioned earlier. Please reach out to me if you need help with integrations or have development questions. 'Aight. I'll get on it. My bad. I used Perplexity to convert it to ts and match it to work as a module here, so that's why there are some redundancies.
Harry added 1 commit 2024-12-20 17:54:40 -05:00
b37ac915c2 MessageReactionAdd.ts
Pins messages in a channel when a partner adds a 📌 reaction

Signed-off-by: Harry <harry@harryrosestudios.com>
Harry added 1 commit 2024-12-20 18:01:03 -05:00
9374a1bca6 MessageReactionRemove.ts
Unpins a message when a partner removes the 📌 reaction from it

Signed-off-by: Harry <harry@harryrosestudios.com>
Harry added 1 commit 2024-12-20 18:02:32 -05:00
e6dae3ae48 MessageReactionAdd.ts
Pins a message when a partner adds a 📌 reaction to it

Signed-off-by: Harry <harry@harryrosestudios.com>

I'd updated the files and their structure. Pretty sure it's uploaded. Let me know if this is what you wanted.

I'd updated the files and their structure. Pretty sure it's uploaded. Let me know if this is what you wanted.
Harry added 1 commit 2024-12-20 20:33:37 -05:00
65f4bd92dc Update discord/events/MessageReactionAdd.ts
switched error messages to Ephemeral: true

Signed-off-by: Harry <harry@harryrosestudios.com>
Harry added 1 commit 2024-12-20 20:34:36 -05:00
54845033f1 Update discord/events/MessageReactionRemove.ts
Switched error messages to ephermal: true

Signed-off-by: Harry <harry@harryrosestudios.com>

@matthew What we saying regarding this?

@matthew What we saying regarding this?
This pull request can be merged automatically.
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b Harry-master master
git pull master

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff Harry-master
git push origin master
Sign in to join this conversation.
No reviewers
No Label
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: engineering/crv2#1
There is no content yet.