mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-02 16:41:25 +03:00
almost done....
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config.js');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
|
||||
@@ -53,7 +53,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
if(message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
|
||||
if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
@@ -106,7 +106,7 @@ module.exports = {
|
||||
.setColor(config.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setTitle(':white_check_mark: **Member added**')
|
||||
.setDescription(`${member} has been added to <#${ticket.get('channel')}>`)
|
||||
.setDescription(`${member} has been added to <#${ticket.channel}>`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
const fs = require('fs');
|
||||
const archive = require('../modules/archive');
|
||||
|
||||
@@ -59,10 +59,10 @@ module.exports = {
|
||||
notTicket
|
||||
.setTitle(':x: **Channel is not a ticket**')
|
||||
.setDescription(`${channel} is not a ticket channel.`);
|
||||
return channel.send(notTicket);
|
||||
return message.channel.send(notTicket);
|
||||
}
|
||||
|
||||
if (message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
|
||||
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
return channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
@@ -78,7 +78,7 @@ module.exports = {
|
||||
let success;
|
||||
let pre = fs.existsSync(`user/transcripts/text/${channel.id}.txt`) ||
|
||||
fs.existsSync(`user/transcripts/raw/${channel.id}.log`) ?
|
||||
`You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.get('id')}\`` :
|
||||
`You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\`` :
|
||||
'';
|
||||
|
||||
let confirm = await message.channel.send(
|
||||
@@ -118,23 +118,8 @@ module.exports = {
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
success = true;
|
||||
ticket.update({
|
||||
open: false
|
||||
}, {
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
channel.delete();
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete()
|
||||
.then(() => confirm.delete());
|
||||
}, 15000);
|
||||
|
||||
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
|
||||
let u = await client.users.fetch(ticket.get('creator'));
|
||||
let u = await client.users.fetch(ticket.creator);
|
||||
|
||||
if (u) {
|
||||
let dm;
|
||||
@@ -145,51 +130,55 @@ module.exports = {
|
||||
}
|
||||
|
||||
|
||||
await dm.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`**Ticket ${ticket.id} closed**`)
|
||||
.setDescription('Your ticket has been closed.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
if (config.transcripts.text.enabled && fs.existsSync(`user/transcripts/text/${channel.id}.txt`)) {
|
||||
try {
|
||||
await dm.send('A basic text transcript of the ticket channel is attached:', {
|
||||
files: [
|
||||
`user/transcripts/text/${channel.id}.txt`
|
||||
]
|
||||
});
|
||||
} catch (e) {
|
||||
log.warn(`Failed to send text transcript to ${u.tag}`);
|
||||
}
|
||||
let res = {};
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`Ticket ${ticket.id}`)
|
||||
.setFooter(guild.name, guild.iconURL());
|
||||
|
||||
if (fs.existsSync(`user/transcripts/text/${ticket.get('channel')}.txt`)) {
|
||||
embed.addField('Text transcript', 'See attachment');
|
||||
res.files = [
|
||||
{
|
||||
attachment: `user/transcripts/text/${ticket.get('channel')}.txt`,
|
||||
name: `ticket-${ticket.id}-${ticket.get('channel')}.txt`
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
if (config.transcripts.web.enabled) {
|
||||
try {
|
||||
let url = await archive.export(client, channel);
|
||||
if (fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`))
|
||||
embed.addField('Web archive', `${await archive.export(Ticket, channel)}`);
|
||||
|
||||
await dm.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`**Ticket ${ticket.id} web archive**`)
|
||||
.setDescription(`You can view an archive of your ticket channel [here](${url})`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
} catch (e) {
|
||||
log.warn(`Failed to send archive URL to ${u.tag}`);
|
||||
log.warn(e);
|
||||
}
|
||||
if (embed.fields.length < 1)
|
||||
embed.setDescription(`No text transcripts or archive data exists for ticket ${ticket.id}`);
|
||||
|
||||
}
|
||||
res.embed = embed;
|
||||
|
||||
dm.send(res).then();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.get('id')})`);
|
||||
// update database
|
||||
success = true;
|
||||
ticket.update({
|
||||
open: false
|
||||
}, {
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
|
||||
// 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)
|
||||
client.channels.cache.get(config.logs.discord.channel).send(
|
||||
@@ -197,7 +186,7 @@ module.exports = {
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('Ticket closed')
|
||||
.addField('Creator', `<@${ticket.get('creator')}>`, true)
|
||||
.addField('Creator', `<@${ticket.creator}>`, true)
|
||||
.addField('Closed by', message.author, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTimestamp()
|
||||
|
@@ -9,7 +9,7 @@
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'help',
|
||||
|
@@ -10,7 +10,7 @@ const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'new',
|
||||
|
@@ -9,7 +9,7 @@
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'panel',
|
||||
|
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config.js');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
|
||||
@@ -53,7 +53,7 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
|
||||
if(message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
|
||||
if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
@@ -106,7 +106,7 @@ module.exports = {
|
||||
.setColor(config.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setTitle(':white_check_mark: **Member removed**')
|
||||
.setDescription(`${member} has been removed from <#${ticket.get('channel')}>`)
|
||||
.setDescription(`${member} has been removed from <#${ticket.channel}>`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'stats',
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'tickets',
|
||||
@@ -93,23 +93,26 @@ module.exports = {
|
||||
let transcript = '';
|
||||
let c = closedTickets.rows[t].channel;
|
||||
if(fs.existsSync(`user/transcripts/text/${c}.txt`) || fs.existsSync(`user/transcripts/raw/${c}.log`))
|
||||
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to download text transcript.`;
|
||||
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to view.`;
|
||||
|
||||
closed.push(`> #${closedTickets.rows[t].id}: \`${desc}${desc.length > 20 ? '...' : ''}\`${transcript}`);
|
||||
closed.push(`> **#${closedTickets.rows[t].id}**: \`${desc}${desc.length > 20 ? '...' : ''}\`${transcript}`);
|
||||
|
||||
}
|
||||
let pre = context === 'self' ? 'You have' : user.username + ' has';
|
||||
embed.addField('Open tickets', openTickets.count === 0 ? `${pre} no open tickets.` : open.join('\n\n'), false);
|
||||
embed.addField('Closed tickets', closedTickets.count === 0 ? `${pre} no old tickets` : closed.join('\n\n'), false);
|
||||
|
||||
let m = await message.channel.send(embed);
|
||||
message.delete({timeout: 15000});
|
||||
|
||||
return setTimeout(async () => {
|
||||
await message.delete();
|
||||
await m.delete();
|
||||
}, 60000);
|
||||
|
||||
|
||||
let channel;
|
||||
try {
|
||||
channel = message.author.dmChannel || await message.author.createDM();
|
||||
message.channel.send('Sent to DM').then(msg => msg.delete({timeout: 15000}));
|
||||
} catch (e) {
|
||||
channel = message.channel;
|
||||
}
|
||||
|
||||
let m = await channel.send(embed);
|
||||
m.delete({timeout: 60000});
|
||||
},
|
||||
};
|
@@ -6,10 +6,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'topic',
|
||||
@@ -17,8 +15,59 @@ module.exports = {
|
||||
usage: '<topic>',
|
||||
aliases: ['edit'],
|
||||
example: 'topic need help error',
|
||||
args: false,
|
||||
args: true,
|
||||
async execute(client, message, args, Ticket) {
|
||||
|
||||
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
let ticket = await Ticket.findOne({
|
||||
where: {
|
||||
channel: message.channel.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!ticket)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(':x: **This isn\'t a ticket channel**')
|
||||
.setDescription('Use this command in the ticket channel you want to close, or mention the channel.')
|
||||
.addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`)
|
||||
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
||||
let topic = args.join(' ');
|
||||
if (topic.length > 256)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(':x: **Description too long**')
|
||||
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
message.channel.setTopic(`<@${ticket.creator}> | ` + topic);
|
||||
|
||||
Ticket.update({
|
||||
topic: topic
|
||||
}, {
|
||||
where: {
|
||||
channel: message.channel.id
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(':white_check_mark: **Ticket updated**')
|
||||
.setDescription('The topic has been changed.')
|
||||
.setFooter(client.user.username, client.user.avatarURL())
|
||||
);
|
||||
}
|
||||
};
|
@@ -6,10 +6,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const fs = require('fs');
|
||||
const {
|
||||
MessageEmbed
|
||||
} = require('discord.js');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
|
||||
module.exports = {
|
||||
name: 'transcript',
|
||||
@@ -17,11 +18,77 @@ module.exports = {
|
||||
usage: '<ticket-id>',
|
||||
aliases: ['archive', 'download'],
|
||||
example: 'transcript 57',
|
||||
args: false,
|
||||
args: true,
|
||||
async execute(client, message, args, Ticket) {
|
||||
/**
|
||||
* @TODO TRY TO SEND ATTACHMENT TO DM
|
||||
* @TODO ONLY ALLOW CREATOR AND STAFF TO RUN CMD
|
||||
*/
|
||||
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
const id = args[0];
|
||||
|
||||
let ticket = await Ticket.findOne({
|
||||
where: {
|
||||
id: id,
|
||||
open: false
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!ticket)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(':x: **Unknown ticket**')
|
||||
.setDescription('Couldn\'t find a closed ticket with that ID')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(':x: **No permission**')
|
||||
.setDescription(`You don't have permission to view ticket ${id} as it does not belong to you and you are not staff.`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
let res = {};
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`Ticket ${id}`)
|
||||
.setFooter(guild.name + ' | This message will be deleted in 15 seconds', guild.iconURL());
|
||||
|
||||
if (fs.existsSync(`user/transcripts/text/${ticket.channel}.txt`)) {
|
||||
embed.addField('Text transcript', 'See attachment');
|
||||
res.files = [
|
||||
{
|
||||
attachment: `user/transcripts/text/${ticket.channel}.txt`,
|
||||
name: `ticket-${id}-${ticket.channel}.txt`
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
const BASE_URL = config.transcripts.web.server;
|
||||
if (fs.existsSync(`user/transcripts/raw/${ticket.channel}.log`))
|
||||
embed.addField('Web archive', `${BASE_URL}/${ticket.creator}/${ticket.channel}`);
|
||||
|
||||
if (embed.fields.length < 1)
|
||||
embed.setDescription(`No text transcripts or archive data exists for ticket ${id}`);
|
||||
|
||||
res.embed = embed;
|
||||
|
||||
let channel;
|
||||
try {
|
||||
channel = message.author.dmChannel || await message.author.createDM();
|
||||
} catch (e) {
|
||||
channel = message.channel;
|
||||
}
|
||||
|
||||
channel.send(res).then(m => {
|
||||
if (channel.id === message.channel.id)
|
||||
m.delete({timeout: 15000});
|
||||
});
|
||||
message.delete({timeout: 1500});
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user