This commit is contained in:
Isaac (eartharoid)
2020-08-17 14:46:23 +01:00
parent fa36d8dbe2
commit 62494aaa4d
29 changed files with 1612 additions and 186 deletions

View File

@@ -20,6 +20,8 @@ module.exports = {
args: true,
async execute(client, message, args, Ticket) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
@@ -27,7 +29,7 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL());
.setFooter(guild.name, guild.iconURL());
let ticket;
@@ -60,12 +62,12 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
let member = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0]));
let member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
if(!member)
return message.channel.send(
@@ -76,7 +78,7 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
try {
@@ -94,7 +96,7 @@ module.exports = {
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle('**Member added**')
.setDescription(`${member} has been added by ${message.author}`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
@@ -105,7 +107,7 @@ module.exports = {
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(':white_check_mark: **Member added**')
.setDescription(`${member} has been added to <#${ticket.get('channel')}>`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
log.info(`${message.author.tag} added a user to a ticket (#${message.channel.id})`);

View File

@@ -10,6 +10,7 @@ const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const Discord = require('discord.js');
const config = require('../../user/config');
const fs = require('fs');
module.exports = {
name: 'close',
@@ -19,6 +20,8 @@ module.exports = {
example: 'close #ticket-17',
args: false,
async execute(client, message, args, Ticket) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new Discord.MessageEmbed()
.setColor(config.err_colour)
@@ -27,30 +30,18 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL());
.setFooter(guild.name, guild.iconURL());
let ticket;
const channel = message.mentions.channels.first();
// let channel = message.guild.channels.resolve(message.mentions.channels.first()); // not necessary
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: message.channel.id } });
ticket = await Ticket.findOne({ where: { channel: channel.id } });
if(!ticket)
return message.channel.send(notTicket);
ticket.update({ open: false}, { where: { channel: message.channel.id } });
message.channel.send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`:white_check_mark: **Ticket ${ticket.id} closed**`)
.setDescription('The channel will be automatically deleted once the contents have been archived.')
.setFooter(message.guild.name, message.guild.iconURL())
);
setTimeout(() => message.channel.delete(), 5000);
return channel.send(notTicket);
} else {
@@ -59,11 +50,11 @@ module.exports = {
notTicket
.setTitle(':x: **Channel is not a ticket**')
.setDescription(`${channel} is not a ticket channel.`);
return message.channel.send(notTicket);
return channel.send(notTicket);
}
if(message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
return message.channel.send(
return channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
@@ -71,36 +62,92 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
}
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')}\``
: '';
let confirm = await message.channel.send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':grey_question: Are you sure?')
.setDescription(`${pre}\n**React with :white_check_mark: 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', () => {
if (channel.id !== message.channel.id)
channel.send(
new Discord.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())
);
ticket.update({ open: false}, { where: { channel: channel.id } });
message.channel.send(
confirm.reactions.removeAll();
confirm.edit(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`:white_check_mark: **Ticket ${ticket.id} closed**`)
.setDescription('The channel will be automatically deleted once the contents have been archived.')
.setFooter(message.guild.name, message.guild.iconURL())
.setDescription('The channel will be automatically deleted in a few seconds, once the contents have been archived.')
.setFooter(guild.name, guild.iconURL())
);
setTimeout(() => channel.delete(), 5000);
}
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);
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.get('id')})`);
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.get('id')})`);
if (config.logs.discord.enabled)
client.channels.cache.get(config.logs.discord.channel).send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle('Ticket closed')
.addField('Creator', `<@${ticket.get('creator')}>` , true)
.addField('Closed by', message.author, true)
.setFooter(client.user.username, client.user.avatarURL())
.setTimestamp()
);
if (config.logs.discord.enabled)
client.channels.cache.get(config.logs.discord.channel).send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle('Ticket closed')
.addField('Creator', `<@${ticket.get('creator')}>` , true)
.addField('Closed by', message.author, true)
.setFooter(guild.name, guild.iconURL())
.setTimestamp()
);
});
collector.on('end', () => {
if(!success) {
confirm.reactions.removeAll();
confirm.edit(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':x: **Expired**')
.setDescription('You took to long to react; confirmation failed.')
.setFooter(guild.name, guild.iconURL()));
message.delete({ timeout: 10000 })
.then(() => confirm.delete());
}
});
},
}
};

View File

@@ -19,6 +19,8 @@ module.exports = {
example: 'help new',
args: false,
execute(client, message, args) {
const guild = client.guilds.cache.get(config.guild);
const commands = Array.from(client.commands.values());
@@ -47,7 +49,7 @@ module.exports = {
\n${cmds.join('\n\n')}
\nPlease contact a member of staff if you require assistance.`
)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
.setTimestamp()
).catch((error) => {
log.warn('Could not send help menu');

View File

@@ -21,15 +21,16 @@ module.exports = {
args: false,
async execute(client, message, args, Ticket) {
const supportRole = message.guild.roles.cache.get(config.staff_role);
const guild = client.guilds.cache.get(config.guild);
const supportRole = guild.roles.cache.get(config.staff_role);
if (!supportRole)
return message.channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setTitle(':x: **Error**')
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
@@ -44,9 +45,9 @@ module.exports = {
if (tickets.count >= config.tickets.max) {
let ticketList = [];
for (let t in tickets.rows) {
let desc = tickets.rows[t].topic.substring(0, 20);
let desc = tickets.rows[t].topic.substring(0, 30);
ticketList
.push(`<#${tickets.rows[t].channel}>: \`${desc}${desc.length > 20 ? '...' : ''}\``);
.push(`<#${tickets.rows[t].channel}>: \`${desc}${desc.length > 30 ? '...' : ''}\``);
}
let m = await message.channel.send(
@@ -55,7 +56,7 @@ module.exports = {
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`:x: **You already have ${tickets.count} or more open tickets**`)
.setDescription(`Use \`${config.prefix}close\` to close unneeded tickets.\n\n${ticketList.join(',\n')}`)
.setFooter(message.guild.name + ' | This message will be deleted in 15 seconds', message.guild.iconURL())
.setFooter(guild.name + ' | This message will be deleted in 15 seconds', guild.iconURL())
);
return setTimeout(async () => {
@@ -73,7 +74,7 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
else if (topic.length < 1)
topic = 'No topic given';
@@ -89,12 +90,12 @@ module.exports = {
let name = 'ticket-' + ticket.get('id');
message.guild.channels.create(name, {
guild.channels.create(name, {
type: 'text',
topic: `${message.author} | ${topic}`,
parent: config.tickets.category,
permissionOverwrites: [{
id: message.guild.roles.everyone,
id: guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
@@ -130,7 +131,8 @@ module.exports = {
await message.delete();
await m.delete();
}, 15000);
require('../utils/archive').create(client, c); // create files
let ping;
switch (config.tickets.ping) {
@@ -167,7 +169,7 @@ module.exports = {
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setDescription(text)
.addField('Topic', `\`${topic}\``)
.setFooter(client.user.username, client.user.avatarURL())
.setFooter(guild.name, guild.iconURL())
);
if (config.tickets.pin)
@@ -183,7 +185,7 @@ module.exports = {
.setDescription(`\`${topic}\``)
.addField('Creator', message.author, true)
.addField('Channel', c, true)
.setFooter(client.user.username, client.user.avatarURL())
.setFooter(guild.name, guild.iconURL())
.setTimestamp()
);

63
src/commands/panel.js Normal file
View File

@@ -0,0 +1,63 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const Discord = require('discord.js');
const config = require('../../user/config');
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'],
example: '',
args: false,
permission: 'MANAGE_SERVER',
async execute(client, message, args, Ticket, 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 {
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')); // delete old panel
}
message.delete();
panel = await message.channel.send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setTitle(config.panel.title)
.setDescription(config.panel.description)
.setFooter(guild.name, guild.iconURL())
.setTimestamp()
); // send new panel
panel.react(config.panel.reaction); // add reaction
Setting.update({ value: panel.id }, { where: { key: 'panel_msg_id' }}); // update database
log.info(`${message.author.tag} created a panel widget`);
}
};

View File

@@ -20,6 +20,8 @@ module.exports = {
args: true,
async execute(client, message, args, Ticket) {
const guild = client.guilds.cache.get(config.guild);
const notTicket = new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
@@ -27,7 +29,7 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL());
.setFooter(guild.name, guild.iconURL());
let ticket;
@@ -60,12 +62,12 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
let member = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[0]));
let member = guild.member(message.mentions.users.first() || guild.members.cache.get(args[0]));
if(!member)
return message.channel.send(
@@ -76,7 +78,7 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
try {
@@ -94,7 +96,7 @@ module.exports = {
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle('**Member remove**')
.setDescription(`${member} has been removed by ${message.author}`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
@@ -105,7 +107,7 @@ module.exports = {
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(':white_check_mark: **Member removed**')
.setDescription(`${member} has been removed from <#${ticket.get('channel')}>`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
log.info(`${message.author.tag} removed a user from a ticket (#${message.channel.id})`);

23
src/commands/stats.js Normal file
View File

@@ -0,0 +1,23 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const Discord = require('discord.js');
const config = require('../../user/config');
module.exports = {
name: 'stats',
description: 'View ticket stats.',
usage: '',
aliases: ['data'],
example: '',
args: false,
async execute(client, message, args, Ticket) {
}
};

View File

@@ -18,22 +18,23 @@ module.exports = {
example: '',
args: false,
async execute(client, message, args, Ticket) {
const supportRole = message.guild.roles.cache.get(config.staff_role);
const guild = client.guilds.cache.get(config.guild);
const supportRole = guild.roles.cache.get(config.staff_role);
if (!supportRole)
return message.channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setTitle(':x: **Error**')
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
let context;
let user = message.mentions.users.first() || message.guild.members.cache.get(args[0]);
let context = 'self';
let user = message.mentions.users.first() || guild.members.cache.get(args[0]);
if(!user) {
if(user) {
if(!message.member.roles.cache.has(config.staff_role))
return message.channel.send(
new Discord.MessageEmbed()
@@ -43,14 +44,13 @@ module.exports = {
.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(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
user = message.author;
context = 'staff';
} else {
user = message.author;
}
context = 'self';
let openTickets = await Ticket.findAndCountAll({
@@ -71,9 +71,9 @@ module.exports = {
let embed = new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle('Your tickets')
.setFooter(message.guild.name + ' | This message will be deleted in 60 seconds', message.guild.iconURL());
.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}).`);
@@ -91,13 +91,14 @@ module.exports = {
for (let t in closedTickets.rows) {
let desc = closedTickets.rows[t].topic.substring(0, 30);
let transcript = '';
if(fs.existsSync(`user/transcripts/text/${closedTickets.rows[t].channel}.txt`))
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.`;
closed.push(`> #${closedTickets.rows[t].id}: \`${desc}${desc.length > 20 ? '...' : ''}\`${transcript}`);
}
let pre = context === 'self' ? 'You have' : user + ' has';
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);

View File

@@ -18,6 +18,9 @@ module.exports = {
example: 'transcript 57',
args: false,
async execute(client, message, args, Ticket) {
/** @TODO TRY TO SEND ATTACHMENT TO DM */
/**
* @TODO TRY TO SEND ATTACHMENT TO DM
* @TODO ONLY ALLOW CREATOR AND STAFF TO RUN CMD
*/
}
};

View File

@@ -11,7 +11,7 @@ const log = new ChildLogger();
module.exports = {
event: 'debug',
execute(client, e) {
execute(client, [e]) {
log.debug(e);
}
};

View File

@@ -11,7 +11,7 @@ const log = new ChildLogger();
module.exports = {
event: 'error',
execute(client, e) {
execute(client, [e]) {
log.error(e);
}
};

View File

@@ -10,18 +10,68 @@ const Discord = require('discord.js');
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const config = require('../../user/config');
const fs = require('fs');
const dtf = require('@eartharoid/dtf');
module.exports = {
event: 'message',
async execute(client, message, Ticket) {
async execute(client, [message], {Ticket, Setting}) {
const guild = client.guilds.cache.get(config.guild);
if (message.author.bot || message.author.id === client.user.id) return;
if (message.channel.type === 'dm') {
log.console(`Received a DM from ${message.author.tag}: ${message.cleanContent}`);
return message.channel.send(`Hello there, ${message.author.username}!
I am the support bot for **${client.guilds.cache.get(config.guild)}**.
I am the support bot for **${guild}**.
Type \`${config.prefix}new\` on the server to create a new ticket.`);
}
}
if (message.guild.id !== guild.id)
return message.reply(`This bot can only be used within the "${guild}" server`);
/**
*
* Ticket transcripts
*
*/
let ticket = await Ticket.findOne({ where: { channel: message.channel.id } });
if(ticket) {
if(config.transcripts.text.enabled) {
let path = `user/transcripts/text/${message.channel.id}.txt`;
let time = dtf('HH:mm:ss n_D MMM YY', message.createdAt),
name = message.author.tag,
msg = message.cleanContent;
let string = `[${time}] [${name}] :> ${msg}`;
fs.appendFileSync(path, string + '\n');
}
if(config.transcripts.web.enabled) {
let path = `user/transcripts/raw/${message.channel.id}.log`;
let embeds = [];
for (let embed in message.embeds)
embeds.push(message.embeds[embed].toJSON());
fs.appendFileSync(path, JSON.stringify({
id: message.id,
type: 'UNKNOWN',
author: message.author.id,
content: message.content,
// deleted: false,
time: message.createdTimestamp,
embeds: embeds,
attachments: [...message.attachments]
}) + ', \n');
}
}
/**
*
* Command handler
*
*/
const prefixRegex = new RegExp(`^(<@!?${client.user.id}>|\\${config.prefix})\\s*`);
if (!prefixRegex.test(message.content)) return;
@@ -38,7 +88,7 @@ Type \`${config.prefix}new\` on the server to create a new ticket.`);
.setColor(config.err_colour)
.setTitle(':x: No permission')
.setDescription(`**You do not have permission to use the \`${command.name}\` command** (requires \`${command.permission}\`).`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
}
@@ -48,7 +98,7 @@ Type \`${config.prefix}new\` on the server to create a new ticket.`);
.setColor(config.err_colour)
.addField('Usage', `\`${config.prefix}${command.name} ${command.usage}\`\n`)
.addField('Help', `Type \`${config.prefix}help ${command.name}\` for more information`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
if (!client.cooldowns.has(command.name)) client.cooldowns.set(command.name, new Discord.Collection());
@@ -67,7 +117,7 @@ Type \`${config.prefix}new\` on the server to create a new ticket.`);
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setDescription(`:x: Please wait ${timeLeft.toFixed(1)} second(s) before reusing the \`${command.name}\` command.`)
.setFooter(message.guild.name, message.guild.iconURL())
.setFooter(guild.name, guild.iconURL())
);
}
}
@@ -76,7 +126,7 @@ Type \`${config.prefix}new\` on the server to create a new ticket.`);
setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);
try {
command.execute(client, message, args, Ticket);
command.execute(client, message, args, Ticket, Setting);
log.console(`${message.author.tag} used the '${command.name}' command`);
} catch (error) {
log.warn(`An error occurred whilst executing the '${command.name}' command`);

View File

@@ -0,0 +1,199 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const Discord = require('discord.js');
const config = require('../../user/config');
const fs = require('fs');
module.exports = {
event: 'messageReactionAdd',
async execute(client, [r, u], {Ticket, Setting}) {
if (r.partial)
try {
await r.fetch();
} catch (err) {
log.error(err);
return;
}
let panelID = await Setting.findOne({ where: { key: 'panel_msg_id' } });
if (!panelID) return;
if(r.message.id !== panelID.get('value')) return;
if (r.emoji.name !== config.panel.reaction || u.id === client.user.id) return;
let channel = r.message.channel;
const supportRole = channel.guild.roles.cache.get(config.staff_role);
if (!supportRole)
return channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setTitle(':x: **Error**')
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
.setFooter(channel.guild.name, channel.guild.iconURL())
);
// everything is cool
await r.users.remove(u.id); // effectively cancel reaction
let tickets = await Ticket.findAndCountAll({
where: {
creator: u.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 dm = u.dmChannel || await u.createDM();
try {
return dm.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle(`:x: **You already have ${tickets.count} or more open tickets**`)
.setDescription(`Use \`${config.prefix}close\` in a server channel to close unneeded tickets.\n\n${ticketList.join(',\n')}`)
.setFooter(channel.guild.name, channel.guild.iconURL())
);
} catch (e) {
let m = await channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle(`:x: **You already have ${tickets.count} or more open tickets**`)
.setDescription(`Use \`${config.prefix}close\` to close unneeded tickets.\n\n${ticketList.join(',\n')}`)
.setFooter(channel.guild.name + ' | This message will be deleted in 15 seconds', channel.guild.iconURL())
);
return m.delete({ timeout: 15000 });
}
}
let topic = 'No topic given (created via panel)';
let ticket = await Ticket.create({
channel: '',
creator: u.id,
open: true,
archived: false,
topic: topic
});
let name = 'ticket-' + ticket.get('id');
channel.guild.channels.create(name, {
type: 'text',
topic: `${u} | ${topic}`,
parent: config.tickets.category,
permissionOverwrites: [{
id: channel.guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: channel.guild.member(u),
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
}
});
require('../utils/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 + `${u} has created a new ticket`);
if (config.tickets.send_img) {
const images = fs.readdirSync('user/images');
await c.send({
files: [
'user/images/' +
images[Math.floor(Math.random() * images.length)]
]
});
}
let text = config.tickets.text
.replace('{{ name }}', u.username)
.replace('{{ tag }}', u);
let w = await c.send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(u.username, u.displayAvatarURL())
.setDescription(text)
.addField('Topic', `\`${topic}\``)
.setFooter(channel.guild.name, channel.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 Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle('New ticket (via panel)')
.setDescription(`\`${topic}\``)
.addField('Creator', u, true)
.addField('Channel', c, true)
.setFooter(channel.guild.name, channel.guild.iconURL())
.setTimestamp()
);
log.info(`${u.tag} created a new ticket (#${name}) via panel`);
}).catch(log.error);
}
};

View File

@@ -0,0 +1,27 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
const Discord = require('discord.js');
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const config = require('../../user/config');
const fs = require('fs');
const dtf = require('@eartharoid/dtf');
module.exports = {
event: 'messageUpdate',
async execute(client, [o, n], {Ticket, Setting}) {
/**
* CHECK IF O === N
*/
console.log(o.author.tag);
// https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-messageUpdate
// append new to raw
}
};

View File

@@ -11,8 +11,8 @@ const log = new ChildLogger();
module.exports = {
event: 'rateLimit',
execute(client, limit) {
log.warn('Rate-limited!');
execute(client, [limit]) {
log.warn('Rate-limited! (Enable debug mode in config for details)');
log.debug(limit);
}
};

View File

@@ -12,7 +12,7 @@ const config = require('../../user/config');
module.exports = {
event: 'ready',
execute(client) {
execute(client, [e], {Ticket, Setting}) {
log.success(`Authenticated as ${client.user.tag}`);

View File

@@ -11,7 +11,7 @@ const log = new ChildLogger();
module.exports = {
event: 'warn',
execute(client, e) {
execute(client, [e]) {
log.warn(e);
}
};

View File

@@ -11,7 +11,8 @@ const Discord = require('discord.js');
const fs = require('fs');
const leeks = require('leeks.js');
const client = new Discord.Client({
autoReconnect: true
autoReconnect: true,
partials: ['MESSAGE', 'CHANNEL', 'REACTION']
});
client.events = new Discord.Collection();
client.commands = new Discord.Collection();
@@ -66,7 +67,17 @@ Ticket.init({
modelName: 'ticket'
});
class Setting extends Model {}
Setting.init({
key: DataTypes.STRING,
value: DataTypes.STRING,
}, {
sequelize,
modelName: 'setting'
});
Ticket.sync();
Setting.sync();
/**
* event loader
@@ -75,7 +86,8 @@ const events = fs.readdirSync('src/events').filter(file => file.endsWith('.js'))
for (const file of events) {
const event = require(`./events/${file}`);
client.events.set(event.event, event);
client.on(event.event, e => client.events.get(event.event).execute(client, e, Ticket));
// client.on(event.event, e => client.events.get(event.event).execute(client, e, Ticket, Setting));
client.on(event.event, (e1, e2) => client.events.get(event.event).execute(client, [e1, e2], {Ticket, Setting}));
log.console(log.format(`> Loaded &7${event.event}&f event`));
}
@@ -93,7 +105,8 @@ log.info(`Loaded ${events.length} events and ${commands.length} commands`);
process.on('unhandledRejection', error => {
log.warn('An error was not caught');
log.error(`Uncaught error: \n${error.stack}`);
log.warn(`Uncaught ${error.name}: ${error.message}`);
log.error(error);
});
client.login(process.env.TOKEN);

View File

@@ -8,15 +8,43 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const lineReader = require('line-reader');
const fs = require('fs');
const config = require('../../user/config');
module.exports.create = (client, channel) => {
// channel.members
if(config.transcripts.text.enabled) {
// text/channel.txt
}
if(config.transcripts.web.enabled) {
// raw/channel.log
}
};
module.exports.addUser = (client, channel, user) => {
};
module.exports.addMessage = (client, channel, message) => {
// if !entities.users.user, add
};
module.exports.export = (client, channel) => {
let path = `user/transcripts/raw/${channel.id}.log`;
if(config.transcripts.web.enabled && fs.existsSync(path)) {
lineReader.eachLine(path, (line, last) => {
console.log(line);
//if raw id exists, overwrite previous
});
}
/**
* @TODO users, roles, etc
* check channel.members again!
* */
};

View File

@@ -7,6 +7,8 @@
*/
const { version, homepage } = require('../../package.json');
const link = require('terminal-link');
module.exports = (leeks) => {
console.log(leeks.colours.cyan(`
######## #### ###### ###### ####### ######## ########
@@ -26,6 +28,7 @@ module.exports = (leeks) => {
## #### ###### ## ## ######## ## ######
`));
console.log(leeks.colours.cyanBright(`DiscordTickets bot v${version} by eartharoid`));
console.log(leeks.colours.cyanBright(homepage));
console.log(leeks.colours.cyanBright(homepage + '\n'));
console.log(leeks.colours.cyanBright(`Please ${link('donate', 'https://ko-fi.com/eartharoid')} if you find this bot useful`));
console.log('\n\n');
};

180
src/utils/panel.js Normal file
View File

@@ -0,0 +1,180 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const Discord = require('discord.js');
const fs = require('fs');
const config = require('../../user/config');
module.exports = async (client, Ticket, Setting) => {
let panelID = await Setting.findOne({ where: { key: 'panel_msg_id' } });
if (!panelID) return;
let chanID = await Setting.findOne({ where: { key: 'panel_chan_id' } });
if (!chanID) return;
let channel = client.channels.cache.get(chanID.get('value'));
if (!channel)
return Setting.destroy({ where: { key: 'panel_chan_id' } });
let panel = channel.messages.cache.get(panelID.get('value'));
if(!panel)
return Setting.destroy({ where: { key: 'panel_msg_id' } });
const collector = panel.createReactionCollector(
(r, u) => r.emoji.name === config.panel.reaction && u.id !== client.user.id);
collector.on('collect', async (r, u) => {
await r.users.remove(u.id); // effectively cancel reaction
const supportRole = channel.guild.roles.cache.get(config.staff_role);
if (!supportRole)
return channel.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setTitle(':x: **Error**')
.setDescription(`${config.name} has not been set up correctly. Could not find a 'support team' role with the id \`${config.staff_role}\``)
.setFooter(channel.guild.name, channel.guild.iconURL())
);
let tickets = await Ticket.findAndCountAll({
where: {
creator: u.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 dm = u.dmChannel || await u.createDM();
let m = await dm.send(
new Discord.MessageEmbed()
.setColor(config.err_colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle(`:x: **You already have ${tickets.count} or more open tickets**`)
.setDescription(`Use \`${config.prefix}close\` to close unneeded tickets.\n\n${ticketList.join(',\n')}`)
.setFooter(channel.guild.name + ' | This message will be deleted in 15 seconds', channel.guild.iconURL())
);
return m.delete({ timeout: 15000 });
}
let topic = 'No topic given (created via panel)';
let ticket = await Ticket.create({
channel: '',
creator: u.id,
open: true,
archived: false,
topic: topic
});
let name = 'ticket-' + ticket.get('id');
channel.guild.channels.create(name, {
type: 'text',
topic: `${u} | ${topic}`,
parent: config.tickets.category,
permissionOverwrites: [{
id: channel.guild.roles.everyone,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES']
},
{
id: channel.guild.member(u),
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 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 + `${u} has created a new ticket`);
if (config.tickets.send_img) {
const images = fs.readdirSync('user/images');
await c.send({
files: [
'user/images/' +
images[Math.floor(Math.random() * images.length)]
]
});
}
let text = config.tickets.text
.replace('{{ name }}', u.username)
.replace('{{ tag }}', u);
let w = await c.send(
new Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(u.username, u.displayAvatarURL())
.setDescription(text)
.addField('Topic', `\`${topic}\``)
.setFooter(channel.guild.name, channel.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 Discord.MessageEmbed()
.setColor(config.colour)
.setAuthor(u.username, u.displayAvatarURL())
.setTitle('New ticket (via panel)')
.setDescription(`\`${topic}\``)
.addField('Creator', u, true)
.addField('Channel', c, true)
.setFooter(channel.guild.name, channel.guild.iconURL())
.setTimestamp()
);
log.info(`${u.tag} created a new ticket (#${name}) via panel`);
}).catch(log.error);
});
};

View File

@@ -8,10 +8,13 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const leeks = require('leeks.js');
const fetch = require('node-fetch');
const config = require('../../user/config');
let {version} = require('../../package.json');
version = 'v' + version;
const boxen = require('boxen');
const link = require('terminal-link');
module.exports = () => {
if(!config.updater)
@@ -21,11 +24,24 @@ module.exports = () => {
.then(res => res.json())
.then(json => {
const update = json[0];
let notice = [];
if (version !== update.tag_name) {
log.notice('There is an update available for Discord Tickets');
log.info(`Download "&f${update.name}&3" from &6https://github.com/eartharoid/DiscordTickets/releases/`);
log.notice(`You currently have ${version}; The latest is ${update.tag_name}`);
log.notice(log.f(`There is an update available for Discord Tickets (${version} -> ${update.tag_name})`));
notice.push(`&6You are currently using &c${version}&6, the latest is &a${update.tag_name}&6.`);
notice.push(`&6Download "&f${update.name}&6" from`);
notice.push(link('&6the GitHub releases page', 'https://github.com/eartharoid/DiscordTickets/releases/'));
console.log(
boxen(log.f(notice.join('\n')), {
padding: 1,
margin: 1,
align: 'center',
borderColor: 'yellow',
borderStyle: 'round'
})
);
}
});
};