mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-07 02:21:27 +03:00
More fixes
This commit is contained in:
@@ -63,6 +63,9 @@ module.exports.patch = fastify => ({
|
||||
const original = req.params.category && await client.prisma.category.findUnique({ where: { id: categoryId } });
|
||||
if (!original) return res.status(404);
|
||||
|
||||
if (data.hasOwnProperty('id')) delete data.id;
|
||||
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
||||
|
||||
const category = await client.prisma.category.update({
|
||||
data: {
|
||||
...data,
|
||||
|
@@ -1,4 +1,6 @@
|
||||
const { logAdminEvent } = require('../../../../../../lib/logging');
|
||||
const emoji = require('node-emoji');
|
||||
const { ChannelType: { GuildCategory } } = require('discord.js');
|
||||
|
||||
module.exports.get = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
@@ -42,14 +44,17 @@ module.exports.post = fastify => ({
|
||||
const user = await client.users.fetch(req.user.payload.id);
|
||||
const guild = client.guilds.cache.get(req.params.guild);
|
||||
const data = req.body;
|
||||
const allow = ['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'SEND_MESSAGES', 'EMBED_LINKS', 'ATTACH_FILES'];
|
||||
const allow = ['ViewChannel', 'ReadMessageHistory', 'SendMessages', 'EmbedLinks', 'AttachFiles'];
|
||||
|
||||
if (!data.discordCategory) {
|
||||
const channel = await guild.channels.create(data.name, {
|
||||
let name = data.name;
|
||||
if (emoji.hasEmoji(data.emoji)) name = `${emoji.get(data.emoji)} ${name}`;
|
||||
const channel = await guild.channels.create({
|
||||
name,
|
||||
permissionOverwrites: [
|
||||
...[
|
||||
{
|
||||
deny: ['VIEW_CHANNEL'],
|
||||
deny: ['ViewChannel'],
|
||||
id: guild.roles.everyone,
|
||||
},
|
||||
{
|
||||
@@ -64,12 +69,12 @@ module.exports.post = fastify => ({
|
||||
],
|
||||
position: 1,
|
||||
reason: `Tickets category created by ${user.tag}`,
|
||||
type: 'GUILD_CATEGORY',
|
||||
type: GuildCategory,
|
||||
});
|
||||
data.discordCategory = channel.id;
|
||||
}
|
||||
|
||||
data.channelName ??= 'ticket-{num}';
|
||||
data.channelName ||= 'ticket-{num}'; // not ??=, expect empty string
|
||||
|
||||
const category = await client.prisma.category.create({
|
||||
data: {
|
||||
|
@@ -1,4 +1,5 @@
|
||||
const { logAdminEvent } = require('../../../../../lib/logging.js');
|
||||
const { Colors } = require('discord.js');
|
||||
|
||||
module.exports.delete = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
@@ -37,16 +38,25 @@ module.exports.get = fastify => ({
|
||||
|
||||
module.exports.patch = fastify => ({
|
||||
handler: async (req, res) => {
|
||||
if (req.body.hasOwnProperty('id')) delete req.body.id;
|
||||
if (req.body.hasOwnProperty('createdAt')) delete req.body.createdAt;
|
||||
const data = req.body;
|
||||
if (data.hasOwnProperty('id')) delete data.id;
|
||||
if (data.hasOwnProperty('createdAt')) delete data.createdAt;
|
||||
const colours = ['errorColour', 'primaryColour', 'successColour'];
|
||||
for (const c of colours) {
|
||||
if (data[c] && !data[c].startsWith('#') && !(data[c] in Colors)) { // if not null/empty and not hex
|
||||
throw new Error(`${data[c]} is not a valid colour. Valid colours are HEX and: ${Object.keys(Colors).join(', ')}`);
|
||||
}
|
||||
}
|
||||
|
||||
/** @type {import('client')} */
|
||||
const client = res.context.config.client;
|
||||
const id = req.params.guild;
|
||||
const original = await client.prisma.guild.findUnique({ where: { id } });
|
||||
const settings = await client.prisma.guild.update({
|
||||
data: req.body,
|
||||
data: data,
|
||||
where: { id },
|
||||
});
|
||||
|
||||
logAdminEvent(client, {
|
||||
action: 'update',
|
||||
diff: {
|
||||
@@ -56,7 +66,7 @@ module.exports.patch = fastify => ({
|
||||
guildId: id,
|
||||
target: {
|
||||
id,
|
||||
name: client.guilds.cache.get(id),
|
||||
name: client.guilds.cache.get(id).name,
|
||||
type: 'settings',
|
||||
},
|
||||
userId: req.user.payload.id,
|
||||
|
Reference in New Issue
Block a user