mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-11-09 22:33:09 +02:00
Add ticket claiming
This commit is contained in:
parent
86aa1837c7
commit
9ebdf557df
@ -1,3 +1,5 @@
|
|||||||
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
event: 'messageReactionAdd',
|
event: 'messageReactionAdd',
|
||||||
execute: async (client, r, u) => {
|
execute: async (client, r, u) => {
|
||||||
@ -12,33 +14,63 @@ module.exports = {
|
|||||||
|
|
||||||
let settings = await guild.settings;
|
let settings = await guild.settings;
|
||||||
if (!settings) settings = await guild.createSettings();
|
if (!settings) settings = await guild.createSettings();
|
||||||
|
const i18n = client.i18n.getLocale(settings.locale);
|
||||||
|
|
||||||
let member = await guild.members.fetch(u.id);
|
const channel = r.message.channel;
|
||||||
|
const member = await guild.members.fetch(u.id);
|
||||||
|
|
||||||
if (settings.blacklist.includes(u.id)) {
|
if (settings.blacklist.includes(u.id)) {
|
||||||
return client.log.info(`Ignoring blacklisted member ${u.tag}`);
|
return client.log.info(`Ignoring blacklisted member ${u.tag}`);
|
||||||
} else {
|
} else {
|
||||||
let member = await guild.members.fetch(u.id);
|
|
||||||
settings.blacklist.forEach(element => {
|
settings.blacklist.forEach(element => {
|
||||||
if (guild.roles.cache.has(element) && member.roles.cache.has(element)) {
|
if (guild.roles.cache.has(element) && member.roles.cache.has(element)) {
|
||||||
return client.log.info(`Ignoring member ${u.tag} with blacklisted role`);
|
return client.log.info(`Ignoring member ${u.tag} with blacklisted role`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
let t_row = await client.db.models.Ticket.findOne({
|
let t_row = await client.db.models.Ticket.findOne({
|
||||||
where: {
|
where: {
|
||||||
id: r.message.channel.id
|
id: channel.id
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
client.log.info('got t row')
|
|
||||||
if (t_row) {
|
if (t_row && t_row.opening_message === r.message.id) {
|
||||||
if (
|
if (r.emoji.name === '🙌' && await member.isStaff()) {
|
||||||
t_row.opening_message === r.message.id
|
|
||||||
&& r.emoji.name === '🙌'
|
|
||||||
&& await member.isStaff()
|
|
||||||
) {
|
|
||||||
// ticket claiming
|
// ticket claiming
|
||||||
client.log.info('claimed')
|
|
||||||
|
await t_row.update({
|
||||||
|
claimed_by: member.user.id
|
||||||
|
});
|
||||||
|
|
||||||
|
await channel.updateOverwrite(member.user.id, {
|
||||||
|
VIEW_CHANNEL: true,
|
||||||
|
}, `Ticket claimed by ${member.user.tag}`);
|
||||||
|
|
||||||
|
let cat_row = await client.db.models.Category.findOne({
|
||||||
|
where: {
|
||||||
|
id: t_row.category
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
for (let role of cat_row.roles) {
|
||||||
|
await channel.updateOverwrite(role, {
|
||||||
|
VIEW_CHANNEL: false,
|
||||||
|
}, `Ticket claimed by ${member.user.tag}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
client.log.info(`${member.user.tag} has claimed "${channel.name}" in "${guild.name}"`);
|
||||||
|
|
||||||
|
await channel.send(
|
||||||
|
new MessageEmbed()
|
||||||
|
.setColor(settings.colour)
|
||||||
|
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||||
|
.setTitle(i18n('commands.new.response.claimed.title'))
|
||||||
|
.setDescription(i18n('commands.new.response.claimed.description', member.toString()))
|
||||||
|
.setFooter(settings.footer, guild.iconURL())
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await r.users.remove(u.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,6 +113,10 @@
|
|||||||
},
|
},
|
||||||
"questions": "Please answer the following questions:\n\n%s",
|
"questions": "Please answer the following questions:\n\n%s",
|
||||||
"response": {
|
"response": {
|
||||||
|
"claimed": {
|
||||||
|
"title":"✅ Ticket claimed",
|
||||||
|
"description": "%s has claimed this ticket."
|
||||||
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"title": "✅ Ticket created",
|
"title": "✅ Ticket created",
|
||||||
"description": "Your ticket has been created: %s."
|
"description": "Your ticket has been created: %s."
|
||||||
|
Loading…
Reference in New Issue
Block a user