mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-09 14:23:08 +02:00
Merge pull request #80 from FivePixels/master
Optional confirmations, transcript sending, and a default topic.
This commit is contained in:
commit
3e72dfda54
@ -78,53 +78,88 @@ module.exports = {
|
||||
.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}\``
|
||||
: '';
|
||||
|
||||
let confirm = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❔ Are you sure?')
|
||||
.setDescription(`${pre}\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||
time: 15000
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
let users = [];
|
||||
if (channel.id !== message.channel.id) {
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('**Ticket closed**')
|
||||
.setDescription(`Ticket closed by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
|
||||
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(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ **Ticket ${ticket.id} closed**`)
|
||||
.setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTitle('❔ Are you sure?')
|
||||
.setDescription(`${pre}\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||
time: 15000
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
if (channel.id !== message.channel.id) {
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('**Ticket closed**')
|
||||
.setDescription(`Ticket closed by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ **Ticket ${ticket.id} closed**`)
|
||||
.setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete({
|
||||
timeout: 5000
|
||||
}).then(() => confirm.delete());
|
||||
|
||||
success = true;
|
||||
close();
|
||||
});
|
||||
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
}).then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
async function close () {
|
||||
let users = [];
|
||||
|
||||
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
|
||||
let u = await client.users.fetch(ticket.creator);
|
||||
|
||||
if (u) {
|
||||
let dm;
|
||||
try {
|
||||
@ -133,7 +168,6 @@ module.exports = {
|
||||
log.warn(`Could not create DM channel with ${u.tag}`);
|
||||
}
|
||||
|
||||
|
||||
let res = {};
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
@ -160,9 +194,9 @@ module.exports = {
|
||||
}
|
||||
|
||||
res.embed = embed;
|
||||
|
||||
|
||||
try {
|
||||
dm.send(res);
|
||||
if (config.commands.close.send_transcripts) dm.send(res);
|
||||
if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res);
|
||||
} catch (e) {
|
||||
message.channel.send('❌ Couldn\'t send DM or transcript log message');
|
||||
@ -171,7 +205,6 @@ module.exports = {
|
||||
}
|
||||
|
||||
// update database
|
||||
success = true;
|
||||
ticket.update({
|
||||
open: false
|
||||
}, {
|
||||
@ -180,13 +213,10 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
// delete messages and channel
|
||||
setTimeout(() => {
|
||||
channel.delete();
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete()
|
||||
.then(() => confirm.delete());
|
||||
}, 5000);
|
||||
// delete channel
|
||||
channel.delete({
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`);
|
||||
|
||||
@ -199,32 +229,12 @@ module.exports = {
|
||||
.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);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
})
|
||||
.then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ module.exports = {
|
||||
}
|
||||
|
||||
}
|
||||
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
return channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
@ -75,49 +75,81 @@ module.exports = {
|
||||
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
||||
let success;
|
||||
|
||||
let confirm = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❔ Are you sure?')
|
||||
.setDescription(
|
||||
`:warning: This action is **irreversible**, the ticket will be completely removed from the database.
|
||||
You will **not** be able to view a transcript/archive of the channel later.
|
||||
Use the \`close\` command instead if you don't want this behaviour.\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||
time: 15000
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
if (channel.id !== message.channel.id)
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('**Ticket deleted**')
|
||||
.setDescription(`Ticket deleted by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
if (config.commands.delete.confirmation) {
|
||||
let success;
|
||||
let confirm = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ **Ticket ${ticket.id} deleted**`)
|
||||
.setDescription('The channel will be automatically deleted in a few seconds.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTitle('❔ Are you sure?')
|
||||
.setDescription(
|
||||
`:warning: This action is **irreversible**, the ticket will be completely removed from the database.
|
||||
You will **not** be able to view a transcript/archive of the channel later.
|
||||
Use the \`close\` command instead if you don't want this behaviour.\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||
time: 15000
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
if (channel.id !== message.channel.id)
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('**Ticket deleted**')
|
||||
.setDescription(`Ticket deleted by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ **Ticket ${ticket.id} deleted**`)
|
||||
.setDescription('The channel will be automatically deleted in a few seconds.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete({
|
||||
timeout: 5000
|
||||
}).then(() => confirm.delete());
|
||||
|
||||
success = true;
|
||||
del();
|
||||
});
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
}).then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
del();
|
||||
}
|
||||
|
||||
|
||||
async function 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`);
|
||||
@ -127,16 +159,13 @@ module.exports = {
|
||||
if (fs.existsSync(json)) fs.unlinkSync(json);
|
||||
|
||||
// update database
|
||||
success = true;
|
||||
ticket.destroy(); // remove ticket from database
|
||||
|
||||
// delete messages and channel
|
||||
setTimeout(() => {
|
||||
channel.delete();
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete()
|
||||
.then(() => confirm.delete());
|
||||
}, 5000);
|
||||
// channel
|
||||
channel.delete({
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
|
||||
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
|
||||
|
||||
@ -152,26 +181,7 @@ module.exports = {
|
||||
.setTimestamp()
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
})
|
||||
.then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
@ -26,7 +26,7 @@ module.exports = {
|
||||
let cmds = [];
|
||||
|
||||
for (let command of commands) {
|
||||
if (command.hide) continue;
|
||||
if (command.hide || command.disabled) continue;
|
||||
if (command.permission && !message.member.hasPermission(command.permission)) continue;
|
||||
|
||||
let desc = command.description;
|
||||
|
@ -11,6 +11,7 @@ const log = new Logger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const config = require(join(__dirname, '../../user/', require('../').config));
|
||||
|
||||
module.exports = {
|
||||
name: 'new',
|
||||
@ -19,10 +20,16 @@ module.exports = {
|
||||
aliases: ['ticket', 'open'],
|
||||
example: 'new my server won\'t start',
|
||||
args: false,
|
||||
disabled: !config.commands.new.enabled,
|
||||
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 supportRole = guild.roles.cache.get(config.staff_role);
|
||||
|
||||
if (!supportRole)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
@ -66,7 +73,7 @@ module.exports = {
|
||||
|
||||
|
||||
let topic = args.join(' ');
|
||||
if (topic.length > 256)
|
||||
if (topic.length > 256) {
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
@ -75,7 +82,10 @@ module.exports = {
|
||||
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
else if (topic.length < 1) topic = 'No topic given';
|
||||
}
|
||||
else if (topic.length < 1) {
|
||||
topic = config.tickets.default_topic.command;
|
||||
}
|
||||
|
||||
let ticket = await Ticket.create({
|
||||
channel: '',
|
||||
@ -192,5 +202,6 @@ module.exports = {
|
||||
|
||||
|
||||
}).catch(log.error);
|
||||
|
||||
},
|
||||
};
|
||||
|
@ -89,8 +89,8 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
let topic = 'No topic given (created via panel)';
|
||||
|
||||
let topic = config.tickets.default_topic.command;
|
||||
|
||||
let ticket = await Ticket.create({
|
||||
channel: '',
|
||||
creator: u.id,
|
||||
|
@ -47,7 +47,6 @@ module.exports = {
|
||||
colour: '#009999',
|
||||
err_colour: 'RED',
|
||||
cooldown: 3,
|
||||
|
||||
guild: '', // ID of your guild (REQUIRED)
|
||||
staff_role: '', // ID of your Support Team role (REQUIRED)
|
||||
|
||||
@ -59,7 +58,24 @@ module.exports = {
|
||||
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
|
||||
max: 3,
|
||||
default_topic: {
|
||||
command: 'No topic given',
|
||||
panel: 'Created via panel'
|
||||
}
|
||||
},
|
||||
|
||||
commands: {
|
||||
close: {
|
||||
confirmation: true,
|
||||
send_transcripts: true
|
||||
},
|
||||
delete: {
|
||||
confirmation: true
|
||||
},
|
||||
new: {
|
||||
enabled: true
|
||||
},
|
||||
},
|
||||
|
||||
transcripts: {
|
||||
|
Loading…
Reference in New Issue
Block a user