Options for confirm on close/delete on/off for new

This commit is contained in:
o5pxels 2020-12-20 19:49:41 -06:00
parent 1beb4b9ed1
commit e7d9d3558a
5 changed files with 207 additions and 180 deletions

View File

@ -82,7 +82,7 @@ module.exports = {
let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log) 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}\`` ? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\``
: ''; : '';
if (config.commands.close.confirmation) {
let confirm = await message.channel.send( let confirm = await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(config.colour) .setColor(config.colour)
@ -121,7 +121,76 @@ 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())
); );
success = true;
closeTicket();
if (config.commands.close.send_transcripts) {
sendTranscript();
}
});
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 {
success = true;
closeTicket();
}
async function closeTicket() {
// update database
ticket.update({
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);
@ -160,71 +229,17 @@ module.exports = {
} }
res.embed = embed; res.embed = embed;
try { try {
if (success) {
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
success = true;
ticket.update({
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);
}
});
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());
}
});
} }
}; };

View File

@ -77,7 +77,7 @@ module.exports = {
); );
let success; let success;
if (config.commands.delete.confirmation) {
let confirm = await message.channel.send( let confirm = await message.channel.send(
new MessageEmbed() new MessageEmbed()
.setColor(config.colour) .setColor(config.colour)
@ -117,7 +117,25 @@ 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())
); );
});
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());
}
});
}
let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`), let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`), raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`),
json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`); json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`);
@ -152,26 +170,5 @@ module.exports = {
.setTimestamp() .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());
}
});
} }
}; };

View File

@ -23,6 +23,7 @@ module.exports = {
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()
@ -75,7 +76,7 @@ module.exports = {
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.') .setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
.setFooter(guild.name, guild.iconURL()) .setFooter(guild.name, guild.iconURL())
); );
else if (topic.length < 1) topic = 'No topic given'; else if (topic.length < 1) topic = config.default_topic;
let ticket = await Ticket.create({ let ticket = await Ticket.create({
channel: '', channel: '',
@ -192,5 +193,6 @@ module.exports = {
}).catch(log.error); }).catch(log.error);
}
}, },
}; };

View File

@ -89,7 +89,7 @@ module.exports = {
} }
} }
let topic = 'No topic given (created via panel)'; let topic = config.default_topic;
let ticket = await Ticket.create({ let ticket = await Ticket.create({
channel: '', channel: '',

View File

@ -47,10 +47,23 @@ module.exports = {
colour: '#009999', colour: '#009999',
err_colour: 'RED', err_colour: 'RED',
cooldown: 3, cooldown: 3,
default_topic: 'Support Needed',
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)
commands: {
close: {
confirmation: true,
send_transcripts: true
},
delete: {
confirmation: true
},
new: {
enabled: true
},
},
tickets: { tickets: {
category: '', // ID of your tickets category (REQUIRED) category: '', // ID of your tickets category (REQUIRED)
send_img: true, send_img: true,