mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-17 17:23:08 +02:00
feat: update command permissions (closes #392)
This commit is contained in:
parent
b8c2a7cc13
commit
b14f057dd0
@ -1,6 +1,7 @@
|
|||||||
const { logAdminEvent } = require('../../../../../../../lib/logging');
|
const { logAdminEvent } = require('../../../../../../../lib/logging');
|
||||||
const { updateStaffRoles } = require('../../../../../../../lib/users');
|
const { updateStaffRoles } = require('../../../../../../../lib/users');
|
||||||
const { randomUUID } = require('crypto');
|
const { randomUUID } = require('crypto');
|
||||||
|
const { ApplicationCommandPermissionType } = require('discord.js');
|
||||||
|
|
||||||
module.exports.delete = fastify => ({
|
module.exports.delete = fastify => ({
|
||||||
handler: async (req, res) => {
|
handler: async (req, res) => {
|
||||||
@ -71,6 +72,7 @@ module.exports.patch = fastify => ({
|
|||||||
const client = res.context.config.client;
|
const client = res.context.config.client;
|
||||||
const guildId = req.params.guild;
|
const guildId = req.params.guild;
|
||||||
const categoryId = Number(req.params.category);
|
const categoryId = Number(req.params.category);
|
||||||
|
/** @type {import('discord.js').Guild} */
|
||||||
const guild = client.guilds.cache.get(req.params.guild);
|
const guild = client.guilds.cache.get(req.params.guild);
|
||||||
const data = req.body;
|
const data = req.body;
|
||||||
|
|
||||||
@ -144,6 +146,37 @@ module.exports.patch = fastify => ({
|
|||||||
await client.tickets.getCategory(categoryId, true);
|
await client.tickets.getCategory(categoryId, true);
|
||||||
await updateStaffRoles(guild);
|
await updateStaffRoles(guild);
|
||||||
|
|
||||||
|
if (req.user.payload.accessToken && JSON.stringify(category.staffRoles) !== JSON.stringify(original.staffRoles)) {
|
||||||
|
Promise.all([
|
||||||
|
'Create ticket for user',
|
||||||
|
'claim',
|
||||||
|
'force-close',
|
||||||
|
'move',
|
||||||
|
'priority',
|
||||||
|
'release',
|
||||||
|
].map(name =>
|
||||||
|
client.application.commands.permissions.set({
|
||||||
|
command: client.application.commands.cache.find(cmd => cmd.name === name),
|
||||||
|
guild,
|
||||||
|
permissions: [
|
||||||
|
{
|
||||||
|
id: guild.id, // @everyone
|
||||||
|
permission: false,
|
||||||
|
type: ApplicationCommandPermissionType.Role,
|
||||||
|
},
|
||||||
|
...category.staffRoles.map(id => ({
|
||||||
|
id,
|
||||||
|
permission: true,
|
||||||
|
type: ApplicationCommandPermissionType.Role,
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
token: req.user.payload.accessToken,
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.then(() => client.log.success('Updated application command permissions in "%s"', guild.name))
|
||||||
|
.catch(error => client.log.error(error));
|
||||||
|
}
|
||||||
|
|
||||||
logAdminEvent(client, {
|
logAdminEvent(client, {
|
||||||
action: 'update',
|
action: 'update',
|
||||||
diff: {
|
diff: {
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
const { logAdminEvent } = require('../../../../../../lib/logging');
|
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||||
const { updateStaffRoles } = require('../../../../../../lib/users');
|
const { updateStaffRoles } = require('../../../../../../lib/users');
|
||||||
const emoji = require('node-emoji');
|
const emoji = require('node-emoji');
|
||||||
const { ChannelType: { GuildCategory } } = require('discord.js');
|
const {
|
||||||
|
ApplicationCommandPermissionType,
|
||||||
|
ChannelType: { GuildCategory },
|
||||||
|
} = require('discord.js');
|
||||||
const ms = require('ms');
|
const ms = require('ms');
|
||||||
|
|
||||||
module.exports.get = fastify => ({
|
module.exports.get = fastify => ({
|
||||||
@ -98,6 +101,37 @@ module.exports.post = fastify => ({
|
|||||||
await client.tickets.getCategory(category.id, true);
|
await client.tickets.getCategory(category.id, true);
|
||||||
await updateStaffRoles(guild);
|
await updateStaffRoles(guild);
|
||||||
|
|
||||||
|
if (req.user.payload.accessToken) {
|
||||||
|
Promise.all([
|
||||||
|
'Create ticket for user',
|
||||||
|
'claim',
|
||||||
|
'force-close',
|
||||||
|
'move',
|
||||||
|
'priority',
|
||||||
|
'release',
|
||||||
|
].map(name =>
|
||||||
|
client.application.commands.permissions.set({
|
||||||
|
command: client.application.commands.cache.find(cmd => cmd.name === name),
|
||||||
|
guild,
|
||||||
|
permissions: [
|
||||||
|
{
|
||||||
|
id: guild.id, // @everyone
|
||||||
|
permission: false,
|
||||||
|
type: ApplicationCommandPermissionType.Role,
|
||||||
|
},
|
||||||
|
...category.staffRoles.map(id => ({
|
||||||
|
id,
|
||||||
|
permission: true,
|
||||||
|
type: ApplicationCommandPermissionType.Role,
|
||||||
|
})),
|
||||||
|
],
|
||||||
|
token: req.user.payload.accessToken,
|
||||||
|
}),
|
||||||
|
))
|
||||||
|
.then(() => client.log.success('Updated application command permissions in "%s"', guild.name))
|
||||||
|
.catch(error => client.log.error(error));
|
||||||
|
}
|
||||||
|
|
||||||
logAdminEvent(client, {
|
logAdminEvent(client, {
|
||||||
action: 'create',
|
action: 'create',
|
||||||
guildId: guild.id,
|
guildId: guild.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user