Improvements and fixes

This commit is contained in:
Isaac (eartharoid) 2021-01-01 15:41:12 +00:00
parent 234d1cd511
commit ae1d24236f
6 changed files with 128 additions and 118 deletions

View File

@ -78,11 +78,13 @@ 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}\``
: '';
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)
@ -96,11 +98,10 @@ module.exports = {
const collector = confirm.createReactionCollector(
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
time: 15000
});
time: 15000
});
collector.on('collect', async () => {
let users = [];
if (channel.id !== message.channel.id) {
channel.send(
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.')
.setFooter(guild.name, guild.iconURL())
);
if (channel.id !== message.channel.id)
message.delete({
timeout: 5000
}).then(() => confirm.delete());
success = true;
closeTicket();
if (config.commands.close.send_transcripts) {
sendTranscript();
}
close();
});
@ -142,58 +147,19 @@ module.exports = {
message.delete({
timeout: 10000
})
.then(() => confirm.delete());
}).then(() => confirm.delete());
}
});
} else {
success = true;
closeTicket();
close();
}
async function closeTicket() {
// update database
ticket.update({
open: false
}, {
where: {
channel: channel.id
}
});
async function close () {
let users = [];
// 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) {
let u = await client.users.fetch(ticket.creator);
if (u) {
let dm;
try {
@ -202,7 +168,6 @@ module.exports = {
log.warn(`Could not create DM channel with ${u.tag}`);
}
let res = {};
const embed = new MessageEmbed()
.setColor(config.colour)
@ -229,17 +194,47 @@ module.exports = {
}
res.embed = embed;
try {
if (success) {
dm.send(res);
if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).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');
}
}
}
}
// 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);
}
}
}
};

View File

@ -76,8 +76,9 @@ module.exports = {
.setFooter(guild.name, guild.iconURL())
);
let success;
if (config.commands.delete.confirmation) {
let success;
let confirm = await message.channel.send(
new MessageEmbed()
.setColor(config.colour)
@ -94,8 +95,8 @@ module.exports = {
const collector = confirm.createReactionCollector(
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
time: 15000
});
time: 15000
});
collector.on('collect', async () => {
if (channel.id !== message.channel.id)
@ -117,7 +118,16 @@ module.exports = {
.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();
@ -131,44 +141,47 @@ module.exports = {
message.delete({
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
success = true;
ticket.destroy(); // remove ticket from database
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`);
// delete messages and channel
setTimeout(() => {
channel.delete();
if (channel.id !== message.channel.id)
message.delete()
.then(() => confirm.delete());
}, 5000);
if (fs.existsSync(txt)) fs.unlinkSync(txt);
if (fs.existsSync(raw)) fs.unlinkSync(raw);
if (fs.existsSync(json)) fs.unlinkSync(json);
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
// update database
ticket.destroy(); // remove ticket from database
if (config.logs.discord.enabled) {
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()
);
// channel
channel.delete({
timeout: 5000
});
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
if (config.logs.discord.enabled) {
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()
);
}
}
}
};

View File

@ -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;

View File

@ -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,12 +20,17 @@ 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 (config.commands.new.enabled) {
if (!supportRole)
if (!supportRole)
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@ -196,6 +202,6 @@ module.exports = {
}).catch(log.error);
}
},
};

View File

@ -89,11 +89,7 @@ module.exports = {
}
}
if (!/("|'|`)("|'|`)/.test(config.default_topic)) {
topic = config.tickets.default_topic.panel;
} else {
topic = 'No topic given (created via panel)';
}
let topic = config.tickets.default_topic.command;
let ticket = await Ticket.create({
channel: '',

View File

@ -50,6 +50,21 @@ module.exports = {
guild: '', // ID of your guild (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: {
close: {
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: {
text: {
enabled: true,