mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-23 00:03:09 +02:00
Improvements and fixes
This commit is contained in:
parent
234d1cd511
commit
ae1d24236f
@ -78,11 +78,13 @@ module.exports = {
|
|||||||
.setFooter(guild.name, guild.iconURL())
|
.setFooter(guild.name, guild.iconURL())
|
||||||
);
|
);
|
||||||
|
|
||||||
let success;
|
|
||||||
let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log)
|
|
||||||
? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\``
|
|
||||||
: '';
|
|
||||||
if (config.commands.close.confirmation) {
|
if (config.commands.close.confirmation) {
|
||||||
|
let success;
|
||||||
|
let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log)
|
||||||
|
? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\``
|
||||||
|
: '';
|
||||||
|
|
||||||
let confirm = await message.channel.send(
|
let confirm = await message.channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(config.colour)
|
.setColor(config.colour)
|
||||||
@ -96,11 +98,10 @@ module.exports = {
|
|||||||
|
|
||||||
const collector = confirm.createReactionCollector(
|
const collector = confirm.createReactionCollector(
|
||||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||||
time: 15000
|
time: 15000
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.on('collect', async () => {
|
collector.on('collect', async () => {
|
||||||
let users = [];
|
|
||||||
if (channel.id !== message.channel.id) {
|
if (channel.id !== message.channel.id) {
|
||||||
channel.send(
|
channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
@ -121,11 +122,15 @@ module.exports = {
|
|||||||
.setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.')
|
.setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.')
|
||||||
.setFooter(guild.name, guild.iconURL())
|
.setFooter(guild.name, guild.iconURL())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if (channel.id !== message.channel.id)
|
||||||
|
message.delete({
|
||||||
|
timeout: 5000
|
||||||
|
}).then(() => confirm.delete());
|
||||||
|
|
||||||
success = true;
|
success = true;
|
||||||
closeTicket();
|
close();
|
||||||
if (config.commands.close.send_transcripts) {
|
|
||||||
sendTranscript();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -142,58 +147,19 @@ module.exports = {
|
|||||||
|
|
||||||
message.delete({
|
message.delete({
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
})
|
}).then(() => confirm.delete());
|
||||||
.then(() => confirm.delete());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
success = true;
|
close();
|
||||||
closeTicket();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function closeTicket() {
|
|
||||||
// update database
|
async function close () {
|
||||||
ticket.update({
|
let users = [];
|
||||||
open: false
|
|
||||||
}, {
|
|
||||||
where: {
|
|
||||||
channel: channel.id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// delete messages and channel
|
|
||||||
setTimeout(() => {
|
|
||||||
channel.delete();
|
|
||||||
if (channel.id !== message.channel.id)
|
|
||||||
message.delete()
|
|
||||||
.then(() => confirm.delete());
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`);
|
|
||||||
|
|
||||||
if (config.logs.discord.enabled) {
|
|
||||||
let embed = new MessageEmbed()
|
|
||||||
.setColor(config.colour)
|
|
||||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
|
||||||
.setTitle(`Ticket ${ticket.id} closed`)
|
|
||||||
.addField('Creator', `<@${ticket.creator}>`, true)
|
|
||||||
.addField('Closed by', message.author, true)
|
|
||||||
.setFooter(guild.name, guild.iconURL())
|
|
||||||
.setTimestamp();
|
|
||||||
|
|
||||||
if (users.length > 1)
|
|
||||||
embed.addField('Members', users.map(u => `<@${u}>`).join('\n'));
|
|
||||||
|
|
||||||
client.channels.cache.get(config.logs.discord.channel).send(embed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (config.commands.close.send_transcripts) {
|
|
||||||
sendTranscript();
|
|
||||||
}
|
|
||||||
async function sendTranscript() {
|
|
||||||
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
|
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
|
||||||
let u = await client.users.fetch(ticket.creator);
|
let u = await client.users.fetch(ticket.creator);
|
||||||
|
|
||||||
if (u) {
|
if (u) {
|
||||||
let dm;
|
let dm;
|
||||||
try {
|
try {
|
||||||
@ -202,7 +168,6 @@ module.exports = {
|
|||||||
log.warn(`Could not create DM channel with ${u.tag}`);
|
log.warn(`Could not create DM channel with ${u.tag}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let res = {};
|
let res = {};
|
||||||
const embed = new MessageEmbed()
|
const embed = new MessageEmbed()
|
||||||
.setColor(config.colour)
|
.setColor(config.colour)
|
||||||
@ -229,17 +194,47 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.embed = embed;
|
res.embed = embed;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (success) {
|
if (config.commands.close.send_transcripts) dm.send(res);
|
||||||
dm.send(res);
|
if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res);
|
||||||
if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.channel.send('❌ Couldn\'t send DM or transcript log message');
|
message.channel.send('❌ Couldn\'t send DM or transcript log message');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
// update database
|
||||||
|
ticket.update({
|
||||||
|
open: false
|
||||||
|
}, {
|
||||||
|
where: {
|
||||||
|
channel: channel.id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// delete channel
|
||||||
|
channel.delete({
|
||||||
|
timeout: 5000
|
||||||
|
});
|
||||||
|
|
||||||
|
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`);
|
||||||
|
|
||||||
|
if (config.logs.discord.enabled) {
|
||||||
|
let embed = new MessageEmbed()
|
||||||
|
.setColor(config.colour)
|
||||||
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||||
|
.setTitle(`Ticket ${ticket.id} closed`)
|
||||||
|
.addField('Creator', `<@${ticket.creator}>`, true)
|
||||||
|
.addField('Closed by', message.author, true)
|
||||||
|
.setFooter(guild.name, guild.iconURL())
|
||||||
|
.setTimestamp();
|
||||||
|
|
||||||
|
if (users.length > 1)
|
||||||
|
embed.addField('Members', users.map(u => `<@${u}>`).join('\n'));
|
||||||
|
|
||||||
|
client.channels.cache.get(config.logs.discord.channel).send(embed);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -76,8 +76,9 @@ module.exports = {
|
|||||||
.setFooter(guild.name, guild.iconURL())
|
.setFooter(guild.name, guild.iconURL())
|
||||||
);
|
);
|
||||||
|
|
||||||
let success;
|
|
||||||
if (config.commands.delete.confirmation) {
|
if (config.commands.delete.confirmation) {
|
||||||
|
let success;
|
||||||
let confirm = await message.channel.send(
|
let confirm = await message.channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(config.colour)
|
.setColor(config.colour)
|
||||||
@ -94,8 +95,8 @@ module.exports = {
|
|||||||
|
|
||||||
const collector = confirm.createReactionCollector(
|
const collector = confirm.createReactionCollector(
|
||||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||||
time: 15000
|
time: 15000
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.on('collect', async () => {
|
collector.on('collect', async () => {
|
||||||
if (channel.id !== message.channel.id)
|
if (channel.id !== message.channel.id)
|
||||||
@ -117,7 +118,16 @@ module.exports = {
|
|||||||
.setDescription('The channel will be automatically deleted in a few seconds.')
|
.setDescription('The channel will be automatically deleted in a few seconds.')
|
||||||
.setFooter(guild.name, guild.iconURL())
|
.setFooter(guild.name, guild.iconURL())
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (channel.id !== message.channel.id)
|
||||||
|
message.delete({
|
||||||
|
timeout: 5000
|
||||||
|
}).then(() => confirm.delete());
|
||||||
|
|
||||||
|
success = true;
|
||||||
|
del();
|
||||||
});
|
});
|
||||||
|
|
||||||
collector.on('end', () => {
|
collector.on('end', () => {
|
||||||
if (!success) {
|
if (!success) {
|
||||||
confirm.reactions.removeAll();
|
confirm.reactions.removeAll();
|
||||||
@ -131,44 +141,47 @@ module.exports = {
|
|||||||
|
|
||||||
message.delete({
|
message.delete({
|
||||||
timeout: 10000
|
timeout: 10000
|
||||||
})
|
}).then(() => confirm.delete());
|
||||||
.then(() => confirm.delete());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
del();
|
||||||
}
|
}
|
||||||
let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
|
|
||||||
raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`),
|
|
||||||
json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`);
|
|
||||||
|
|
||||||
if (fs.existsSync(txt)) fs.unlinkSync(txt);
|
|
||||||
if (fs.existsSync(raw)) fs.unlinkSync(raw);
|
|
||||||
if (fs.existsSync(json)) fs.unlinkSync(json);
|
|
||||||
|
|
||||||
// update database
|
async function del () {
|
||||||
success = true;
|
let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
|
||||||
ticket.destroy(); // remove ticket from database
|
raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`),
|
||||||
|
json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`);
|
||||||
|
|
||||||
// delete messages and channel
|
if (fs.existsSync(txt)) fs.unlinkSync(txt);
|
||||||
setTimeout(() => {
|
if (fs.existsSync(raw)) fs.unlinkSync(raw);
|
||||||
channel.delete();
|
if (fs.existsSync(json)) fs.unlinkSync(json);
|
||||||
if (channel.id !== message.channel.id)
|
|
||||||
message.delete()
|
|
||||||
.then(() => confirm.delete());
|
|
||||||
}, 5000);
|
|
||||||
|
|
||||||
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
|
// update database
|
||||||
|
ticket.destroy(); // remove ticket from database
|
||||||
|
|
||||||
if (config.logs.discord.enabled) {
|
// channel
|
||||||
client.channels.cache.get(config.logs.discord.channel).send(
|
channel.delete({
|
||||||
new MessageEmbed()
|
timeout: 5000
|
||||||
.setColor(config.colour)
|
});
|
||||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
|
||||||
.setTitle('Ticket deleted')
|
|
||||||
.addField('Creator', `<@${ticket.creator}>`, true)
|
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
|
||||||
.addField('Deleted by', message.author, true)
|
|
||||||
.setFooter(guild.name, guild.iconURL())
|
if (config.logs.discord.enabled) {
|
||||||
.setTimestamp()
|
client.channels.cache.get(config.logs.discord.channel).send(
|
||||||
);
|
new MessageEmbed()
|
||||||
|
.setColor(config.colour)
|
||||||
|
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||||
|
.setTitle('Ticket deleted')
|
||||||
|
.addField('Creator', `<@${ticket.creator}>`, true)
|
||||||
|
.addField('Deleted by', message.author, true)
|
||||||
|
.setFooter(guild.name, guild.iconURL())
|
||||||
|
.setTimestamp()
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
@ -26,7 +26,7 @@ module.exports = {
|
|||||||
let cmds = [];
|
let cmds = [];
|
||||||
|
|
||||||
for (let command of commands) {
|
for (let command of commands) {
|
||||||
if (command.hide) continue;
|
if (command.hide || command.disabled) continue;
|
||||||
if (command.permission && !message.member.hasPermission(command.permission)) continue;
|
if (command.permission && !message.member.hasPermission(command.permission)) continue;
|
||||||
|
|
||||||
let desc = command.description;
|
let desc = command.description;
|
||||||
|
@ -11,6 +11,7 @@ const log = new Logger();
|
|||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
const config = require(join(__dirname, '../../user/', require('../').config));
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'new',
|
name: 'new',
|
||||||
@ -19,12 +20,17 @@ module.exports = {
|
|||||||
aliases: ['ticket', 'open'],
|
aliases: ['ticket', 'open'],
|
||||||
example: 'new my server won\'t start',
|
example: 'new my server won\'t start',
|
||||||
args: false,
|
args: false,
|
||||||
|
disabled: !config.commands.new.enabled,
|
||||||
async execute(client, message, args, {config, Ticket}) {
|
async execute(client, message, args, {config, Ticket}) {
|
||||||
|
|
||||||
|
if (!config.commands.new.enabled) return; // stop if the command is disabled
|
||||||
|
|
||||||
|
|
||||||
const guild = client.guilds.cache.get(config.guild);
|
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_role);
|
||||||
if (config.commands.new.enabled) {
|
|
||||||
if (!supportRole)
|
if (!supportRole)
|
||||||
return message.channel.send(
|
return message.channel.send(
|
||||||
new MessageEmbed()
|
new MessageEmbed()
|
||||||
.setColor(config.err_colour)
|
.setColor(config.err_colour)
|
||||||
@ -196,6 +202,6 @@ module.exports = {
|
|||||||
|
|
||||||
|
|
||||||
}).catch(log.error);
|
}).catch(log.error);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -89,11 +89,7 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!/("|'|`)("|'|`)/.test(config.default_topic)) {
|
let topic = config.tickets.default_topic.command;
|
||||||
topic = config.tickets.default_topic.panel;
|
|
||||||
} else {
|
|
||||||
topic = 'No topic given (created via panel)';
|
|
||||||
}
|
|
||||||
|
|
||||||
let ticket = await Ticket.create({
|
let ticket = await Ticket.create({
|
||||||
channel: '',
|
channel: '',
|
||||||
|
@ -50,6 +50,21 @@ module.exports = {
|
|||||||
guild: '', // ID of your guild (REQUIRED)
|
guild: '', // ID of your guild (REQUIRED)
|
||||||
staff_role: '', // ID of your Support Team role (REQUIRED)
|
staff_role: '', // ID of your Support Team role (REQUIRED)
|
||||||
|
|
||||||
|
tickets: {
|
||||||
|
category: '', // ID of your tickets category (REQUIRED)
|
||||||
|
send_img: true,
|
||||||
|
ping: 'here',
|
||||||
|
text: `Hello there, {{ tag }}!
|
||||||
|
A member of staff will assist you shortly.
|
||||||
|
In the mean time, please describe your issue in as much detail as possible! :)`,
|
||||||
|
pin: false,
|
||||||
|
max: 3,
|
||||||
|
default_topic: {
|
||||||
|
command: 'No topic given',
|
||||||
|
panel: 'Created via panel'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
commands: {
|
commands: {
|
||||||
close: {
|
close: {
|
||||||
confirmation: true,
|
confirmation: true,
|
||||||
@ -63,21 +78,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
tickets: {
|
|
||||||
default_topic: {
|
|
||||||
command: 'No topic given',
|
|
||||||
panel: 'Created via panel'
|
|
||||||
},
|
|
||||||
category: '', // ID of your tickets category (REQUIRED)
|
|
||||||
send_img: true,
|
|
||||||
ping: 'here',
|
|
||||||
text: `Hello there, {{ tag }}!
|
|
||||||
A member of staff will assist you shortly.
|
|
||||||
In the mean time, please describe your issue in as much detail as possible! :)`,
|
|
||||||
pin: false,
|
|
||||||
max: 3
|
|
||||||
},
|
|
||||||
|
|
||||||
transcripts: {
|
transcripts: {
|
||||||
text: {
|
text: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user