mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2025-09-02 00:31:27 +03:00
progress. archiving works (other than uploading to server)
This commit is contained in:
@@ -11,6 +11,7 @@ const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
const fs = require('fs');
|
||||
const archive = require('../utils/archive');
|
||||
|
||||
module.exports = {
|
||||
name: 'close',
|
||||
@@ -22,7 +23,7 @@ module.exports = {
|
||||
async execute(client, message, args, Ticket) {
|
||||
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
||||
|
||||
const notTicket = new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
@@ -31,29 +32,37 @@ module.exports = {
|
||||
.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) {
|
||||
if (!channel) {
|
||||
channel = message.channel;
|
||||
|
||||
ticket = await Ticket.findOne({ where: { channel: channel.id } });
|
||||
if(!ticket)
|
||||
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) {
|
||||
ticket = await Ticket.findOne({
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
if (!ticket) {
|
||||
notTicket
|
||||
.setTitle(':x: **Channel is not a ticket**')
|
||||
.setDescription(`${channel} is not a ticket channel.`);
|
||||
return channel.send(notTicket);
|
||||
}
|
||||
|
||||
if(message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
|
||||
if (message.author.id !== ticket.get('creator') && !message.member.roles.cache.has(config.staff_role))
|
||||
return channel.send(
|
||||
new MessageEmbed()
|
||||
.setColor(config.err_colour)
|
||||
@@ -67,10 +76,10 @@ 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')}\``
|
||||
: '';
|
||||
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 MessageEmbed()
|
||||
@@ -82,12 +91,13 @@ module.exports = {
|
||||
);
|
||||
|
||||
await confirm.react('✅');
|
||||
|
||||
|
||||
const collector = confirm.createReactionCollector(
|
||||
(r, u) => r.emoji.name === '✅' && u.id === message.author.id,
|
||||
{ time: 15000 });
|
||||
|
||||
collector.on('collect', () => {
|
||||
(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()
|
||||
@@ -109,32 +119,94 @@ module.exports = {
|
||||
);
|
||||
|
||||
success = true;
|
||||
ticket.update({ open: false}, { where: { channel: channel.id } });
|
||||
ticket.update({
|
||||
open: false
|
||||
}, {
|
||||
where: {
|
||||
channel: channel.id
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
channel.delete();
|
||||
if (channel.id !== message.channel.id)
|
||||
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'));
|
||||
|
||||
if (u) {
|
||||
let dm;
|
||||
try {
|
||||
dm = u.dmChannel || await u.createDM();
|
||||
} catch (e) {
|
||||
log.warn(`Could not create DM channel with ${u.tag}`);
|
||||
}
|
||||
|
||||
|
||||
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}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (config.transcripts.web.enabled) {
|
||||
try {
|
||||
let url = await archive.export(client, 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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 MessageEmbed()
|
||||
.setColor(config.colour)
|
||||
.setAuthor(message.author.username, message.author.displayAvatarURL())
|
||||
.setTitle('Ticket closed')
|
||||
.addField('Creator', `<@${ticket.get('creator')}>` , true)
|
||||
.addField('Creator', `<@${ticket.get('creator')}>`, true)
|
||||
.addField('Closed by', message.author, true)
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
.setTimestamp()
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
collector.on('end', () => {
|
||||
if(!success) {
|
||||
if (!success) {
|
||||
confirm.reactions.removeAll();
|
||||
confirm.edit(
|
||||
new MessageEmbed()
|
||||
@@ -143,11 +215,13 @@ module.exports = {
|
||||
.setTitle(':x: **Expired**')
|
||||
.setDescription('You took to long to react; confirmation failed.')
|
||||
.setFooter(guild.name, guild.iconURL()));
|
||||
|
||||
message.delete({ timeout: 10000 })
|
||||
|
||||
message.delete({
|
||||
timeout: 10000
|
||||
})
|
||||
.then(() => confirm.delete());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
};
|
@@ -132,7 +132,7 @@ module.exports = {
|
||||
await m.delete();
|
||||
}, 15000);
|
||||
|
||||
require('../utils/archive').create(client, c); // create files
|
||||
// require('../utils/archive').create(client, c); // create files
|
||||
|
||||
let ping;
|
||||
switch (config.tickets.ping) {
|
||||
|
@@ -41,7 +41,7 @@ module.exports = {
|
||||
} 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
|
||||
panel.delete({ reason: 'Creating new panel/widget' }).then(() => log.info('Deleted old panel')).catch(e => log.warn(e)); // delete old panel
|
||||
}
|
||||
|
||||
message.delete();
|
||||
@@ -55,6 +55,7 @@ module.exports = {
|
||||
); // send new panel
|
||||
|
||||
panel.react(config.panel.reaction); // 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`);
|
||||
|
@@ -8,16 +8,31 @@
|
||||
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const Discord = require('discord.js');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
|
||||
module.exports = {
|
||||
name: 'stats',
|
||||
description: 'View ticket stats.',
|
||||
usage: '',
|
||||
aliases: ['data'],
|
||||
aliases: ['data', 'statistics'],
|
||||
example: '',
|
||||
args: false,
|
||||
async execute(client, message, args, 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())
|
||||
);
|
||||
}
|
||||
};
|
24
src/commands/topic.js
Normal file
24
src/commands/topic.js
Normal file
@@ -0,0 +1,24 @@
|
||||
/**
|
||||
*
|
||||
* @name DiscordTickets
|
||||
* @author eartharoid <contact@eartharoid.me>
|
||||
* @license GNU-GPLv3
|
||||
*
|
||||
*/
|
||||
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
|
||||
module.exports = {
|
||||
name: 'topic',
|
||||
description: 'Edit a ticket topic',
|
||||
usage: '<topic>',
|
||||
aliases: ['edit'],
|
||||
example: 'topic need help error',
|
||||
args: false,
|
||||
async execute(client, message, args, Ticket) {
|
||||
|
||||
}
|
||||
};
|
@@ -6,8 +6,9 @@
|
||||
*
|
||||
*/
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const ChildLogger = require('leekslazylogger').ChildLogger;
|
||||
const log = new ChildLogger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const config = require('../../user/config');
|
||||
|
||||
module.exports = {
|
||||
|
@@ -32,9 +32,9 @@ 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.addMessage(client, message);
|
||||
archive.add(client, message); // add message to archive
|
||||
|
||||
if (message.author.bot || message.author.id === client.user.id) return; // if bot, fuck off
|
||||
if (message.author.bot || message.author.id === client.user.id) return; // goodbye bots
|
||||
|
||||
|
||||
/**
|
||||
|
@@ -43,7 +43,8 @@ module.exports = {
|
||||
time: message.createdTimestamp,
|
||||
embeds: embeds,
|
||||
attachments: [...message.attachments.values()],
|
||||
deleted: true
|
||||
edited: message.edits.length > 1,
|
||||
deleted: true // delete the message
|
||||
}) + '\n');
|
||||
|
||||
}
|
||||
|
@@ -134,7 +134,7 @@ module.exports = {
|
||||
}
|
||||
});
|
||||
|
||||
require('../utils/archive').create(client, c); // create files
|
||||
// require('../utils/archive').create(client, c); // create files
|
||||
|
||||
let ping;
|
||||
switch (config.tickets.ping) {
|
||||
|
@@ -14,7 +14,7 @@ const fs = require('fs');
|
||||
const dtf = require('@eartharoid/dtf');
|
||||
|
||||
module.exports = {
|
||||
event: 'oUpdate',
|
||||
event: 'messageUpdate',
|
||||
async execute(client, [o, n], {Ticket}) {
|
||||
|
||||
if(!config.transcripts.web.enabled) return;
|
||||
@@ -29,29 +29,29 @@ module.exports = {
|
||||
|
||||
if (n.partial)
|
||||
try {
|
||||
await o.fetch();
|
||||
await n.fetch();
|
||||
} catch (err) {
|
||||
log.error(err);
|
||||
return;
|
||||
}
|
||||
|
||||
if(o === n) return;
|
||||
if(o.content === n.content) return; // apparently editing a message isn't the only thing that emits this event
|
||||
|
||||
let ticket = await Ticket.findOne({ where: { channel: o.channel.id } });
|
||||
let ticket = await Ticket.findOne({ where: { channel: n.channel.id } });
|
||||
if(!ticket) return;
|
||||
|
||||
let path = `user/transcripts/raw/${o.channel.id}.log`;
|
||||
let path = `user/transcripts/raw/${n.channel.id}.log`;
|
||||
let embeds = [];
|
||||
for (let embed in o.embeds)
|
||||
embeds.push(o.embeds[embed].toJSON());
|
||||
for (let embed in n.embeds)
|
||||
embeds.push(n.embeds[embed].toJSON());
|
||||
|
||||
fs.appendFileSync(path, JSON.stringify({
|
||||
id: o.id,
|
||||
author: o.author.id,
|
||||
content: o.content, // do not use cleanContent!
|
||||
time: o.createdTimestamp,
|
||||
id: n.id,
|
||||
author: n.author.id,
|
||||
content: n.content, // do not use cleanContent!
|
||||
time: n.createdTimestamp,
|
||||
embeds: embeds,
|
||||
attachments: [...o.attachments.values()],
|
||||
attachments: [...n.attachments.values()],
|
||||
edited: true
|
||||
}) + '\n');
|
||||
|
||||
|
@@ -13,24 +13,11 @@ const fs = require('fs');
|
||||
const dtf = require('@eartharoid/dtf');
|
||||
const config = require('../../user/config');
|
||||
|
||||
module.exports.create = (client, channel) => {
|
||||
module.exports.add = (client, message) => {
|
||||
|
||||
// channel.members
|
||||
if(message.type !== 'DEFAULT') return;
|
||||
|
||||
if(config.transcripts.text.enabled) {
|
||||
// text/channel.txt
|
||||
}
|
||||
|
||||
if(config.transcripts.web.enabled) {
|
||||
// raw/channel.log
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
module.exports.addMessage = async (client, message) => {
|
||||
|
||||
if(config.transcripts.text.enabled) { // text transcripts
|
||||
if (config.transcripts.text.enabled) { // text transcripts
|
||||
let path = `user/transcripts/text/${message.channel.id}.txt`,
|
||||
time = dtf('HH:mm:ss n_D MMM YY', message.createdAt),
|
||||
msg = message.cleanContent;
|
||||
@@ -39,14 +26,14 @@ module.exports.addMessage = async (client, message) => {
|
||||
fs.appendFileSync(path, string + '\n');
|
||||
}
|
||||
|
||||
if(config.transcripts.web.enabled) { // web archives
|
||||
if (config.transcripts.web.enabled) { // web archives
|
||||
let raw = `user/transcripts/raw/${message.channel.id}.log`,
|
||||
json = `user/transcripts/raw/entities/${message.channel.id}.json`;
|
||||
|
||||
|
||||
let embeds = [];
|
||||
for (let embed in message.embeds)
|
||||
embeds.push(message.embeds[embed].toJSON());
|
||||
|
||||
|
||||
// message
|
||||
fs.appendFileSync(raw, JSON.stringify({
|
||||
id: message.id,
|
||||
@@ -56,15 +43,22 @@ module.exports.addMessage = async (client, message) => {
|
||||
embeds: embeds,
|
||||
attachments: [...message.attachments.values()]
|
||||
}) + '\n');
|
||||
|
||||
// channel entities
|
||||
if(!fs.existsSync(json))
|
||||
await fs.writeFileSync(json, '{}');
|
||||
|
||||
let entities = await JSON.parse(fs.readFileSync(json));
|
||||
|
||||
if(!entities.users[message.author.id]) {
|
||||
entities.users[message.author.id] = {
|
||||
// channel entities
|
||||
if (!fs.existsSync(json))
|
||||
fs.writeFileSync(json, JSON.stringify({
|
||||
channel_name: message.channel.name,
|
||||
entities: {
|
||||
users: {},
|
||||
channels: {},
|
||||
roles: {}
|
||||
}
|
||||
})); // create new
|
||||
|
||||
let data = JSON.parse(fs.readFileSync(json));
|
||||
|
||||
if (!data.entities.users[message.author.id]) {
|
||||
data.entities.users[message.author.id] = {
|
||||
avatar: message.author.avatarURL(),
|
||||
username: message.author.username,
|
||||
discriminator: message.author.discriminator,
|
||||
@@ -74,27 +68,44 @@ module.exports.addMessage = async (client, message) => {
|
||||
};
|
||||
}
|
||||
|
||||
message.mentions.channels.each(c => entities.channels[c.id].name = c.name);
|
||||
message.mentions.channels.each(c => data.entities.channels[c.id] = {
|
||||
name: c.name
|
||||
});
|
||||
|
||||
message.mentions.roles.each(r => entities.roles[r.id] = {
|
||||
message.mentions.roles.each(r => data.entities.roles[r.id] = {
|
||||
name: r.name,
|
||||
color: r.color
|
||||
});
|
||||
|
||||
|
||||
fs.writeFileSync(json, JSON.stringify(data));
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
module.exports.export = (client, channel) => {
|
||||
let path = `user/transcripts/raw/${channel.id}.log`;
|
||||
module.exports.export = (client, channel) => new Promise((resolve, reject) => {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(!config.transcripts.web.enabled || !fs.existsSync(path))
|
||||
return reject(false);
|
||||
let raw = `user/transcripts/raw/${channel.id}.log`,
|
||||
json = `user/transcripts/raw/entities/${channel.id}.json`;
|
||||
|
||||
lineReader.eachLine(path, (line, last) => {
|
||||
console.log(line);
|
||||
// if raw id exists, overwrite previous
|
||||
// also: channel_name
|
||||
});
|
||||
});
|
||||
};
|
||||
if (!config.transcripts.web.enabled || !fs.existsSync(raw) || !fs.existsSync(json))
|
||||
return reject(false);
|
||||
|
||||
let data = JSON.parse(fs.readFileSync(json));
|
||||
|
||||
data.messages = [];
|
||||
|
||||
lineReader.eachLine(raw, line => {
|
||||
let message = JSON.parse(line);
|
||||
// data.messages[message.id] = message;
|
||||
let index = data.messages.findIndex(m => m.id === message.id);
|
||||
|
||||
if (index === -1)
|
||||
data.messages.push(message);
|
||||
else
|
||||
data.messages[index] = message;
|
||||
}, () => {
|
||||
// fs.writeFileSync('user/data.json', JSON.stringify(data)); // FOR TESTING
|
||||
// post(data).then()
|
||||
resolve(config.transcripts.web.server); // json.url
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user