mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-03 00:41:27 +03:00
Database things, pinned messages, start on ticket claiming
This commit is contained in:
@@ -105,22 +105,23 @@ module.exports = class TicketArchives {
|
||||
}
|
||||
|
||||
async updateEntities(message) {
|
||||
|
||||
let m_row = await this.client.db.models.Message.findOne({
|
||||
where: {
|
||||
id: message.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!m_row) return;
|
||||
|
||||
// message author
|
||||
try {
|
||||
await this.client.db.transaction(async t => {
|
||||
let m_row = await this.client.db.models.Message.findOne({
|
||||
where: {
|
||||
id: message.id
|
||||
},
|
||||
transaction: t
|
||||
});
|
||||
|
||||
if (!m_row) return;
|
||||
|
||||
// message author
|
||||
await this.client.db.transaction(async t => {
|
||||
let u_model_data = {
|
||||
user: message.author.id,
|
||||
ticket: message.channel.id
|
||||
};
|
||||
|
||||
let [u_row] = await this.client.db.models.UserEntity.findOrCreate({
|
||||
where: u_model_data,
|
||||
defaults: u_model_data,
|
||||
@@ -136,8 +137,17 @@ module.exports = class TicketArchives {
|
||||
bot: message.author.bot
|
||||
}, { transaction: t });
|
||||
|
||||
// mentioned members
|
||||
message.mentions.members.forEach(async member => {
|
||||
return u_row;
|
||||
});
|
||||
} catch (e) {
|
||||
this.client.log.warn('Failed to update message author entity in ticket archive');
|
||||
this.client.log.error(e);
|
||||
}
|
||||
|
||||
// mentioned members
|
||||
message.mentions.members.forEach(async member => {
|
||||
try {
|
||||
await this.client.db.transaction(async t => {
|
||||
let m_model_data = {
|
||||
user: member.user.id,
|
||||
ticket: message.channel.id
|
||||
@@ -156,10 +166,19 @@ module.exports = class TicketArchives {
|
||||
colour: member.displayColor === 0 ? null : int2hex(member.displayColor),
|
||||
bot: member.user.bot
|
||||
}, { transaction: t });
|
||||
});
|
||||
|
||||
// mentioned channels
|
||||
message.mentions.channels.forEach(async channel => {
|
||||
return m_row;
|
||||
});
|
||||
} catch (e) {
|
||||
this.client.log.warn('Failed to update mentioned members entities in ticket archive');
|
||||
this.client.log.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
// mentioned channels
|
||||
message.mentions.channels.forEach(async channel => {
|
||||
try {
|
||||
await this.client.db.transaction(async t => {
|
||||
let c_model_data = {
|
||||
channel: channel.id,
|
||||
ticket: message.channel.id
|
||||
@@ -172,10 +191,19 @@ module.exports = class TicketArchives {
|
||||
await c_row.update({
|
||||
name: this.encrypt(channel.name)
|
||||
}, { transaction: t });
|
||||
});
|
||||
|
||||
// mentioned roles
|
||||
message.mentions.roles.forEach(async role => {
|
||||
return c_row;
|
||||
});
|
||||
} catch (e) {
|
||||
this.client.log.warn('Failed to update mentioned channels entities in ticket archive');
|
||||
this.client.log.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
// mentioned roles
|
||||
message.mentions.roles.forEach(async role => {
|
||||
try {
|
||||
await this.client.db.transaction(async t => {
|
||||
let r_model_data = {
|
||||
role: role.id,
|
||||
ticket: message.channel.id
|
||||
@@ -189,12 +217,15 @@ module.exports = class TicketArchives {
|
||||
name: this.encrypt(role.name),
|
||||
colour: role.color === 0 ? '7289DA' : int2hex(role.color) // 7289DA = 7506394
|
||||
}, { transaction: t });
|
||||
|
||||
return r_row;
|
||||
});
|
||||
});
|
||||
} catch (e) {
|
||||
this.client.log.warn('Failed to update message entities in ticket archive');
|
||||
this.client.log.error(e);
|
||||
}
|
||||
} catch (e) {
|
||||
this.client.log.warn('Failed to update mentioned roles entities in ticket archive');
|
||||
this.client.log.error(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
@@ -23,8 +23,8 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Handle post-creation tasks
|
||||
* @param {*} t_row
|
||||
* @param {*} cat_row
|
||||
* @param {Model} t_row
|
||||
* @param {Model} cat_row
|
||||
*/
|
||||
async postCreate(t_row, cat_row) {
|
||||
|
||||
@@ -70,10 +70,17 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
.catch(() => this.client.log.warn('Failed to delete system pin message'));
|
||||
}
|
||||
|
||||
let questions = cat_row.opening_questions
|
||||
.map((q, index) => `**${index + 1}.** ${q}`)
|
||||
.join('\n\n');
|
||||
if (cat_row.claiming) {
|
||||
await sent.react('🙌');
|
||||
}
|
||||
|
||||
let questions;
|
||||
if (cat_row.opening_questions) {
|
||||
questions = cat_row.opening_questions
|
||||
.map((q, index) => `**${index + 1}.** ${q}`)
|
||||
.join('\n\n');
|
||||
}
|
||||
|
||||
if (cat_row.require_topic && topic.length === 0) {
|
||||
let collector_message = await t_channel.send(
|
||||
new MessageEmbed()
|
||||
@@ -111,15 +118,17 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
collector_message
|
||||
.delete()
|
||||
.catch(() => this.client.log.warn('Failed to delete topic collector message'));
|
||||
await t_channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
.setDescription(i18n('commands.new.questions', questions))
|
||||
.setFooter(settings.footer)
|
||||
);
|
||||
if (cat_row.opening_questions) {
|
||||
await t_channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
.setDescription(i18n('commands.new.questions', questions))
|
||||
.setFooter(settings.footer)
|
||||
);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (cat_row.opening_questions.length > 0) {
|
||||
if (cat_row.opening_questions) {
|
||||
await t_channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(settings.colour)
|
||||
@@ -280,13 +289,15 @@ module.exports = class TicketManager extends EventEmitter {
|
||||
}
|
||||
|
||||
this.client.log.info(`A ticket was closed (${ticket_id})${reason ? `: "${reason}"` : ''}`);
|
||||
|
||||
}
|
||||
|
||||
let pinned = await channel.messages.fetchPinned();
|
||||
|
||||
await t_row.update({
|
||||
open: false,
|
||||
closed_by: closer_id || null,
|
||||
closed_reason: reason || null
|
||||
closed_reason: reason || null,
|
||||
pinned: [ ...pinned.keys() ]
|
||||
});
|
||||
|
||||
this.emit('close', ticket_id);
|
||||
|
Reference in New Issue
Block a user