Skip to content

Commit

Permalink
Added unlock button + locking owner
Browse files Browse the repository at this point in the history
  • Loading branch information
Arisamiga committed Jul 26, 2023
1 parent 28bd57e commit ed03793
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Change the following
"answer_category": "(Enter id of Category for Tickets)",
"allow_user_delete": false, (Allow users to delete their own tickets)
"allow_user_lock": false, (Allow users to lock their own tickets)
"allow_user_unlock": false, (Allow users to unlock their own tickets)
"one_app": true (Pick either True = To allow only 1 ticket to exist at a time / False = To allow multiple ticket to exist at a time)
}
Expand Down
3 changes: 2 additions & 1 deletion commands/startapps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const contining = async (client, message, user) => {
fs.readFile('./collectors.json', 'utf8', function readFileCallback(err, data) {
if (err) console.error(err);
const obj = JSON.parse(data);
obj.tickets.push({ id: messageID, channelId: channelID });
obj.tickets.push({ id: messageID, channelId: channelID, owner: user.id });
const json = JSON.stringify(obj);
fs.writeFile('./collectors.json', json, 'utf8', (err) => {
if (err) throw err;
Expand Down Expand Up @@ -84,6 +84,7 @@ const contining = async (client, message, user) => {
embeds: [reactionMessageEmbed],
});
await reactionMessage.react('🔒');
await reactionMessage.react('🔓');
await reactionMessage.react('⛔');

addToTickets(reactionMessage.id, channel.id);
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"answer_category": "(Enter id of Category for Tickets)",
"allow_user_delete": false,
"allow_user_lock": false,
"allow_user_unlock": false,
"one_app": true
}
65 changes: 43 additions & 22 deletions events/messageReactionAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,51 @@ module.exports = (client, messageReaction, user) => {
// Handle tickets
if (collectors.tickets.filter((e) => e.id === messageReaction.message.id).length > 0) {
let channel = messageReaction.message.guild.channels.cache.find((channel) => channel.id === messageReaction.message.channel.id);
switch (messageReaction.emoji.name) {
case '🔒':
if (!checkUser(messageReaction.message, user) && !config.allow_user_lock) {
user.send('Only Staff can lock the channels');
return messageReaction.users.remove(user.id);
}
channel.permissionOverwrites.edit(user.id, {
SEND_MESSAGES: false,
});
return messageReaction.message.channel.send('Channel Locked 🔒');
case '⛔':
if (!messageReaction.message.guild.channels.cache.find((c) => c.name.toLowerCase() === channel.name)) return;
if (!checkUser(messageReaction.message, user) && !config.allow_user_delete) {
user.send('Only Staff can delete the channels').catch(console.error);
return messageReaction.users.remove(user.id);
}
const ownerID = collectors.tickets.filter((e) => e.id === messageReaction.message.id)[0].owner;
// Get owner of the ticket
client.users.fetch(ownerID).then((owner) => {
switch (messageReaction.emoji.name) {
case '🔒':
if (!checkUser(messageReaction.message, user) && !config.allow_user_lock) {
user.send('Only Staff can lock the channels');
return messageReaction.users.remove(user.id);
}
if (channel.permissionOverwrites.cache.get(ownerID)?.deny.has('SEND_MESSAGES')) {
user.send('This channel is already locked');
return messageReaction.users.remove(user.id);
}
channel.permissionOverwrites.edit(owner, {
SEND_MESSAGES: false,
});
return messageReaction.message.channel.send('Channel Locked 🔒');
case '🔓':
if (!checkUser(messageReaction.message, user) && !config.allow_user_unlock) {
user.send('Only Staff can unlock the channels');
return messageReaction.users.remove(user.id);
}
if (channel.permissionOverwrites.cache.get(ownerID)?.allow.has('SEND_MESSAGES')) {
user.send('This channel is already unlocked');
return messageReaction.users.remove(user.id);
}
channel.permissionOverwrites.edit(owner, {
SEND_MESSAGES: true,
});
return messageReaction.message.channel.send('Channel Unlocked 🔓');
case '⛔':
if (!messageReaction.message.guild.channels.cache.find((c) => c.name.toLowerCase() === channel.name)) return;
if (!checkUser(messageReaction.message, user) && !config.allow_user_delete) {
user.send('Only Staff can delete the channels').catch(console.error);
return messageReaction.users.remove(user.id);
}

setTimeout(() => {
if (messageReaction.message.guild.channels.cache.find((c) => c.name.toLowerCase() === channel.name)) channel.delete();
removeTicketfromCollectors(messageReaction.message.id);
}, 5000);
setTimeout(() => {
if (messageReaction.message.guild.channels.cache.find((c) => c.name.toLowerCase() === channel.name)) channel.delete();
removeTicketfromCollectors(messageReaction.message.id);
}, 5000);

return messageReaction.message.channel.send('Deleting this channel in 5 seconds!');
}
return messageReaction.message.channel.send('Deleting this channel in 5 seconds!');
}
});
}
};

Expand Down

0 comments on commit ed03793

Please sign in to comment.