mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-02 08:41:25 +03:00
Set up for v3
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'add',
|
||||
description: 'Add a member to a ticket channel',
|
||||
usage: '<@member> [... #channel]',
|
||||
aliases: ['none'],
|
||||
example: 'add @member to #ticket-23',
|
||||
args: true,
|
||||
async execute(client, message, args, log, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const notTicket = new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **This isn\'t a ticket channel**')
|
||||
.setDescription('Use this command in the ticket channel you want to add a user to, 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 ticket;
|
||||
|
||||
let channel = message.mentions.channels.first();
|
||||
|
||||
if (!channel) {
|
||||
channel = message.channel;
|
||||
ticket = await Ticket.findOne({ where: { channel: message.channel.id } });
|
||||
if (!ticket) return message.channel.send(notTicket);
|
||||
|
||||
} else {
|
||||
ticket = await Ticket.findOne({ where: { channel: channel.id } });
|
||||
if (!ticket) {
|
||||
notTicket
|
||||
.setTitle('❌ **Channel is not a ticket**')
|
||||
.setDescription(`${channel} is not a ticket channel.`);
|
||||
return message.channel.send(notTicket);
|
||||
}
|
||||
}
|
||||
|
||||
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('❌ **No permission**')
|
||||
.setDescription(`You don't have permission to alter ${channel} as it does not belong to you and you are not staff.`)
|
||||
.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 member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
|
||||
|
||||
if (!member) {
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Unknown member**')
|
||||
.setDescription('Please mention a valid member.')
|
||||
.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())
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
channel.updateOverwrite(member.user, {
|
||||
VIEW_CHANNEL: true,
|
||||
SEND_MESSAGES: true,
|
||||
ATTACH_FILES: true,
|
||||
READ_MESSAGE_HISTORY: true
|
||||
});
|
||||
|
||||
if (channel.id !== message.channel.id) {
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setTitle('**Member added**')
|
||||
.setDescription(`${member} has been added by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setTitle('✅ **Member added**')
|
||||
.setDescription(`${member} has been added to <#${ticket.channel}>`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
log.info(`${message.author.tag} added a user to a ticket (#${message.channel.id})`);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
// command ends here
|
||||
},
|
||||
};
|
@@ -1,238 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const archive = require('../modules/archive');
|
||||
|
||||
module.exports = {
|
||||
name: 'close',
|
||||
description: 'Close a ticket; either a specified (mentioned) channel, or the channel the command is used in.',
|
||||
usage: '[ticket]',
|
||||
aliases: ['none'],
|
||||
example: 'close #ticket-17',
|
||||
args: false,
|
||||
async execute(client, message, _args, log, { config, Ticket }) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const notTicket = new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **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 ticket;
|
||||
let channel = message.mentions.channels.first();
|
||||
// || client.channels.resolve(await Ticket.findOne({ where: { id: args[0] } }).channel) // channels.fetch()
|
||||
|
||||
if (!channel) {
|
||||
channel = message.channel;
|
||||
|
||||
ticket = await Ticket.findOne({
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
if (!ticket) return message.channel.send(notTicket);
|
||||
} else {
|
||||
ticket = await Ticket.findOne({
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
if (!ticket) {
|
||||
notTicket
|
||||
.setTitle('❌ **Channel is not a ticket**')
|
||||
.setDescription(`${channel} is not a ticket channel.`);
|
||||
return message.channel.send(notTicket);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let paths = {
|
||||
text: join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
|
||||
log: join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`),
|
||||
json: join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`)
|
||||
};
|
||||
|
||||
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('❌ **No permission**')
|
||||
.setDescription(`You don't have permission to close ${channel} as it does not belong to you and you are not staff.`)
|
||||
.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())
|
||||
);
|
||||
|
||||
|
||||
if (config.commands.close.confirmation) {
|
||||
let success;
|
||||
let pre = fs.existsSync(paths.text) || fs.existsSync(paths.log)
|
||||
? `You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\``
|
||||
: '';
|
||||
|
||||
let confirm = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❔ Are you sure?')
|
||||
.setDescription(`${pre}\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||
time: 15000
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
if (channel.id !== message.channel.id) {
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('**Ticket closed**')
|
||||
.setDescription(`Ticket closed by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ **Ticket ${ticket.id} closed**`)
|
||||
.setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete({
|
||||
timeout: 5000
|
||||
}).then(() => confirm.delete());
|
||||
|
||||
success = true;
|
||||
close();
|
||||
});
|
||||
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
}).then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
async function close () {
|
||||
let users = [];
|
||||
|
||||
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
|
||||
let u = await client.users.fetch(ticket.creator);
|
||||
if (u) {
|
||||
let dm;
|
||||
try {
|
||||
dm = u.dmChannel || await u.createDM();
|
||||
} catch (e) {
|
||||
log.warn(`Could not create DM channel with ${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(paths.text)) {
|
||||
embed.addField('Text transcript', 'See attachment');
|
||||
res.files = [{
|
||||
attachment: paths.text,
|
||||
name: `ticket-${ticket.id}-${ticket.get('channel')}.txt`
|
||||
}];
|
||||
}
|
||||
|
||||
if (fs.existsSync(paths.log) && fs.existsSync(paths.json)) {
|
||||
let data = JSON.parse(fs.readFileSync(paths.json));
|
||||
for (u in data.entities.users) users.push(u);
|
||||
embed.addField('Web archive', await archive.export(Ticket, channel)); // this will also delete these files
|
||||
}
|
||||
|
||||
if (embed.fields.length < 1) {
|
||||
embed.setDescription(`No text transcripts or archive data exists for ticket ${ticket.id}`);
|
||||
}
|
||||
|
||||
res.embed = embed;
|
||||
|
||||
try {
|
||||
if (config.commands.close.send_transcripts) dm.send(res);
|
||||
if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res);
|
||||
} catch (e) {
|
||||
message.channel.send('❌ Couldn\'t send DM or transcript log message');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update database
|
||||
ticket.update({
|
||||
open: false
|
||||
}, {
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
|
||||
// delete channel
|
||||
channel.delete({
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`);
|
||||
|
||||
if (config.logs.discord.enabled) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`Ticket ${ticket.id} closed`)
|
||||
.addField('Creator', `<@${ticket.creator}>`, true)
|
||||
.addField('Closed by', message.author, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTimestamp();
|
||||
|
||||
if (users.length > 1)
|
||||
embed.addField('Members', users.map(u => `<@${u}>`).join('\n'));
|
||||
|
||||
client.channels.cache.get(config.logs.discord.channel).send(embed);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
@@ -1,258 +0,0 @@
|
||||
/**
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const config = require(join(__dirname, '../../user/', require('../').config));
|
||||
const archive = require('../modules/archive');
|
||||
const { plural } = require('../modules/utils');
|
||||
const { Op } = require('sequelize');
|
||||
const toTime = require('to-time-monthsfork');
|
||||
|
||||
// A slight modification to the 'close' command to allow multiple tickets to be closed at once
|
||||
|
||||
module.exports = {
|
||||
name: 'closeall',
|
||||
description: 'Closes all currently open tickets older than a specified time length',
|
||||
usage: '[time]',
|
||||
aliases: ['ca'],
|
||||
example: 'closeall 1mo 1w',
|
||||
args: false,
|
||||
disabled: !config.commands.closeall.enabled,
|
||||
async execute(client, message, args, log, {
|
||||
config,
|
||||
Ticket
|
||||
}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
if (!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('❌ **No permission**')
|
||||
.setDescription('You do not have permission to use this command as you are not a staff member.')
|
||||
.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 tickets;
|
||||
|
||||
if (args.length > 0) {
|
||||
let time, maxDate;
|
||||
let timestamp = args.join(' ');
|
||||
|
||||
try {
|
||||
time = toTime(timestamp).milliseconds();
|
||||
maxDate = new Date(Date.now() - time);
|
||||
} catch (error) {
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Invalid Timestamp**')
|
||||
.setDescription(`The timestamp that you specified, \`${timestamp}\`, was invalid.`)
|
||||
.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())
|
||||
);
|
||||
}
|
||||
|
||||
tickets = await Ticket.findAndCountAll({
|
||||
where: {
|
||||
open: true,
|
||||
updatedAt: {
|
||||
[Op.lte]: maxDate,
|
||||
}
|
||||
},
|
||||
});
|
||||
} else {
|
||||
tickets = await Ticket.findAndCountAll({
|
||||
where: {
|
||||
open: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (tickets.count === 0)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.display)
|
||||
.setTitle('❌ **No open tickets**')
|
||||
.setDescription('There are no open tickets to close.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
log.info(`Found ${tickets.count} open tickets`);
|
||||
|
||||
if (config.commands.close.confirmation) {
|
||||
let success;
|
||||
let pre = config.transcripts.text.enabled || config.transcripts.web.enabled
|
||||
? `You will be able to view an archived version of each ticket later with \`${config.prefix}transcript <id>\``
|
||||
: '';
|
||||
|
||||
let confirm = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`❔ Are you sure you want to close **${tickets.count}** tickets?`)
|
||||
.setDescription(`${pre}\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(reaction, user) => reaction.emoji.name === '✅' && user.id === message.author.id, {
|
||||
time: 15000,
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`**\`${tickets.count}\` tickets closed**`)
|
||||
.setDescription(`**\`${tickets.count}\`** tickets closed by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ ** \`${tickets.count}\` tickets closed**`)
|
||||
.setDescription('The channels will be automatically deleted in a few seconds, once the contents have been archived.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
message.delete({
|
||||
timeout: 5000,
|
||||
}).then(() => confirm.delete());
|
||||
|
||||
success = true;
|
||||
closeAll();
|
||||
});
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
}).then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
closeAll();
|
||||
}
|
||||
|
||||
|
||||
async function closeAll() {
|
||||
tickets.rows.forEach(async ticket => {
|
||||
let users = [];
|
||||
|
||||
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
|
||||
let {
|
||||
channel,
|
||||
id,
|
||||
creator
|
||||
} = ticket;
|
||||
|
||||
let user = await client.users.fetch(creator);
|
||||
let paths = {
|
||||
text: join(__dirname, `../../user/transcripts/text/${channel}.txt`),
|
||||
log: join(__dirname, `../../user/transcripts/raw/${channel}.log`),
|
||||
json: join(__dirname, `../../user/transcripts/raw/entities/${channel}.json`)
|
||||
};
|
||||
|
||||
if (user) {
|
||||
let dm;
|
||||
try {
|
||||
dm = user.dmChannel || await user.createDM();
|
||||
} catch (e) {
|
||||
log.warn(`Could not create DM channel with ${user.tag}`);
|
||||
}
|
||||
|
||||
let res = {};
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username)
|
||||
.setTitle(`Ticket ${id}`)
|
||||
.setFooter(guild.name, guild.iconURL());
|
||||
|
||||
if (fs.existsSync(paths.text)) {
|
||||
embed.addField('Text Transcript', 'See attachment');
|
||||
res.files = [{
|
||||
attachment: paths.text,
|
||||
name: `ticket-${id}-${channel}.txt`
|
||||
}];
|
||||
}
|
||||
|
||||
if (fs.existsSync(paths.log) && fs.existsSync(paths.json)) {
|
||||
let data = JSON.parse(fs.readFileSync(paths.json));
|
||||
data.entities.users.forEach(u => users.push(u));
|
||||
embed.addField('Web archive', await archive.export(Ticket, channel));
|
||||
}
|
||||
|
||||
res.embed = embed;
|
||||
|
||||
try {
|
||||
if (config.commands.close.send_transcripts) dm.send(res);
|
||||
if (config.transcripts.channel.length > 1) client.channels.cache.get(config.transcripts.channel).send(res);
|
||||
} catch (e) {
|
||||
message.channel.send('❌ Couldn\'t send DM or transcript log message');
|
||||
}
|
||||
}
|
||||
|
||||
await Ticket.update({
|
||||
open: false,
|
||||
}, {
|
||||
where: {
|
||||
id,
|
||||
}
|
||||
});
|
||||
|
||||
log.info(log.format(`${message.author.tag} closed ticket &7${id}&f`));
|
||||
|
||||
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));
|
||||
|
||||
if (config.logs.discord.enabled) {
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`${tickets.count} ${plural('ticket', tickets.count)} closed (${config.prefix}closeall)`)
|
||||
.addField('Closed by', message.author, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTimestamp();
|
||||
|
||||
if (users.length > 1)
|
||||
embed.addField('Members', users.map(u => `<@${u}>`).join('\n'));
|
||||
|
||||
client.channels.cache.get(config.logs.discord.channel).send(embed);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
},
|
||||
};
|
@@ -1,185 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const {
|
||||
MessageEmbed
|
||||
} = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
name: 'delete',
|
||||
description: 'Delete a ticket. Similar to closing a ticket, but does not save transcript or archives.',
|
||||
usage: '[ticket]',
|
||||
aliases: ['del'],
|
||||
example: 'delete #ticket-17',
|
||||
args: false,
|
||||
async execute(client, message, _args, log, {
|
||||
config,
|
||||
Ticket
|
||||
}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const notTicket = new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **This isn\'t a ticket channel**')
|
||||
.setDescription('Use this command in the ticket channel you want to delete, 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 ticket;
|
||||
let channel = message.mentions.channels.first();
|
||||
// || client.channels.resolve(await Ticket.findOne({ where: { id: args[0] } }).channel) // channels.fetch()
|
||||
|
||||
if (!channel) {
|
||||
channel = message.channel;
|
||||
|
||||
ticket = await Ticket.findOne({
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
if (!ticket) return channel.send(notTicket);
|
||||
|
||||
} else {
|
||||
ticket = await Ticket.findOne({
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
if (!ticket) {
|
||||
notTicket
|
||||
.setTitle('❌ **Channel is not a ticket**')
|
||||
.setDescription(`${channel} is not a ticket channel.`);
|
||||
return message.channel.send(notTicket);
|
||||
}
|
||||
|
||||
}
|
||||
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
|
||||
return channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **No permission**')
|
||||
.setDescription(`You don't have permission to delete ${channel} as it does not belong to you and you are not staff.`)
|
||||
.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())
|
||||
);
|
||||
|
||||
|
||||
if (config.commands.delete.confirmation) {
|
||||
let success;
|
||||
let confirm = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❔ Are you sure?')
|
||||
.setDescription(
|
||||
`:warning: This action is **irreversible**, the ticket will be completely removed from the database.
|
||||
You will **not** be able to view a transcript/archive of the channel later.
|
||||
Use the \`close\` command instead if you don't want this behaviour.\n**React with ✅ to confirm.**`)
|
||||
.setFooter(guild.name + ' | Expires in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id, {
|
||||
time: 15000
|
||||
});
|
||||
|
||||
collector.on('collect', async () => {
|
||||
if (channel.id !== message.channel.id)
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('**Ticket deleted**')
|
||||
.setDescription(`Ticket deleted by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`✅ **Ticket ${ticket.id} deleted**`)
|
||||
.setDescription('The channel will be automatically deleted in a few seconds.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
if (channel.id !== message.channel.id)
|
||||
message.delete({
|
||||
timeout: 5000
|
||||
}).then(() => confirm.delete());
|
||||
|
||||
success = true;
|
||||
del();
|
||||
});
|
||||
|
||||
collector.on('end', () => {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Expired**')
|
||||
.setDescription('You took too long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
}).then(() => confirm.delete());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
del();
|
||||
}
|
||||
|
||||
|
||||
async function del () {
|
||||
let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
|
||||
raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`),
|
||||
json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`);
|
||||
|
||||
if (fs.existsSync(txt)) fs.unlinkSync(txt);
|
||||
if (fs.existsSync(raw)) fs.unlinkSync(raw);
|
||||
if (fs.existsSync(json)) fs.unlinkSync(json);
|
||||
|
||||
// update database
|
||||
ticket.destroy(); // remove ticket from database
|
||||
|
||||
// channel
|
||||
channel.delete({
|
||||
timeout: 5000
|
||||
});
|
||||
|
||||
|
||||
log.info(`${message.author.tag} deleted a ticket (#ticket-${ticket.id})`);
|
||||
|
||||
if (config.logs.discord.enabled) {
|
||||
client.channels.cache.get(config.logs.discord.channel).send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('Ticket deleted')
|
||||
.addField('Creator', `<@${ticket.creator}>`, true)
|
||||
.addField('Deleted by', message.author, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTimestamp()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'help',
|
||||
description: 'Display help menu',
|
||||
usage: '[command]',
|
||||
aliases: ['command', 'commands'],
|
||||
example: 'help new',
|
||||
args: false,
|
||||
execute(client, message, args, log, {config}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const commands = Array.from(client.commands.values());
|
||||
|
||||
if (!args.length) {
|
||||
let cmds = [];
|
||||
|
||||
for (let command of commands) {
|
||||
if (command.hide || command.disabled) continue;
|
||||
if (command.permission && !message.member.hasPermission(command.permission)) continue;
|
||||
|
||||
let desc = command.description;
|
||||
|
||||
if (desc.length > 50) desc = desc.substring(0, 50) + '...';
|
||||
cmds.push(`**${config.prefix}${command.name}** **·** ${desc}`);
|
||||
}
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setTitle('Commands')
|
||||
.setColor(config.colour)
|
||||
.setDescription(
|
||||
`\nThe commands you have access to are listed below. Type \`${config.prefix}help [command]\` for more information about a specific command.
|
||||
\n${cmds.join('\n\n')}
|
||||
\nPlease contact a member of staff if you require assistance.`
|
||||
)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
).catch((error) => {
|
||||
log.warn('Could not send help menu');
|
||||
log.error(error);
|
||||
});
|
||||
|
||||
} else {
|
||||
const name = args[0].toLowerCase();
|
||||
const command = client.commands.get(name) || client.commands.find(c => c.aliases && c.aliases.includes(name));
|
||||
|
||||
if (!command)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setDescription(`❌ **Invalid command name** (\`${config.prefix}help\`)`)
|
||||
);
|
||||
|
||||
|
||||
const cmd = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setTitle(command.name);
|
||||
|
||||
|
||||
if (command.long) cmd.setDescription(command.long);
|
||||
else cmd.setDescription(command.description);
|
||||
|
||||
if (command.aliases) cmd.addField('Aliases', `\`${command.aliases.join(', ')}\``, true);
|
||||
|
||||
if (command.usage) cmd.addField('Usage', `\`${config.prefix}${command.name} ${command.usage}\``, false);
|
||||
|
||||
if (command.usage) cmd.addField('Example', `\`${config.prefix}${command.example}\``, false);
|
||||
|
||||
|
||||
if (command.permission && !message.member.hasPermission(command.permission)) {
|
||||
cmd.addField('Required Permission', `\`${command.permission}\` :exclamation: You don't have permission to use this command`, true);
|
||||
} else cmd.addField('Required Permission', `\`${command.permission || 'none'}\``, true);
|
||||
|
||||
message.channel.send(cmd);
|
||||
}
|
||||
|
||||
// command ends here
|
||||
},
|
||||
};
|
@@ -1,205 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const config = require(join(__dirname, '../../user/', require('../').config));
|
||||
|
||||
module.exports = {
|
||||
name: 'new',
|
||||
description: 'Create a new support ticket',
|
||||
usage: '[brief description]',
|
||||
aliases: ['ticket', 'open'],
|
||||
example: 'new my server won\'t start',
|
||||
args: false,
|
||||
disabled: !config.commands.new.enabled,
|
||||
async execute(client, message, args, log, {config, Ticket}) {
|
||||
|
||||
if (!config.commands.new.enabled) return; // stop if the command is disabled
|
||||
|
||||
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const supportRole = guild.roles.cache.get(config.staff_role);
|
||||
|
||||
if (!supportRole)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setTitle('❌ **Error**')
|
||||
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
|
||||
let tickets = await Ticket.findAndCountAll({
|
||||
where: {
|
||||
creator: message.author.id,
|
||||
open: true
|
||||
},
|
||||
limit: config.tickets.max
|
||||
});
|
||||
|
||||
if (tickets.count >= config.tickets.max) {
|
||||
let ticketList = [];
|
||||
for (let t in tickets.rows) {
|
||||
let desc = tickets.rows[t].topic.substring(0, 30);
|
||||
ticketList
|
||||
.push(`<#${tickets.rows[t].channel}>: \`${desc}${desc.length > 30 ? '...' : ''}\``);
|
||||
}
|
||||
|
||||
let m = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle(`❌ **You already have ${tickets.count} or more open tickets**`)
|
||||
.setDescription(`Use \`${config.prefix}close\` to close unneeded tickets.\n\n${ticketList.join(',\n')}`)
|
||||
.setFooter(guild.name + ' | This message will be deleted in 15 seconds', guild.iconURL())
|
||||
);
|
||||
|
||||
return setTimeout(async () => {
|
||||
await message.delete();
|
||||
await m.delete();
|
||||
}, 15000);
|
||||
}
|
||||
|
||||
|
||||
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('❌ **Description too long**')
|
||||
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
else if (topic.length < 1) {
|
||||
topic = config.tickets.default_topic.command;
|
||||
}
|
||||
|
||||
let ticket = await Ticket.create({
|
||||
channel: '',
|
||||
creator: message.author.id,
|
||||
open: true,
|
||||
archived: false,
|
||||
topic: topic
|
||||
});
|
||||
|
||||
let name = 'ticket-' + ticket.get('id');
|
||||
|
||||
guild.channels.create(name, {
|
||||
type: 'text',
|
||||
topic: `${message.author} | ${topic}`,
|
||||
parent: config.tickets.category,
|
||||
permissionOverwrites: [{
|
||||
id: guild.roles.everyone,
|
||||
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
|
||||
},
|
||||
{
|
||||
id: client.user,
|
||||
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
|
||||
},
|
||||
{
|
||||
id: message.member,
|
||||
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
|
||||
},
|
||||
{
|
||||
id: supportRole,
|
||||
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES', 'ATTACH_FILES', 'READ_MESSAGE_HISTORY']
|
||||
}
|
||||
],
|
||||
reason: 'User requested a new support ticket channel'
|
||||
}).then(async c => {
|
||||
|
||||
Ticket.update({
|
||||
channel: c.id
|
||||
}, {
|
||||
where: {
|
||||
id: ticket.id
|
||||
}
|
||||
});
|
||||
|
||||
let m = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('✅ **Ticket created**')
|
||||
.setDescription(`Your ticket has been created: ${c}`)
|
||||
.setFooter(client.user.username + ' | This message will be deleted in 15 seconds', client.user.displayAvatarURL())
|
||||
);
|
||||
|
||||
setTimeout(async () => {
|
||||
await message.delete();
|
||||
await m.delete();
|
||||
}, 15000);
|
||||
|
||||
// require('../modules/archive').create(client, c); // create files
|
||||
|
||||
let ping;
|
||||
switch (config.tickets.ping) {
|
||||
case 'staff':
|
||||
ping = `<@&${config.staff_role}>,\n`;
|
||||
break;
|
||||
case false:
|
||||
ping = '';
|
||||
break;
|
||||
default:
|
||||
ping = `@${config.tickets.ping},\n`;
|
||||
}
|
||||
|
||||
await c.send(ping + `${message.author} has created a new ticket`);
|
||||
|
||||
if (config.tickets.send_img) {
|
||||
const images = fs.readdirSync(join(__dirname, '../../user/images'));
|
||||
await c.send({
|
||||
files: [
|
||||
join(__dirname, '../../user/images', images[Math.floor(Math.random() * images.length)])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
let text = config.tickets.text
|
||||
.replace(/{{ ?name ?}}/gmi, message.author.username)
|
||||
.replace(/{{ ?(tag|mention) ?}}/gmi, message.author);
|
||||
|
||||
|
||||
let w = await c.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setDescription(text)
|
||||
.addField('Topic', `\`${topic}\``)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
if (config.tickets.pin) await w.pin();
|
||||
// await w.pin().then(m => m.delete()); // oopsie, this deletes the pinned message
|
||||
|
||||
if (config.logs.discord.enabled)
|
||||
client.channels.cache.get(config.logs.discord.channel).send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('New ticket')
|
||||
.setDescription(`\`${topic}\``)
|
||||
.addField('Creator', message.author, true)
|
||||
.addField('Channel', c, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTimestamp()
|
||||
);
|
||||
|
||||
log.info(`${message.author.tag} created a new ticket (#${name})`);
|
||||
|
||||
|
||||
}).catch(log.error);
|
||||
|
||||
},
|
||||
};
|
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'panel',
|
||||
description: 'Create or a panel widget in the channel the command is used in. Note that there can only be 1 panel.',
|
||||
usage: '',
|
||||
aliases: ['widget'],
|
||||
args: false,
|
||||
permission: 'MANAGE_GUILD',
|
||||
async execute(client, message, _args, log, {config, Setting}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
let msgID = await Setting.findOne({ where: { key: 'panel_msg_id' } });
|
||||
let chanID = await Setting.findOne({ where: { key: 'panel_chan_id' } });
|
||||
let panel;
|
||||
|
||||
if (!chanID) {
|
||||
chanID = await Setting.create({
|
||||
key: 'panel_chan_id',
|
||||
value: message.channel.id,
|
||||
});
|
||||
}
|
||||
|
||||
if (!msgID) {
|
||||
msgID = await Setting.create({
|
||||
key: 'panel_msg_id',
|
||||
value: '',
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
panel = await client.channels.cache.get(chanID.get('value')).messages.fetch(msgID.get('value')); // get old panel message
|
||||
if (panel) {
|
||||
panel.delete({ reason: 'Creating new panel/widget' }).then(() => log.info('Deleted old panel')).catch(e => log.warn(e)); // delete old panel
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn('Couldn\'t delete old panel');
|
||||
}
|
||||
}
|
||||
|
||||
message.delete();
|
||||
|
||||
panel = await message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setTitle(config.panel.title)
|
||||
.setDescription(config.panel.description)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
); // send new panel
|
||||
|
||||
let emoji = panel.guild.emojis.cache.get(config.panel.reaction) || config.panel.reaction;
|
||||
panel.react(emoji); // add reaction
|
||||
Setting.update({ value: message.channel.id }, { where: { key: 'panel_chan_id' }}); // update database
|
||||
Setting.update({ value: panel.id }, { where: { key: 'panel_msg_id' }}); // update database
|
||||
|
||||
log.info(`${message.author.tag} created a panel widget`);
|
||||
}
|
||||
};
|
@@ -1,112 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'remove',
|
||||
description: 'Remove a member from ticket channel',
|
||||
usage: '<@member> [... #channel]',
|
||||
aliases: ['none'],
|
||||
example: 'remove @member from #ticket-23',
|
||||
args: true,
|
||||
async execute(client, message, args, log, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const notTicket = new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **This isn\'t a ticket channel**')
|
||||
.setDescription('Use this command in the ticket channel you want to remove a user from, 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 ticket;
|
||||
|
||||
let channel = message.mentions.channels.first();
|
||||
|
||||
if (!channel) {
|
||||
|
||||
channel = message.channel;
|
||||
ticket = await Ticket.findOne({ where: { channel: message.channel.id } });
|
||||
if (!ticket)
|
||||
return message.channel.send(notTicket);
|
||||
|
||||
} else {
|
||||
|
||||
ticket = await Ticket.findOne({ where: { channel: channel.id } });
|
||||
if (!ticket) {
|
||||
notTicket
|
||||
.setTitle('❌ **Channel is not a ticket**')
|
||||
.setDescription(`${channel} is not a ticket channel.`);
|
||||
return message.channel.send(notTicket);
|
||||
}
|
||||
}
|
||||
|
||||
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('❌ **No permission**')
|
||||
.setDescription(`You don't have permission to alter ${channel} as it does not belong to you and you are not staff.`)
|
||||
.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 member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
|
||||
|
||||
if (!member || member.id === message.author.id || member.id === guild.me.id)
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Unknown member**')
|
||||
.setDescription('Please mention a valid member.')
|
||||
.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())
|
||||
);
|
||||
|
||||
try {
|
||||
channel.updateOverwrite(member.user, {
|
||||
VIEW_CHANNEL: false,
|
||||
SEND_MESSAGES: false,
|
||||
ATTACH_FILES: false,
|
||||
READ_MESSAGE_HISTORY: false
|
||||
});
|
||||
|
||||
if (channel.id !== message.channel.id) {
|
||||
channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setTitle('**Member removed**')
|
||||
.setDescription(`${member} has been removed by ${message.author}`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(member.user.username, member.user.displayAvatarURL())
|
||||
.setTitle('✅ **Member removed**')
|
||||
.setDescription(`${member} has been removed from <#${ticket.channel}>`)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
log.info(`${message.author.tag} removed a user from a ticket (#${message.channel.id})`);
|
||||
} catch (error) {
|
||||
log.error(error);
|
||||
}
|
||||
},
|
||||
};
|
@@ -1,63 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author iFusion for eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'rename',
|
||||
description: 'Rename a ticket channel',
|
||||
usage: '<new name>',
|
||||
aliases: ['none'],
|
||||
example: 'rename important-ticket',
|
||||
args: true,
|
||||
async execute(client, message, args, {config, 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('❌ **This isn\'t a ticket channel**')
|
||||
.setDescription('Use this command in the ticket channel you want to rename.')
|
||||
.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())
|
||||
);
|
||||
}
|
||||
|
||||
if (!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('❌ **No permission**')
|
||||
.setDescription('You don\'t have permission to rename this channel as you are not staff.')
|
||||
.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())
|
||||
);
|
||||
|
||||
message.channel.setName(args.join('-')); // new channel name
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('✅ **Ticket updated**')
|
||||
.setDescription('The name has been changed.')
|
||||
.setFooter(client.user.username, client.user.displayAvatarURL())
|
||||
);
|
||||
}
|
||||
};
|
@@ -1,34 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'stats',
|
||||
description: 'View ticket stats.',
|
||||
usage: '',
|
||||
aliases: ['data', 'statistics'],
|
||||
|
||||
args: false,
|
||||
async execute(client, message, _args, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
let open = await Ticket.count({ where: { open: true } });
|
||||
let closed = await Ticket.count({ where: { open: false } });
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setTitle(':bar_chart: Statistics')
|
||||
.addField('Open tickets', open, true)
|
||||
.addField('Closed tickets', closed, true)
|
||||
.addField('Total tickets', open + closed, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
};
|
@@ -1,116 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
name: 'tickets',
|
||||
description: 'List your recent tickets to access transcripts / archives.',
|
||||
usage: '[@member]',
|
||||
aliases: ['list'],
|
||||
args: false,
|
||||
async execute(client, message, args, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
const supportRole = guild.roles.cache.get(config.staff_role);
|
||||
if (!supportRole) {
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setTitle('❌ **Error**')
|
||||
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
}
|
||||
|
||||
let context = 'self';
|
||||
let user = message.mentions.users.first() || guild.members.cache.get(args[0]);
|
||||
|
||||
if (user) {
|
||||
if (!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('❌ **No permission**')
|
||||
.setDescription('You don\'t have permission to list others\' tickets as you are not staff.')
|
||||
.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())
|
||||
);
|
||||
}
|
||||
|
||||
context = 'staff';
|
||||
} else user = message.author;
|
||||
|
||||
let openTickets = await Ticket.findAndCountAll({
|
||||
where: {
|
||||
creator: user.id,
|
||||
open: true
|
||||
}
|
||||
});
|
||||
|
||||
let closedTickets = await Ticket.findAndCountAll({
|
||||
where: {
|
||||
creator: user.id,
|
||||
open: false
|
||||
}
|
||||
});
|
||||
|
||||
closedTickets.rows = closedTickets.rows.slice(-10); // get most recent 10
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(user.username, user.displayAvatarURL())
|
||||
.setTitle(`${context === 'self' ? 'Your' : user.username + '\'s'} tickets`)
|
||||
.setFooter(guild.name + ' | This message will be deleted in 60 seconds', guild.iconURL());
|
||||
|
||||
/* if (config.transcripts.web.enabled) {
|
||||
embed.setDescription(`You can access all of your ticket archives on the [web portal](${config.transcripts.web.server}/${user.id}).`);
|
||||
} */
|
||||
|
||||
let open = [],
|
||||
closed = [];
|
||||
|
||||
for (let t in openTickets.rows) {
|
||||
let desc = openTickets.rows[t].topic.substring(0, 30);
|
||||
open.push(`> <#${openTickets.rows[t].channel}>: \`${desc}${desc.length > 20 ? '...' : ''}\``);
|
||||
}
|
||||
|
||||
for (let t in closedTickets.rows) {
|
||||
let desc = closedTickets.rows[t].topic.substring(0, 30);
|
||||
let transcript = '';
|
||||
let c = closedTickets.rows[t].channel;
|
||||
if (config.transcripts.web.enabled || fs.existsSync(join(__dirname, `../../user/transcripts/text/${c}.txt`))) {
|
||||
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to view.`;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
message.delete({timeout: 15000});
|
||||
|
||||
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});
|
||||
},
|
||||
};
|
@@ -1,71 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'topic',
|
||||
description: 'Edit a ticket topic',
|
||||
usage: '<topic>',
|
||||
aliases: ['edit'],
|
||||
example: 'topic need help error',
|
||||
args: true,
|
||||
async execute(client, message, args, {config, 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('❌ **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('❌ **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('✅ **Ticket updated**')
|
||||
.setDescription('The topic has been changed.')
|
||||
.setFooter(client.user.username, client.user.displayAvatarURL())
|
||||
);
|
||||
}
|
||||
};
|
@@ -1,95 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const {
|
||||
MessageEmbed
|
||||
} = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'transcript',
|
||||
description: 'Download a transcript',
|
||||
usage: '<ticket-id>',
|
||||
aliases: ['archive', 'download'],
|
||||
example: 'transcript 57',
|
||||
args: true,
|
||||
async execute(client, message, args, {config, Ticket}) {
|
||||
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('❌ **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('❌ **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, guild.iconURL());
|
||||
|
||||
let file = `../../user/transcripts/text/${ticket.channel}.txt`;
|
||||
if (fs.existsSync(join(__dirname, file))) {
|
||||
embed.addField('Text transcript', 'See attachment');
|
||||
res.files = [
|
||||
{
|
||||
attachment: join(__dirname, file),
|
||||
name: `ticket-${id}-${ticket.channel}.txt`
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
const BASE_URL = config.transcripts.web.server;
|
||||
if (config.transcripts.web.enabled) 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});
|
||||
}
|
||||
};
|
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
name: 'transfer',
|
||||
description: 'Transfer ownership of a ticket channel',
|
||||
usage: '<@member>',
|
||||
aliases: ['none'],
|
||||
example: 'transfer @user',
|
||||
args: true,
|
||||
async execute(client, message, args, { config, 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('❌ **This isn\'t a ticket channel**')
|
||||
.setDescription('Use this command in the ticket channel you want to change owner.')
|
||||
.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())
|
||||
);
|
||||
}
|
||||
|
||||
if (!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('❌ **No permission**')
|
||||
.setDescription('You don\'t have permission to change ownership of this channel as you are not staff.')
|
||||
.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 member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
|
||||
|
||||
if (!member) {
|
||||
return message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('❌ **Unknown member**')
|
||||
.setDescription('Please mention a valid member.')
|
||||
.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())
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
message.channel.setTopic(`${member} | ${ticket.topic}`);
|
||||
|
||||
Ticket.update({
|
||||
creator: member.user.id
|
||||
}, {
|
||||
where: {
|
||||
channel: message.channel.id
|
||||
}
|
||||
});
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('✅ **Ticket transferred**')
|
||||
.setDescription(`Ownership of this ticket has been transferred to ${member}.`)
|
||||
.setFooter(client.user.username, client.user.displayAvatarURL())
|
||||
);
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user