Skip to content

Commit

Permalink
new big update :3
Browse files Browse the repository at this point in the history
  • Loading branch information
Barış Demirci authored and repl.it user committed Jul 5, 2020
1 parent 9f95471 commit 6e0f19b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 21 deletions.
5 changes: 3 additions & 2 deletions methods/createMessage.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
module.exports = (master, ...arguments) => {
let reactions = [];
for (let i = 3; i < arguments.length; i++) reactions.push(arguments[i]);
for (let i = 4; i < arguments.length; i++) reactions.push(arguments[i]);
master.config.push({
"messageID": arguments[0],
"channelID": arguments[1],
"limited": arguments[2],
"limit": arguments[2],
"restrictions": arguments[3],
"reactions": reactions
});
};
45 changes: 30 additions & 15 deletions methods/importEvents.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
const SuperError = require("../classes/SuperError");

module.exports = async (self) => {
self.client.on("messageReactionAdd", async(reaction, user) => {
if (self.client.user.equals(user)) return;
let { client, config } = self;

client.on("messageReactionAdd", async(reaction, user) => {
if (client.user.equals(user)) return;
let member = reaction.message.guild.members.cache.get(user.id);

if (!member) return;

let cleanEmoji = require("./getEmoji")(reaction.emoji);
for (let { channelID, reactions, limited } of self.config) {

for (let { messageID, channelID, reactions, limit, restrictions } of config) {
if (channelID != reaction.message.channel.id) continue;
if (messageID != reaction.message.id) continue;
if (restrictions && !member.permissions.has(restrictions)) {
await reaction.users.remove(user.id).catch((err) => {
throw new SuperError("CanNotRemoveReaction", err.toString());
});
continue;
}

let addRole = [];

Expand All @@ -18,13 +29,18 @@ module.exports = async (self) => {

for (let { emoji, roles } of reactions) {
if (cleanEmoji == emoji) whitelist.push.apply(whitelist, roles);
blacklist.push.apply(blacklist, roles);
else blacklist.push.apply(blacklist, roles);
};

if (limited) {
addRole = addRole.filter((role) => {
return !blacklist.includes(role) && !member.roles.cache.has(role);
let reactionSize = reaction.message.reactions.cache.filter(reaction => {
return reaction.users.cache.has(user.id);
}).size;

if (reactionSize > limit) {
await reaction.users.remove(user.id).catch((err) => {
throw new SuperError("CanNotRemoveReaction", err.toString());
});
continue;
}

addRole.push.apply(addRole, whitelist);
Expand All @@ -33,20 +49,19 @@ module.exports = async (self) => {
throw new SuperError("CanNotSetUserRoles", err.toString());
});

if (limited) await reaction.users.remove(user.id).catch((err) => {
throw new SuperError("CanNotRemoveReaction", err.toString());
});
};
});

self.client.on("messageReactionRemove", async(reaction, user) => {
if (self.client.user.equals(user)) return;


client.on("messageReactionRemove", async(reaction, user) => {
if (client.user.equals(user)) return;
let member = reaction.message.guild.members.cache.get(user.id);
let cleanEmoji = require("./getEmoji")(reaction.emoji);

for (let { channelID, reactions, limited} of self.config) {
if (limited) continue;
for (let { messageID, channelID, reactions } of config) {
if (channelID != reaction.message.channel.id) continue;
if (messageID != reaction.message.id) continue;

let keep = [];
let remove = [];
Expand Down
10 changes: 6 additions & 4 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const ReactionRole = require(".");
const reactionRole = new ReactionRole("NTkwNzk4MTcyNjcwOTE4NjY5.Xu91iA.trM8YH7NpP4umusk8Bpwy-CxONE");
const reactionRole = new ReactionRole("TOKEN");

let option1 = reactionRole.createOption("✅", "714542230135767060");
let option2 = reactionRole.createOption("cuteknife:715959996029993009", "717633838616018944");
reactionRole.createMessage("724296760129749014", "717628563813171260", false, option1, option2);
let option1 = reactionRole.createOption("✅", "697809380137107478");
let option2 = reactionRole.createOption("rifcat:720623460321198152", "708355720436777033");
let option3 = reactionRole.createOption("eywreyiz:720623464507244576", "703908514887761930");

reactionRole.createMessage("727272497157898372", "702115562158948432", 2, [ "MANAGE_GUILD" ], option1, option2, option3);

reactionRole.init();

0 comments on commit 6e0f19b

Please sign in to comment.