From 1c226e8f7ebccbb3d0e512e7eb5ca4e90193e457 Mon Sep 17 00:00:00 2001 From: "Isaac (eartharoid)" Date: Sun, 20 Sep 2020 22:01:10 +0100 Subject: [PATCH] Added extremely basic multi-role support --- src/commands/add.js | 3 ++- src/commands/close.js | 3 ++- src/commands/delete.js | 2 +- src/commands/new.js | 6 +++--- src/commands/remove.js | 3 ++- src/commands/tickets.js | 7 ++++--- src/commands/transcript.js | 3 ++- src/events/messageReactionAdd.js | 6 +++--- src/index.js | 1 + src/modules/utils.js | 11 +++++++++++ user/config.js | 2 +- 11 files changed, 32 insertions(+), 15 deletions(-) diff --git a/src/commands/add.js b/src/commands/add.js index dc500d7..7b96afa 100644 --- a/src/commands/add.js +++ b/src/commands/add.js @@ -9,6 +9,7 @@ const { MessageEmbed } = require('discord.js'); const ChildLogger = require('leekslazylogger').ChildLogger; const log = new ChildLogger(); +const utils = require('../modules/utils'); module.exports = { name: 'add', @@ -52,7 +53,7 @@ module.exports = { } } - if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) + if(message.author.id !== ticket.creator && !utils.isStaff(message.member)) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) diff --git a/src/commands/close.js b/src/commands/close.js index 3bd2841..f16d223 100644 --- a/src/commands/close.js +++ b/src/commands/close.js @@ -13,6 +13,7 @@ const { } = require('discord.js'); const fs = require('fs'); const archive = require('../modules/archive'); +const utils = require('../modules/utils'); module.exports = { name: 'close', @@ -66,7 +67,7 @@ module.exports = { return message.channel.send(notTicket); } - if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) + if (message.author.id !== ticket.creator && !utils.isStaff(message.member)) return channel.send( new MessageEmbed() .setColor(config.err_colour) diff --git a/src/commands/delete.js b/src/commands/delete.js index d06a51e..ff2c988 100644 --- a/src/commands/delete.js +++ b/src/commands/delete.js @@ -65,7 +65,7 @@ module.exports = { return message.channel.send(notTicket); } - if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) + if (message.author.id !== ticket.creator && !utils.isStaff(message.member)) return channel.send( new MessageEmbed() .setColor(config.err_colour) diff --git a/src/commands/new.js b/src/commands/new.js index 162d7aa..0ccf5ee 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -22,13 +22,13 @@ module.exports = { const guild = client.guilds.cache.get(config.guild); - const supportRole = guild.roles.cache.get(config.staff_role); + const supportRole = guild.roles.cache.get(config.staff_roles[0]); if (!supportRole) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) .setTitle(':x: **Error**') - .setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``) + .setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_roles[0]}\``) .setFooter(guild.name, guild.iconURL()) ); @@ -140,7 +140,7 @@ module.exports = { let ping; switch (config.tickets.ping) { case 'staff': - ping = `<@&${config.staff_role}>,\n`; + ping = `<@&${config.staff_roles[0]}>,\n`; break; case false: ping = ''; diff --git a/src/commands/remove.js b/src/commands/remove.js index 48b2de3..31f4f38 100644 --- a/src/commands/remove.js +++ b/src/commands/remove.js @@ -9,6 +9,7 @@ const { MessageEmbed } = require('discord.js'); const ChildLogger = require('leekslazylogger').ChildLogger; const log = new ChildLogger(); +const utils = require('../modules/utils'); module.exports = { name: 'remove', @@ -52,7 +53,7 @@ module.exports = { } } - if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) + if(message.author.id !== ticket.creator && !utils.isStaff(message.member)) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) diff --git a/src/commands/tickets.js b/src/commands/tickets.js index d125865..624fd42 100644 --- a/src/commands/tickets.js +++ b/src/commands/tickets.js @@ -8,6 +8,7 @@ const { MessageEmbed } = require('discord.js'); const fs = require('fs'); +const utils = require('../modules/utils'); module.exports = { name: 'tickets', @@ -20,13 +21,13 @@ module.exports = { const guild = client.guilds.cache.get(config.guild); - const supportRole = guild.roles.cache.get(config.staff_role); + const supportRole = guild.roles.cache.get(config.staff_roles[0]); if (!supportRole) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) .setTitle(':x: **Error**') - .setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``) + .setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_roles[0]}\``) .setFooter(guild.name, guild.iconURL()) ); @@ -34,7 +35,7 @@ module.exports = { let user = message.mentions.users.first() || guild.members.cache.get(args[0]); if(user) { - if(!message.member.roles.cache.has(config.staff_role)) + if(!utils.isStaff(message.member)) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) diff --git a/src/commands/transcript.js b/src/commands/transcript.js index 5c6be40..d0cefde 100644 --- a/src/commands/transcript.js +++ b/src/commands/transcript.js @@ -10,6 +10,7 @@ const fs = require('fs'); const { MessageEmbed } = require('discord.js'); +const utils = require('../modules/utils'); module.exports = { name: 'transcript', @@ -41,7 +42,7 @@ module.exports = { .setFooter(guild.name, guild.iconURL()) ); - if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role)) + if (message.author.id !== ticket.creator && !utils.isStaff(message.member)) return message.channel.send( new MessageEmbed() .setColor(config.err_colour) diff --git a/src/events/messageReactionAdd.js b/src/events/messageReactionAdd.js index a1c212e..310745e 100644 --- a/src/events/messageReactionAdd.js +++ b/src/events/messageReactionAdd.js @@ -34,13 +34,13 @@ module.exports = { let channel = r.message.channel; - const supportRole = channel.guild.roles.cache.get(config.staff_role); + const supportRole = channel.guild.roles.cache.get(config.staff_roles[0]); if (!supportRole) return channel.send( new MessageEmbed() .setColor(config.err_colour) .setTitle(':x: **Error**') - .setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``) + .setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_roles[0]}\``) .setFooter(channel.guild.name, channel.guild.iconURL()) ); @@ -144,7 +144,7 @@ module.exports = { let ping; switch (config.tickets.ping) { case 'staff': - ping = `<@&${config.staff_role}>,\n`; + ping = `<@&${config.staff_roles[0]}>,\n`; break; case false: ping = ''; diff --git a/src/index.js b/src/index.js index 744d890..7095916 100644 --- a/src/index.js +++ b/src/index.js @@ -23,6 +23,7 @@ const client = new Discord.Client({ client.events = new Discord.Collection(); client.commands = new Discord.Collection(); client.cooldowns = new Discord.Collection(); +client.config = config; const utils = require('./modules/utils'); const leeks = require('leeks.js'); diff --git a/src/modules/utils.js b/src/modules/utils.js index d86de48..19118c4 100644 --- a/src/modules/utils.js +++ b/src/modules/utils.js @@ -14,5 +14,16 @@ module.exports = { */ plural(word, num) { return num !== 1 ? word + 's' : word; + }, + + isStaff(member) { + let staff = false; + + member.client.config.staff_roles.forEach(id => { + if (member.roles.cache.has(id)) + staff = true; + }); + + return staff; } }; \ No newline at end of file diff --git a/user/config.js b/user/config.js index ead0ac6..e8d96cd 100644 --- a/user/config.js +++ b/user/config.js @@ -36,7 +36,7 @@ module.exports = { cooldown: 3, guild: '', // ID of your guild - staff_role: '', // ID of your Support Team role + staff_roles: [''], // ID of your Support Team role tickets: { category: '', // ID of your tickets category