MessagePinReactionHandler.ts #1
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "Harry/crv2-MessagePinReactionHandler.ts:master"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
/**
*/
Signed-off-by: Harry harry@staff.libraryofcode.org
WIP: MessagePinReactionHandler.tsto MessagePinReactionHandler.tsI 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.
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.
@ -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.@ -0,0 +16,4 @@
try {
await reaction.fetch();
} catch (error) {
console.error('Error fetching reaction:', error);
Avoid using console.error. I'd either:
TODO:
command emphasizing the need for an error handler (since we don't have one implemented yet), or;@ -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;
.@ -0,0 +31,4 @@
try {
await reaction.message.pin();
console.log(`Pinned message: ${reaction.message.id}`);
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.
@ -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.
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.
Pins messages in a channel when a partner adds a 📌 reaction Signed-off-by: Harry <harry@harryrosestudios.com>
Unpins a message when a partner removes the 📌 reaction from it Signed-off-by: Harry <harry@harryrosestudios.com>
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.
@matthew What we saying regarding this?
Step 1:
From your project repository, check out a new branch and test the changes.Step 2:
Merge the changes and update on Gitea.