Skip to content

Commit

Permalink
update msgReactions to new handling
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnipers committed Jan 14, 2025
1 parent 7b8fff9 commit 6954a26
Show file tree
Hide file tree
Showing 5 changed files with 134 additions and 122 deletions.
79 changes: 79 additions & 0 deletions src/events/messageReactionAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
const { PermissionFlagsBits, Events } = require("discord.js");
const reactions = require("../Schemas/reactionrole.js");
const requests = require("../Schemas/request-status.js");

module.exports = {
name: Events.MessageReactionAdd,
async execute(reaction, user, client) {
if (!reaction || !user || !client) {
return;
}

if (user.partial) await user.fetch();
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();

let cID = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
if (!reaction.emoji.id) {
cID = reaction.emoji.name;
}
const reactData = await reactions.findOne({
Guild: reaction.message.guildId,
Message: reaction.message.id,
Emoji: cID,
});
if (reactData) {
const guild = await client.guilds.cache.get(reaction.message.guildId);
if (!guild) {
return;
}

const member = await guild.members.cache.get(user.id);
if (!member) {
return;
}

try {
await member.roles.add(reactData.Role);
} catch (e) {
console.error(e);
}
}

const requestData = await requests.findOne({
User: user.id,
Type: "Whitelist",
});
if (requestData) {
const guild = reaction.message.guild;
const newRole = guild.roles.cache.find((role) => role.name === "Femmy");
const oldRole = member.roles.cache.find(
(role) => role.name === "Wannabe Fem"
);

const member = reaction.message.guild.members.cache.get(user.id);
if (
!member ||
!member.permissions.has(PermissionFlagsBits.Administrator)
) {
return;
}
if (reaction.emoji.name === "👍") {
await schema.findOneAndUpdate(
{ User: user.id, Type: "Whitelist" },
{ Status: true }
);
if (member.roles.cache.has(newRole.id)) await member.roles.add(newRole);
if (member.roles.cache.has(oldRole.id))
await member.roles.remove(oldRole);
} else if (reaction.emoji.name === "👎") {
await schema.findOneAndUpdate(
{ User: user.id, Type: "Whitelist" },
{ Status: false }
);
} else {
return;
}
}
},
};
55 changes: 55 additions & 0 deletions src/events/messageReactionRemove.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
const { Events } = require("discord.js");
const reactions = require("../Schemas/reactionrole.js");
//const requests = require("../Schemas/request-status.js");

module.exports = {
name: Events.MessageReactionRemove,
async execute(reaction, user, client) {
if (!reaction || !user || !client) {
return;
}

if (user.partial) await user.fetch();
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();

let cID = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
if (!reaction.emoji.id) {
cID = reaction.emoji.name;
}
const reactData = await reactions.findOne({
Guild: reaction.message.guildId,
Message: reaction.message.id,
Emoji: cID,
});
if (reactData) {
const guild = await client.guilds.cache.get(reaction.message.guildId);
if (!guild) {
return;
}

const member = await guild.members.cache.get(user.id);
if (!member) {
return;
}

try {
await member.roles.remove(reactData.Role);
} catch (e) {
console.error(e);
}
}
},
};

/*
module.exports = {
name: Events.MessageReactionRemoveAll,
async execute(reaction, user, client) {},
};
module.exports = {
name: Events.MessageReactionRemoveEmoji,
async execute(reaction, user, client) {},
};
*/
2 changes: 0 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ client.on("disconnect", () => {

require("./auto-roles.js");
require("./guild-scraper.js");
require("./reaction-roles.js");
require("./whitelist-response.js");

require("./logger/automod-rules.js");
require("./logger/bans.js");
Expand Down
74 changes: 0 additions & 74 deletions src/reaction-roles.js

This file was deleted.

46 changes: 0 additions & 46 deletions src/whitelist-response.js

This file was deleted.

0 comments on commit 6954a26

Please sign in to comment.