mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-03 00:41:27 +03:00
More settings, update things
This commit is contained in:
@@ -94,60 +94,85 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
* @param {(string|number)} ticket_id - The channel ID, or the ticket number
|
||||
* @param {string?} closer_id - ID of the member who is closing the ticket, or null
|
||||
* @param {string} [guild_id] - The ID of the ticket's guild (used if a ticket number is provided instead of ID)
|
||||
* @param {string} [reason] - The reason for closing the ticket
|
||||
*/
|
||||
async close(ticket_id, closer_id, guild_id) {
|
||||
async close(ticket_id, closer_id, guild_id, reason) {
|
||||
let t_row = await this.resolve(ticket_id, guild_id);
|
||||
if (!t_row) throw new Error(`Could not find a ticket with ID ${ticket_id}`);
|
||||
ticket_id = t_row.id;
|
||||
|
||||
this.emit('beforeClose', ticket_id);
|
||||
|
||||
let u_model_data = {
|
||||
user: closer_id,
|
||||
ticket: ticket_id
|
||||
};
|
||||
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||
where: u_model_data,
|
||||
defaults: u_model_data
|
||||
});
|
||||
|
||||
let guild = this.client.guilds.cache.get(t_row.guild);
|
||||
let member = await guild.members.fetch(closer_id);
|
||||
let settings = await guild.settings;
|
||||
const i18n = this.client.i18n.get(settings.locale);
|
||||
let channel = await this.client.channels.fetch(t_row.channel);
|
||||
|
||||
await u_row.update({
|
||||
avatar: member.user.displayAvatarURL(),
|
||||
username: member.user.username,
|
||||
discriminator: member.user.discriminator,
|
||||
display_name: member.displayName,
|
||||
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
|
||||
bot: member.user.bot
|
||||
});
|
||||
if (closer_id) {
|
||||
let u_model_data = {
|
||||
user: closer_id,
|
||||
ticket: ticket_id
|
||||
};
|
||||
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||
where: u_model_data,
|
||||
defaults: u_model_data
|
||||
});
|
||||
|
||||
let member = await guild.members.fetch(closer_id);
|
||||
|
||||
await u_row.update({
|
||||
avatar: member.user.displayAvatarURL(),
|
||||
username: member.user.username,
|
||||
discriminator: member.user.discriminator,
|
||||
display_name: member.displayName,
|
||||
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
|
||||
bot: member.user.bot
|
||||
});
|
||||
|
||||
if (channel) {
|
||||
let description = reason
|
||||
? i18n('commands.close.response.closed_by_member_with_reason.description', member.user.toString(), reason)
|
||||
: i18n('commands.close.response.closed_by_member.description', member.user.toString());
|
||||
await channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.success_colour)
|
||||
.setTitle(i18n('commands.close.response.closed.title'))
|
||||
.setDescription(description)
|
||||
);
|
||||
|
||||
setTimeout(async () => {
|
||||
await channel.delete(`Ticket channel closed by ${member.user.tag}${reason ? `: "${reason}"` : ''}`);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
this.client.log.info(`${member.user.tag} closed a ticket (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
||||
} else {
|
||||
if (channel) {
|
||||
let description = reason
|
||||
? i18n('commands.close.response.closed_with_reason.description')
|
||||
: i18n('commands.close.response.closed.description');
|
||||
await channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.success_colour)
|
||||
.setTitle(i18n('commands.close.response.closed.title'))
|
||||
.setDescription(description)
|
||||
);
|
||||
|
||||
setTimeout(async () => {
|
||||
await channel.delete(`Ticket channel closed${reason ? `: "${reason}"` : ''}`);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
||||
|
||||
}
|
||||
|
||||
await t_row.update({
|
||||
open: false,
|
||||
closed_by: closer_id
|
||||
closed_by: closer_id,
|
||||
reason: reason
|
||||
});
|
||||
|
||||
let channel = await this.client.channels.fetch(t_row.channel);
|
||||
|
||||
if (channel) {
|
||||
let settings = await guild.settings;
|
||||
const i18n = this.client.i18n.get(settings.locale);
|
||||
|
||||
await channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.success_colour)
|
||||
.setTitle(i18n('commands.close.response.closed.title'))
|
||||
.setDescription(i18n('commands.close.response.closed.description', member.user.toString()))
|
||||
);
|
||||
|
||||
setTimeout(async () => {
|
||||
await channel.delete(`Ticket channel closed by ${member.user.tag}`);
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
this.client.log.info(`${member.user.tag} closed a ticket (${ticket_id})`);
|
||||
|
||||
this.emit('close', ticket_id);
|
||||
return t_row;
|
||||
}
|
||||
|
Reference in New Issue
Block a user