Skip to content

Commit ac48177

Browse files
committed
Add support roles and ping roles per ticket category
1 parent b33519e commit ac48177

19 files changed

+140
-129
lines changed

commands/Tickets/add.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const fs = require("fs");
77
const yaml = require("yaml");
88
const configFile = fs.readFileSync("./config.yml", "utf8");
99
const config = yaml.parse(configFile);
10-
const { ticketsDB, sanitizeInput, logMessage } = require("../../index.js");
10+
const {
11+
ticketsDB,
12+
sanitizeInput,
13+
logMessage,
14+
checkSupportRole,
15+
} = require("../../index.js");
1116

1217
module.exports = {
1318
enabled: config.commands.add.enabled,
@@ -32,11 +37,8 @@ module.exports = {
3237
});
3338
}
3439

35-
if (
36-
!interaction.member.roles.cache.some((role) =>
37-
config.support_role_ids.includes(role.id),
38-
)
39-
) {
40+
const hasSupportRole = await checkSupportRole(interaction);
41+
if (!hasSupportRole) {
4042
return interaction.reply({
4143
content: config.errors.not_allowed,
4244
ephemeral: true,

commands/Tickets/alert.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ const fs = require("fs");
1010
const yaml = require("yaml");
1111
const configFile = fs.readFileSync("./config.yml", "utf8");
1212
const config = yaml.parse(configFile);
13-
const { ticketsDB, logMessage, client } = require("../../index.js");
13+
const {
14+
ticketsDB,
15+
logMessage,
16+
client,
17+
checkSupportRole,
18+
} = require("../../index.js");
1419

1520
module.exports = {
1621
enabled: config.commands.alert.enabled,
@@ -29,11 +34,8 @@ module.exports = {
2934
});
3035
}
3136

32-
if (
33-
!interaction.member.roles.cache.some((role) =>
34-
config.support_role_ids.includes(role.id),
35-
)
36-
) {
37+
const hasSupportRole = await checkSupportRole(interaction);
38+
if (!hasSupportRole) {
3739
return interaction.reply({
3840
content: config.errors.not_allowed,
3941
ephemeral: true,

commands/Tickets/claim.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
logMessage,
1717
ticketCategories,
1818
mainDB,
19+
checkSupportRole,
1920
} = require("../../index.js");
2021

2122
module.exports = {
@@ -35,11 +36,8 @@ module.exports = {
3536
});
3637
}
3738

38-
if (
39-
!interaction.member.roles.cache.some((role) =>
40-
config.support_role_ids.includes(role.id),
41-
)
42-
) {
39+
const hasSupportRole = await checkSupportRole(interaction);
40+
if (!hasSupportRole) {
4341
return interaction.reply({
4442
content: config.errors.not_allowed,
4543
ephemeral: true,
@@ -124,7 +122,7 @@ module.exports = {
124122

125123
Object.keys(ticketCategories).forEach(async (id) => {
126124
if (ticketButton === id) {
127-
config.support_role_ids.forEach(async (roleId) => {
125+
ticketCategories[id].support_role_ids.forEach(async (roleId) => {
128126
await interaction.channel.permissionOverwrites
129127
.edit(roleId, {
130128
SendMessages: true,

commands/Tickets/close.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
ticketCategories,
1818
sanitizeInput,
1919
logMessage,
20+
checkSupportRole,
2021
} = require("../../index.js");
2122

2223
module.exports = {
@@ -45,11 +46,8 @@ module.exports = {
4546
});
4647
}
4748

48-
if (
49-
!interaction.member.roles.cache.some((role) =>
50-
config.support_role_ids.includes(role.id),
51-
)
52-
) {
49+
const hasSupportRole = await checkSupportRole(interaction);
50+
if (!hasSupportRole) {
5351
return interaction.reply({
5452
content: config.errors.not_allowed,
5553
ephemeral: true,
@@ -177,7 +175,7 @@ module.exports = {
177175
lockPermissions: false,
178176
});
179177

180-
config.support_role_ids.forEach(async (roleId) => {
178+
category.support_role_ids.forEach(async (roleId) => {
181179
await interaction.channel.permissionOverwrites
182180
.edit(roleId, {
183181
SendMessages: false,

commands/Tickets/delete.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
sanitizeInput,
1919
logMessage,
2020
saveTranscriptTxt,
21+
checkSupportRole,
2122
} = require("../../index.js");
2223

2324
module.exports = {
@@ -37,11 +38,8 @@ module.exports = {
3738
});
3839
}
3940

40-
if (
41-
!interaction.member.roles.cache.some((role) =>
42-
config.support_role_ids.includes(role.id),
43-
)
44-
) {
41+
const hasSupportRole = await checkSupportRole(interaction);
42+
if (!hasSupportRole) {
4543
return interaction.reply({
4644
content: config.errors.not_allowed,
4745
ephemeral: true,

commands/Tickets/move.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const {
1212
sanitizeInput,
1313
logMessage,
1414
ticketCategories,
15+
checkSupportRole,
1516
} = require("../../index.js");
1617
const customIds = Object.keys(ticketCategories);
1718
const choices = customIds.map((customId) => {
@@ -42,11 +43,8 @@ module.exports = {
4243
});
4344
}
4445

45-
if (
46-
!interaction.member.roles.cache.some((role) =>
47-
config.support_role_ids.includes(role.id),
48-
)
49-
) {
46+
const hasSupportRole = await checkSupportRole(interaction);
47+
if (!hasSupportRole) {
5048
return interaction.reply({
5149
content: config.errors.not_allowed,
5250
ephemeral: true,

commands/Tickets/panel.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ const fs = require("fs");
1212
const yaml = require("yaml");
1313
const configFile = fs.readFileSync("./config.yml", "utf8");
1414
const config = yaml.parse(configFile);
15-
const { ticketCategories, logMessage, mainDB } = require("../../index.js");
15+
const {
16+
ticketCategories,
17+
logMessage,
18+
mainDB,
19+
checkSupportRole,
20+
} = require("../../index.js");
1621

1722
module.exports = {
1823
enabled: config.commands.panel.enabled,
@@ -24,11 +29,8 @@ module.exports = {
2429
)
2530
.setDMPermission(false),
2631
async execute(interaction) {
27-
if (
28-
!interaction.member.roles.cache.some((role) =>
29-
config.support_role_ids.includes(role.id),
30-
)
31-
) {
32+
const hasSupportRole = await checkSupportRole(interaction);
33+
if (!hasSupportRole) {
3234
return interaction.reply({
3335
content: config.errors.not_allowed,
3436
ephemeral: true,

commands/Tickets/pin.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fs = require("fs");
77
const yaml = require("yaml");
88
const configFile = fs.readFileSync("./config.yml", "utf8");
99
const config = yaml.parse(configFile);
10-
const { ticketsDB, logMessage } = require("../../index.js");
10+
const { ticketsDB, logMessage, checkSupportRole } = require("../../index.js");
1111

1212
module.exports = {
1313
enabled: config.commands.pin.enabled,
@@ -26,11 +26,8 @@ module.exports = {
2626
});
2727
}
2828

29-
if (
30-
!interaction.member.roles.cache.some((role) =>
31-
config.support_role_ids.includes(role.id),
32-
)
33-
) {
29+
const hasSupportRole = await checkSupportRole(interaction);
30+
if (!hasSupportRole) {
3431
return interaction.reply({
3532
content: config.errors.not_allowed,
3633
ephemeral: true,

commands/Tickets/remove.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const fs = require("fs");
77
const yaml = require("yaml");
88
const configFile = fs.readFileSync("./config.yml", "utf8");
99
const config = yaml.parse(configFile);
10-
const { ticketsDB, sanitizeInput, logMessage } = require("../../index.js");
10+
const {
11+
ticketsDB,
12+
sanitizeInput,
13+
logMessage,
14+
checkSupportRole,
15+
} = require("../../index.js");
1116

1217
module.exports = {
1318
enabled: config.commands.remove.enabled,
@@ -32,11 +37,8 @@ module.exports = {
3237
});
3338
}
3439

35-
if (
36-
!interaction.member.roles.cache.some((role) =>
37-
config.support_role_ids.includes(role.id),
38-
)
39-
) {
40+
const hasSupportRole = await checkSupportRole(interaction);
41+
if (!hasSupportRole) {
4042
return interaction.reply({
4143
content: config.errors.not_allowed,
4244
ephemeral: true,

commands/Tickets/rename.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ const fs = require("fs");
77
const yaml = require("yaml");
88
const configFile = fs.readFileSync("./config.yml", "utf8");
99
const config = yaml.parse(configFile);
10-
const { ticketsDB, sanitizeInput, logMessage } = require("../../index.js");
10+
const {
11+
ticketsDB,
12+
sanitizeInput,
13+
logMessage,
14+
checkSupportRole,
15+
} = require("../../index.js");
1116

1217
module.exports = {
1318
enabled: config.commands.rename.enabled,
@@ -29,11 +34,8 @@ module.exports = {
2934
});
3035
}
3136

32-
if (
33-
!interaction.member.roles.cache.some((role) =>
34-
config.support_role_ids.includes(role.id),
35-
)
36-
) {
37+
const hasSupportRole = await checkSupportRole(interaction);
38+
if (!hasSupportRole) {
3739
return interaction.reply({
3840
content: config.errors.not_allowed,
3941
ephemeral: true,

0 commit comments

Comments
 (0)