fixed closing (db & discord channel) in closeall

This commit is contained in:
Oliver Cordingley 2021-01-16 15:44:35 +00:00
parent 2cd943985e
commit bf12ac8e7a

View File

@ -43,11 +43,7 @@ module.exports = {
.setFooter(guild.name, guild.iconURL()) .setFooter(guild.name, guild.iconURL())
); );
let tickets; let tickets = await Ticket.findAll({
let channel;
channel = message.channel;
tickets = await Ticket.findAll({
where: { where: {
open: true, open: true,
} }
@ -86,16 +82,14 @@ module.exports = {
}); });
collector.on('collect', async () => { collector.on('collect', async () => {
if (channel.id != message.channel.id) { message.channel.send(
channel.send( new MessageEmbed()
new MessageEmbed() .setColor(config.colour)
.setColor(config.colour) .setAuthor(message.author.username, message.author.displayAvatarURL())
.setAuthor(message.author.username, message.author.displayAvatarURL()) .setTitle(`**\`${tickets.length}\` tickets closed**`)
.setTitle(`**\`${tickets.length}\` tickets closed**`) .setDescription(`**\`${tickets.length}\`** tickets closed by ${message.author}`)
.setDescription(`**\`${tickets.length}\`** tickets closed by ${message.author}`) .setFooter(guild.name, guild.iconURL())
.setFooter(guild.name, guild.iconURL()) );
);
}
confirm.reactions.removeAll(); confirm.reactions.removeAll();
confirm.edit( confirm.edit(
@ -107,10 +101,9 @@ module.exports = {
.setFooter(guild.name, guild.iconURL()) .setFooter(guild.name, guild.iconURL())
); );
if (channel.id !== message.channel.id) message.delete({
message.delete({ timeout: 5000,
timeout: 5000, }).then(() => confirm.delete());
}).then(() => confirm.delete());
success = true; success = true;
closeAll(); closeAll();
@ -143,11 +136,17 @@ module.exports = {
// LOOP START // LOOP START
tickets.forEach(async ticket => { tickets.forEach(async ticket => {
let user = await client.users.fetch(ticket.creator); let {
channel,
id,
creator
} = ticket;
let user = await client.users.fetch(creator);
let paths = { let paths = {
text: join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`), text: join(__dirname, `../../user/transcripts/text/${channel}.txt`),
log: join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`), log: join(__dirname, `../../user/transcripts/raw/${channel}.log`),
json: join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`) json: join(__dirname, `../../user/transcripts/raw/entities/${channel}.json`)
}; };
if (user) { if (user) {
@ -169,13 +168,13 @@ module.exports = {
embed.addField('Text Transcript', 'See attachment'); embed.addField('Text Transcript', 'See attachment');
res.files = [{ res.files = [{
attachment: paths.text, attachment: paths.text,
name: `ticket-${ticket.id}-${ticket.get('channel')}.txt` name: `ticket-${id}-${channel}.txt`
}]; }];
} }
if (fs.existsSync(paths.log) && fs.existsSync(paths.json)) { if (fs.existsSync(paths.log) && fs.existsSync(paths.json)) {
let data = JSON.parse(fs.readFileSync(paths.json)); let data = JSON.parse(fs.readFileSync(paths.json));
for (user in data.entities.users) users.push(user); for (u in data.entities.users) users.push(u);
embed.addField('Web archive', await archive.export(Ticket, channel)); embed.addField('Web archive', await archive.export(Ticket, channel));
} }
@ -189,11 +188,22 @@ module.exports = {
} }
} }
await Ticket.update({
open: false,
}, {
where: {
id,
}
});
client.channels.fetch(channel)
.then(c => c.delete()
.then(o => log.info(`Deleted channel with name: \'#${o.name}\' <${o.id}>`))
.catch(e => log.error(e)))
.catch(e => log.error(e));
}); });
} }
} }
// TODO: possibly make users allow to close all of their issues?
}, },
}; };