Compare commits

..

6 Commits

Author SHA1 Message Date
Harry 54845033f1 Update discord/events/MessageReactionRemove.ts
Switched error messages to ephermal: true

Signed-off-by: Harry <harry@harryrosestudios.com>
2024-12-20 20:34:31 -05:00
Harry 65f4bd92dc Update discord/events/MessageReactionAdd.ts
switched error messages to Ephemeral: true

Signed-off-by: Harry <harry@harryrosestudios.com>
2024-12-20 20:33:31 -05:00
Harry e6dae3ae48 MessageReactionAdd.ts
Pins a message when a partner adds a 📌 reaction to it

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

Signed-off-by: Harry <harry@harryrosestudios.com>
2024-12-20 18:00:58 -05:00
Harry b37ac915c2 MessageReactionAdd.ts
Pins messages in a channel when a partner adds a 📌 reaction

Signed-off-by: Harry <harry@harryrosestudios.com>
2024-12-20 17:54:35 -05:00
Harry 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>
2024-12-20 02:12:27 -05:00
3 changed files with 126 additions and 0 deletions

38
MessageReactionAdd.ts Normal file
View File

@ -0,0 +1,38 @@
import DiscordEvent from "../../util/DiscordEvent";
import { MessageReaction, PartialMessageReaction, PartialUser, User, Events } from "discord.js";
import MemberUtil from "../../util/MemberUtil";
const PUSH_PIN_EMOJI = "📌"; // Unicode
export default class MessageReactionAdd extends DiscordEvent {
constructor(client) {
super(Events.MessageReactionAdd, client);
}
public async execute(reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser): Promise<void> {
try {
// Fetch partials if necessary
if (reaction.partial) await reaction.fetch();
// Condensed check for guild existence and emoji name
if (!reaction.message.guild || reaction.emoji.name !== PUSH_PIN_EMOJI) return;
const guild = reaction.message.guild;
const member = await guild.members.fetch(user.id);
// Combine all partner roles from PartnerDiscordRoleMap
const allPartnerRoles = Object.values(MemberUtil.PartnerDiscordRoleMap).flat();
// Check if the user has any of the partner roles
if (!member.roles.cache.some(role => allPartnerRoles.includes(role.id))) return;
// Attempt to pin the message
await reaction.message.pin();
const channel = reaction.message.channel;
await channel.send(`Pinned message: ${reaction.message.id}`);
} catch (error) {
const channel = reaction.message.channel;
await channel.send(`Error pinning message: ${error}`);
}
}
}

View File

@ -0,0 +1,44 @@
import DiscordEvent from "../../util/DiscordEvent";
import { MessageReaction, PartialMessageReaction, PartialUser, User, Events } from "discord.js";
import MemberUtil from "../../util/MemberUtil";
const PUSH_PIN_EMOJI = "📌"; // Unicode
export default class MessageReactionAdd extends DiscordEvent {
constructor(client) {
super(Events.MessageReactionAdd, client);
}
public async execute(reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser): Promise<void> {
try {
// Fetch partials if necessary
if (reaction.partial) await reaction.fetch();
// Condensed check for guild existence and emoji name
if (!reaction.message.guild || reaction.emoji.name !== PUSH_PIN_EMOJI) return;
const guild = reaction.message.guild;
const member = await guild.members.fetch(user.id);
// Combine all partner roles from PartnerDiscordRoleMap
const allPartnerRoles = Object.values(MemberUtil.PartnerDiscordRoleMap).flat();
// Check if the user has any of the partner roles
if (!member.roles.cache.some(role => allPartnerRoles.includes(role.id))) return;
// Attempt to pin the message
await reaction.message.pin();
console.log(`Pinned message: ${reaction.message.id}`);
} catch (error) {
try {
const dmChannel = await user.createDM();
await dmChannel.send({
content: `There was an error pinning the message: ${error.message}`,
ephemeral: true,
});
} catch (dmError) {
console.error(`Failed to send ephemeral error message to ${user.tag}: ${dmError}`);
}
}
}
}

View File

@ -0,0 +1,44 @@
import DiscordEvent from "../../util/DiscordEvent";
import { MessageReaction, PartialMessageReaction, PartialUser, User, Events } from "discord.js";
import MemberUtil from "../../util/MemberUtil";
const PUSH_PIN_EMOJI = "📌"; // Unicode
export default class MessageReactionRemove extends DiscordEvent {
constructor(client) {
super(Events.MessageReactionRemove, client);
}
public async execute(reaction: MessageReaction | PartialMessageReaction, user: User | PartialUser): Promise<void> {
try {
// Fetch partials if necessary
if (reaction.partial) await reaction.fetch();
// Condensed check for guild existence and emoji name
if (!reaction.message.guild || reaction.emoji.name !== PUSH_PIN_EMOJI) return;
const guild = reaction.message.guild;
const member = await guild.members.fetch(user.id);
// Combine all partner roles from PartnerDiscordRoleMap
const allPartnerRoles = Object.values(MemberUtil.PartnerDiscordRoleMap).flat();
// Check if the user has any of the partner roles
if (!member.roles.cache.some(role => allPartnerRoles.includes(role.id))) return;
// Attempt to unpin the message
await reaction.message.unpin();
console.log(`Unpinned message: ${reaction.message.id}`);
} catch (error) {
try {
const dmChannel = await user.createDM();
await dmChannel.send({
content: `There was an error unpinning the message: ${error.message}`,
ephemeral: true,
});
} catch (dmError) {
console.error(`Failed to send ephemeral error message to ${user.tag}: ${dmError}`);
}
}
}
}