almost done....

This commit is contained in:
Isaac (eartharoid) 2020-08-23 22:01:21 +01:00
parent 6425e3930c
commit 5c65888c95
21 changed files with 261 additions and 128 deletions

3
.gitignore vendored
View File

@ -1,6 +1,7 @@
logs/
node_modules/
user/.env
user/dev.env
user/dev.config.js
user/storage.db
user/transcripts/text/*.txt
user/transcripts/raw/*.log

View File

@ -7,7 +7,7 @@
*/
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config.js');
const config = require('../../user/' + require('../').config);
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
@ -53,7 +53,7 @@ module.exports = {
}
}
if(message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@ -106,7 +106,7 @@ module.exports = {
.setColor(config.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(':white_check_mark: **Member added**')
.setDescription(`${member} has been added to <#${ticket.get('channel')}>`)
.setDescription(`${member} has been added to <#${ticket.channel}>`)
.setFooter(guild.name, guild.iconURL())
);

View File

@ -9,7 +9,7 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
const fs = require('fs');
const archive = require('../modules/archive');
@ -59,10 +59,10 @@ module.exports = {
notTicket
.setTitle(':x: **Channel is not a ticket**')
.setDescription(`${channel} is not a ticket channel.`);
return channel.send(notTicket);
return message.channel.send(notTicket);
}
if (message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
return channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@ -78,7 +78,7 @@ module.exports = {
let success;
let pre = fs.existsSync(`user/transcripts/text/${channel.id}.txt`) ||
fs.existsSync(`user/transcripts/raw/${channel.id}.log`) ?
`You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.get('id')}\`` :
`You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\`` :
'';
let confirm = await message.channel.send(
@ -118,23 +118,8 @@ module.exports = {
.setFooter(guild.name, guild.iconURL())
);
success = true;
ticket.update({
open: false
}, {
where: {
channel: channel.id
}
});
setTimeout(() => {
channel.delete();
if (channel.id !== message.channel.id)
message.delete()
.then(() => confirm.delete());
}, 15000);
if (config.transcripts.text.enabled || config.transcripts.web.enabled) {
let u = await client.users.fetch(ticket.get('creator'));
let u = await client.users.fetch(ticket.creator);
if (u) {
let dm;
@ -145,51 +130,55 @@ module.exports = {
}
await dm.send(
new MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`**Ticket ${ticket.id} closed**`)
.setDescription('Your ticket has been closed.')
.setFooter(guild.name, guild.iconURL())
);
if (config.transcripts.text.enabled && fs.existsSync(`user/transcripts/text/${channel.id}.txt`)) {
try {
await dm.send('A basic text transcript of the ticket channel is attached:', {
files: [
`user/transcripts/text/${channel.id}.txt`
]
});
} catch (e) {
log.warn(`Failed to send text transcript to ${u.tag}`);
}
let res = {};
const embed = new MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`Ticket ${ticket.id}`)
.setFooter(guild.name, guild.iconURL());
if (fs.existsSync(`user/transcripts/text/${ticket.get('channel')}.txt`)) {
embed.addField('Text transcript', 'See attachment');
res.files = [
{
attachment: `user/transcripts/text/${ticket.get('channel')}.txt`,
name: `ticket-${ticket.id}-${ticket.get('channel')}.txt`
}
];
}
if (config.transcripts.web.enabled) {
try {
let url = await archive.export(client, channel);
if (fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`))
embed.addField('Web archive', `${await archive.export(Ticket, channel)}`);
await dm.send(
new MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`**Ticket ${ticket.id} web archive**`)
.setDescription(`You can view an archive of your ticket channel [here](${url})`)
.setFooter(guild.name, guild.iconURL())
);
} catch (e) {
log.warn(`Failed to send archive URL to ${u.tag}`);
log.warn(e);
}
if (embed.fields.length < 1)
embed.setDescription(`No text transcripts or archive data exists for ticket ${ticket.id}`);
}
res.embed = embed;
dm.send(res).then();
}
}
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.get('id')})`);
// update database
success = true;
ticket.update({
open: false
}, {
where: {
channel: channel.id
}
});
// delete messages and channel
setTimeout(() => {
channel.delete();
if (channel.id !== message.channel.id)
message.delete()
.then(() => confirm.delete());
}, 5000);
log.info(`${message.author.tag} closed a ticket (#ticket-${ticket.id})`);
if (config.logs.discord.enabled)
client.channels.cache.get(config.logs.discord.channel).send(
@ -197,7 +186,7 @@ module.exports = {
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle('Ticket closed')
.addField('Creator', `<@${ticket.get('creator')}>`, true)
.addField('Creator', `<@${ticket.creator}>`, true)
.addField('Closed by', message.author, true)
.setFooter(guild.name, guild.iconURL())
.setTimestamp()

View File

@ -9,7 +9,7 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'help',

View File

@ -10,7 +10,7 @@ const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const fs = require('fs');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'new',

View File

@ -9,7 +9,7 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'panel',

View File

@ -7,7 +7,7 @@
*/
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config.js');
const config = require('../../user/' + require('../').config);
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
@ -53,7 +53,7 @@ module.exports = {
}
}
if(message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
if(message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
@ -106,7 +106,7 @@ module.exports = {
.setColor(config.colour)
.setAuthor(member.user.username, member.user.displayAvatarURL())
.setTitle(':white_check_mark: **Member removed**')
.setDescription(`${member} has been removed from <#${ticket.get('channel')}>`)
.setDescription(`${member} has been removed from <#${ticket.channel}>`)
.setFooter(guild.name, guild.iconURL())
);

View File

@ -9,7 +9,7 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'stats',

View File

@ -8,7 +8,7 @@
const { MessageEmbed } = require('discord.js');
const fs = require('fs');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'tickets',
@ -93,23 +93,26 @@ module.exports = {
let transcript = '';
let c = closedTickets.rows[t].channel;
if(fs.existsSync(`user/transcripts/text/${c}.txt`) || fs.existsSync(`user/transcripts/raw/${c}.log`))
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to download text transcript.`;
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to view.`;
closed.push(`> #${closedTickets.rows[t].id}: \`${desc}${desc.length > 20 ? '...' : ''}\`${transcript}`);
closed.push(`> **#${closedTickets.rows[t].id}**: \`${desc}${desc.length > 20 ? '...' : ''}\`${transcript}`);
}
let pre = context === 'self' ? 'You have' : user.username + ' has';
embed.addField('Open tickets', openTickets.count === 0 ? `${pre} no open tickets.` : open.join('\n\n'), false);
embed.addField('Closed tickets', closedTickets.count === 0 ? `${pre} no old tickets` : closed.join('\n\n'), false);
let m = await message.channel.send(embed);
return setTimeout(async () => {
await message.delete();
await m.delete();
}, 60000);
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});
},
};

View File

@ -6,10 +6,8 @@
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'topic',
@ -17,8 +15,59 @@ module.exports = {
usage: '<topic>',
aliases: ['edit'],
example: 'topic need help error',
args: false,
args: true,
async execute(client, message, args, Ticket) {
const guild = client.guilds.cache.get(config.guild);
let ticket = await Ticket.findOne({
where: {
channel: message.channel.id
}
});
if (!ticket)
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':x: **This isn\'t a ticket channel**')
.setDescription('Use this command in the ticket channel you want to close, or mention the channel.')
.addField('Usage', `\`${config.prefix}${this.name} ${this.usage}\`\n`)
.addField('Help', `Type \`${config.prefix}help ${this.name}\` for more information`)
.setFooter(guild.name, guild.iconURL())
);
let topic = args.join(' ');
if (topic.length > 256)
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':x: **Description too long**')
.setDescription('Please limit your ticket topic to less than 256 characters. A short sentence will do.')
.setFooter(guild.name, guild.iconURL())
);
message.channel.setTopic(`<@${ticket.creator}> | ` + topic);
Ticket.update({
topic: topic
}, {
where: {
channel: message.channel.id
}
});
message.channel.send(
new MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':white_check_mark: **Ticket updated**')
.setDescription('The topic has been changed.')
.setFooter(client.user.username, client.user.avatarURL())
);
}
};

View File

@ -6,10 +6,11 @@
*
*/
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const fs = require('fs');
const {
MessageEmbed
} = require('discord.js');
const config = require('../../user/' + require('../').config);
module.exports = {
name: 'transcript',
@ -17,11 +18,77 @@ module.exports = {
usage: '<ticket-id>',
aliases: ['archive', 'download'],
example: 'transcript 57',
args: false,
args: true,
async execute(client, message, args, Ticket) {
/**
* @TODO TRY TO SEND ATTACHMENT TO DM
* @TODO ONLY ALLOW CREATOR AND STAFF TO RUN CMD
*/
const guild = client.guilds.cache.get(config.guild);
const id = args[0];
let ticket = await Ticket.findOne({
where: {
id: id,
open: false
}
});
if (!ticket)
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':x: **Unknown ticket**')
.setDescription('Couldn\'t find a closed ticket with that ID')
.setFooter(guild.name, guild.iconURL())
);
if (message.author.id !== ticket.creator && !message.member.roles.cache.has(config.staff_role))
return message.channel.send(
new MessageEmbed()
.setColor(config.err_colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(':x: **No permission**')
.setDescription(`You don't have permission to view ticket ${id} as it does not belong to you and you are not staff.`)
.setFooter(guild.name, guild.iconURL())
);
let res = {};
const embed = new MessageEmbed()
.setColor(config.colour)
.setAuthor(message.author.username, message.author.displayAvatarURL())
.setTitle(`Ticket ${id}`)
.setFooter(guild.name + ' | This message will be deleted in 15 seconds', guild.iconURL());
if (fs.existsSync(`user/transcripts/text/${ticket.channel}.txt`)) {
embed.addField('Text transcript', 'See attachment');
res.files = [
{
attachment: `user/transcripts/text/${ticket.channel}.txt`,
name: `ticket-${id}-${ticket.channel}.txt`
}
];
}
const BASE_URL = config.transcripts.web.server;
if (fs.existsSync(`user/transcripts/raw/${ticket.channel}.log`))
embed.addField('Web archive', `${BASE_URL}/${ticket.creator}/${ticket.channel}`);
if (embed.fields.length < 1)
embed.setDescription(`No text transcripts or archive data exists for ticket ${id}`);
res.embed = embed;
let channel;
try {
channel = message.author.dmChannel || await message.author.createDM();
} catch (e) {
channel = message.channel;
}
channel.send(res).then(m => {
if (channel.id === message.channel.id)
m.delete({timeout: 15000});
});
message.delete({timeout: 1500});
}
};

View File

@ -9,7 +9,7 @@
const { Collection, MessageEmbed } = require('discord.js');
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
const archive = require('../modules/archive');
module.exports = {
@ -32,7 +32,7 @@ Type \`${config.prefix}new\` on the server to create a new ticket.`);
let ticket = await Ticket.findOne({ where: { channel: message.channel.id } });
if(ticket)
archive.add(client, message); // add message to archive
archive.add(message); // add message to archive
if (message.author.bot || message.author.id === client.user.id) return; // goodbye bots

View File

@ -6,12 +6,10 @@
*
*/
const Discord = require('discord.js');
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
const fs = require('fs');
const dtf = require('@eartharoid/dtf');
module.exports = {
event: 'messageDelete',
@ -23,7 +21,8 @@ module.exports = {
try {
await message.fetch();
} catch (err) {
log.error(err);
log.warn('Failed to fetch deleted messaged');
log.error(err.message);
return;
}

View File

@ -9,7 +9,7 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const { MessageEmbed } = require('discord.js');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
const fs = require('fs');
module.exports = {
@ -104,7 +104,7 @@ module.exports = {
topic: topic
});
let name = 'ticket-' + ticket.get('id');
let name = 'ticket-' + ticket.id;
channel.guild.channels.create(name, {
type: 'text',

View File

@ -9,7 +9,7 @@
const Discord = require('discord.js');
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
const fs = require('fs');
const dtf = require('@eartharoid/dtf');

View File

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

View File

@ -5,11 +5,17 @@
* @license GNU-GPLv3
*
*/
require('dotenv').config({path: 'user/.env'});
const Discord = require('discord.js');
const fs = require('fs');
const leeks = require('leeks.js');
const path = require('path');
let dev = fs.existsSync('user/dev.env') && fs.existsSync('user/dev.config.js');
require('dotenv').config({path: path.join('user/', dev ? 'dev.env' : '.env')});
module.exports.config = dev ? 'dev.config.js' : 'config.js';
const config = require(path.join('../user/', module.exports.config));
const Discord = require('discord.js');
const client = new Discord.Client({
autoReconnect: true,
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
@ -18,9 +24,10 @@ client.events = new Discord.Collection();
client.commands = new Discord.Collection();
client.cooldowns = new Discord.Collection();
const utils = require('./modules/utils');
const leeks = require('leeks.js');
require('./modules/banner')(leeks); // big coloured text thing
const config = require('../user/config');
const Logger = require('leekslazylogger');
const log = new Logger({
name: config.name,
@ -28,6 +35,7 @@ const log = new Logger({
maxAge: config.logs.files.keep_for,
debug: config.debug
});
log.multi(log); // required to allow other files to access the logger
require('./modules/updater')(); // check for updates

View File

@ -11,9 +11,9 @@ const log = new ChildLogger();
const lineReader = require('line-reader');
const fs = require('fs');
const dtf = require('@eartharoid/dtf');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
module.exports.add = (client, message) => {
module.exports.add = (message) => {
if(message.type !== 'DEFAULT') return;
@ -92,7 +92,13 @@ module.exports.add = (client, message) => {
}
};
module.exports.export = (client, channel) => new Promise((resolve, reject) => {
module.exports.export = (Ticket, channel) => new Promise((resolve, reject) => {
let ticket = (async () => await Ticket.findOne({
where: {
channel: channel.id
}
}))();
let raw = `user/transcripts/raw/${channel.id}.log`,
json = `user/transcripts/raw/entities/${channel.id}.json`;
@ -102,6 +108,14 @@ module.exports.export = (client, channel) => new Promise((resolve, reject) => {
let data = JSON.parse(fs.readFileSync(json));
data.ticket = {
id: ticket.id,
name: channel.name,
creator: ticket.creator,
channel: channel.id,
topic: channel.topic
};
data.messages = [];
lineReader.eachLine(raw, line => {
@ -115,8 +129,12 @@ module.exports.export = (client, channel) => new Promise((resolve, reject) => {
data.messages[index] = message;
}, () => {
// fs.writeFileSync('user/data.json', JSON.stringify(data)); // FOR TESTING
// post(data).then()
// delete raw .json and .log
/**
* @todo post(data).then()
* @todo if 200 OK delete raw .json and .log
*/
resolve(config.transcripts.web.server); // json.url
});
});

View File

@ -8,9 +8,8 @@
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const leeks = require('leeks.js');
const fetch = require('node-fetch');
const config = require('../../user/config');
const config = require('../../user/' + require('../').config);
let {version} = require('../../package.json');
version = 'v' + version;
const boxen = require('boxen');

View File

@ -29,24 +29,24 @@
module.exports = {
prefix: '-',
name: 'DiscordTickets',
activities: ['-new', 'with tickets', 'for new tickets'], /** @INFO " | {PRE}help" */
activity_types: ['PLAYING', 'PLAYING', 'WATCHING'], /** @INFO paired */
activities: ['-new', 'with tickets', 'for new tickets'],
activity_types: ['PLAYING', 'PLAYING', 'WATCHING'],
colour: '#009999',
err_colour: '#E74C3C',
cooldown: 3,
guild: '451745464480432129', // ID of your guild
staff_role: '451745586564169728', // ID of your Support Team role
guild: '', // ID of your guild
staff_role: '', // ID of your Support Team role
tickets: {
category: '620272351988285480', // ID of your tickets category
category: '', // ID of your tickets category
send_img: true,
ping: 'here', /** @INFO here, everyone, staff, false */
ping: 'here',
text: `Hello there, {{ tag }}!
A member of staff will assist you shortly.
In the mean time, please describe your issue in as much detail as possible! :)`, // {{ name }} and {{ tag }}
In the mean time, please describe your issue in as much detail as possible! :)`,
pin: false,
max: 3 /** @INFO OPEN */
max: 3
},
transcripts: {
@ -55,8 +55,8 @@ module.exports = {
keep_for: 90,
},
web: {
enabled: true,
server: 'https://tickets.example.com', // WITHOUT! trailing /
enabled: false,
server: 'https://tickets.example.com',
}
},
@ -76,11 +76,11 @@ module.exports = {
keep_for: 7
},
discord: {
enabled: true,
channel: '573957980152791080' // ID of your log channel
enabled: false,
channel: '' // ID of your log channel
}
},
debug: false,
updater: false /** @INFO ENABLE BY DEFAULT */
updater: true
};