Finished web archives, added suppor for custom emoji for panel reaction, minor fixes

This commit is contained in:
Isaac (eartharoid) 2020-08-25 15:55:20 +01:00
parent 4009daffbb
commit 015351afe5
7 changed files with 80 additions and 51 deletions

View File

@ -8,7 +8,9 @@
const ChildLogger = require('leekslazylogger').ChildLogger; const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger(); const log = new ChildLogger();
const { MessageEmbed } = require('discord.js'); const {
MessageEmbed
} = require('discord.js');
const fs = require('fs'); const fs = require('fs');
const archive = require('../modules/archive'); const archive = require('../modules/archive');
@ -19,7 +21,10 @@ module.exports = {
aliases: ['none'], aliases: ['none'],
example: 'close #ticket-17', example: 'close #ticket-17',
args: false, args: false,
async execute(client, message, args, {config, Ticket}) { async execute(client, message, args, {
config,
Ticket
}) {
const guild = client.guilds.cache.get(config.guild); const guild = client.guilds.cache.get(config.guild);
@ -138,17 +143,16 @@ module.exports = {
if (fs.existsSync(`user/transcripts/text/${ticket.get('channel')}.txt`)) { if (fs.existsSync(`user/transcripts/text/${ticket.get('channel')}.txt`)) {
embed.addField('Text transcript', 'See attachment'); embed.addField('Text transcript', 'See attachment');
res.files = [ res.files = [{
{
attachment: `user/transcripts/text/${ticket.get('channel')}.txt`, attachment: `user/transcripts/text/${ticket.get('channel')}.txt`,
name: `ticket-${ticket.id}-${ticket.get('channel')}.txt` name: `ticket-${ticket.id}-${ticket.get('channel')}.txt`
} }];
];
} }
if (fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`)) if (fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`))
embed.addField('Web archive', `${await archive.export(Ticket, channel)}`); embed.addField('Web archive', `${await archive.export(Ticket, channel)}`);
if (embed.fields.length < 1) if (embed.fields.length < 1)
embed.setDescription(`No text transcripts or archive data exists for ticket ${ticket.id}`); embed.setDescription(`No text transcripts or archive data exists for ticket ${ticket.id}`);

View File

@ -58,7 +58,8 @@ module.exports = {
.setFooter(guild.name, guild.iconURL()) .setFooter(guild.name, guild.iconURL())
); // send new panel ); // send new panel
panel.react(config.panel.reaction); // add reaction 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: message.channel.id }, { where: { key: 'panel_chan_id' }}); // update database
Setting.update({ value: panel.id }, { where: { key: 'panel_msg_id' }}); // update database Setting.update({ value: panel.id }, { where: { key: 'panel_msg_id' }}); // update database

View File

@ -91,7 +91,7 @@ module.exports = {
let desc = closedTickets.rows[t].topic.substring(0, 30); let desc = closedTickets.rows[t].topic.substring(0, 30);
let transcript = ''; let transcript = '';
let c = closedTickets.rows[t].channel; let c = closedTickets.rows[t].channel;
if(fs.existsSync(`user/transcripts/text/${c}.txt`) || fs.existsSync(`user/transcripts/raw/${c}.log`)) if(fs.existsSync(`user/transcripts/text/${c}.txt`) || config.transcripts.web.enabled)
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to view.`; 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}`);

View File

@ -69,7 +69,7 @@ module.exports = {
const BASE_URL = config.transcripts.web.server; const BASE_URL = config.transcripts.web.server;
if (fs.existsSync(`user/transcripts/raw/${ticket.channel}.log`)) if (config.transcripts.web.enabled)
embed.addField('Web archive', `${BASE_URL}/${ticket.creator}/${ticket.channel}`); embed.addField('Web archive', `${BASE_URL}/${ticket.creator}/${ticket.channel}`);
if (embed.fields.length < 1) if (embed.fields.length < 1)

View File

@ -28,7 +28,9 @@ module.exports = {
if(r.message.id !== panelID.get('value')) return; if(r.message.id !== panelID.get('value')) return;
if (r.emoji.name !== config.panel.reaction || u.id === client.user.id) return; if(u.id === client.user.id) return;
if (r.emoji.name !== config.panel.reaction && r.emoji.id !== config.panel.reaction) return;
let channel = r.message.channel; let channel = r.message.channel;

View File

@ -6,10 +6,14 @@
* *
*/ */
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const lineReader = require('line-reader'); const lineReader = require('line-reader');
const fs = require('fs'); const fs = require('fs');
const dtf = require('@eartharoid/dtf'); const dtf = require('@eartharoid/dtf');
const config = require('../../user/' + require('../').config); const config = require('../../user/' + require('../').config);
const fetch = require('node-fetch');
module.exports.add = (message) => { module.exports.add = (message) => {
@ -45,7 +49,6 @@ module.exports.add = (message) => {
// channel entities // channel entities
if (!fs.existsSync(json)) if (!fs.existsSync(json))
fs.writeFileSync(json, JSON.stringify({ fs.writeFileSync(json, JSON.stringify({
channel_name: message.channel.name,
entities: { entities: {
users: {}, users: {},
channels: {}, channels: {},
@ -71,7 +74,7 @@ module.exports.add = (message) => {
avatar: m.user.avatarURL(), avatar: m.user.avatarURL(),
username: m.user.username, username: m.user.username,
discriminator: m.user.discriminator, discriminator: m.user.discriminator,
displayName: m.user.displayName, displayName: m.user.displayName || m.user.username,
color: m.displayColor, color: m.displayColor,
badge: m.user.bot ? 'bot' : null badge: m.user.bot ? 'bot' : null
}); });
@ -92,11 +95,12 @@ module.exports.add = (message) => {
module.exports.export = (Ticket, channel) => new Promise((resolve, reject) => { module.exports.export = (Ticket, channel) => new Promise((resolve, reject) => {
let ticket = (async () => await Ticket.findOne({ (async () => {
let ticket = await Ticket.findOne({
where: { where: {
channel: channel.id channel: channel.id
} }
}))(); });
let raw = `user/transcripts/raw/${channel.id}.log`, let raw = `user/transcripts/raw/${channel.id}.log`,
json = `user/transcripts/raw/entities/${channel.id}.json`; json = `user/transcripts/raw/entities/${channel.id}.json`;
@ -118,21 +122,38 @@ module.exports.export = (Ticket, channel) => new Promise((resolve, reject) => {
lineReader.eachLine(raw, line => { lineReader.eachLine(raw, line => {
let message = JSON.parse(line); let message = JSON.parse(line);
// data.messages[message.id] = message;
let index = data.messages.findIndex(m => m.id === message.id); let index = data.messages.findIndex(m => m.id === message.id);
if (index === -1) if (index === -1)
data.messages.push(message); data.messages.push(message);
else else
data.messages[index] = message; data.messages[index] = message;
}, () => { }, () => {
// fs.writeFileSync('user/data.json', JSON.stringify(data)); // FOR TESTING fs.writeFileSync('user/data.json', JSON.stringify(data)); // FOR TESTING
/** /**
* @todo post(data).then() * @todo post(data).then()
* @todo if 200 OK delete raw .json and .log * @todo if 200 OK delete raw .json and .log
*/ */
let endpoint = config.transcripts.web.server;
if (endpoint[endpoint.length - 1] === '/')
endpoint = endpoint.slice(0, -1);
endpoint += `/${data.ticket.creator}/${data.ticket.channel}/?key=${process.env.ARCHIVES_KEY}`;
fetch(endpoint, {
method: 'post',
body: JSON.stringify(data),
headers: { 'Content-Type': 'application/json' },
})
.then(res => res.json())
.then(json => {
if (json.status !== 200) {
log.warn(json);
return resolve(new Error(`${json.status} (${json.message})`));
}
log.success(`Uploaded ${ticket.id} archive to server`);
resolve(json.url);
});
});
})();
resolve(config.transcripts.web.server); // json.url
});
}); });

1
user/data.json Normal file
View File

@ -0,0 +1 @@
{"entities":{"users":{"475371285531066368":{"avatar":"https://cdn.discordapp.com/avatars/475371285531066368/962b420d036d3f310e4a920f8517d01c.webp","username":"Roadside Assistance","discriminator":"2057","displayName":"Roadside Assistance","color":39321,"badge":"bot"},"319467558166069248":{"avatar":"https://cdn.discordapp.com/avatars/319467558166069248/c0a069ef452737cc75609430a5b6f14f.webp","username":"Eartharoid","discriminator":"2006","displayName":"Eartharoid","color":15277667,"badge":null}},"channels":{},"roles":{}},"ticket":{"id":55,"name":"ticket-55","creator":"319467558166069248","channel":"747831136801259652","topic":"<@319467558166069248> | No topic given"},"messages":[{"id":"747831139024240691","author":"475371285531066368","content":"@here,\n<@319467558166069248> has created a new ticket","time":1598367237574,"embeds":[],"attachments":[]},{"id":"747831144455602268","author":"475371285531066368","content":"","time":1598367238869,"embeds":[],"attachments":[{"attachment":"https://cdn.discordapp.com/attachments/747831136801259652/747831143986102342/how-can-we-help.gif","name":"how-can-we-help.gif","id":"747831143986102342","size":1721116,"url":"https://cdn.discordapp.com/attachments/747831136801259652/747831143986102342/how-can-we-help.gif","proxyURL":"https://media.discordapp.net/attachments/747831136801259652/747831143986102342/how-can-we-help.gif","height":278,"width":498}]},{"id":"747831145437200475","author":"475371285531066368","content":"","time":1598367239103,"embeds":[{"type":"rich","description":"Hello there, <@319467558166069248>!\n\t\tA member of staff will assist you shortly.\n\t\tIn the mean time, please describe your issue in as much detail as possible! :)","timestamp":null,"color":39321,"fields":[{"value":"`No topic given`","name":"Topic","inline":false}],"thumbnail":null,"image":null,"author":{"name":"Eartharoid","icon_url":"https://cdn.discordapp.com/avatars/319467558166069248/c0a069ef452737cc75609430a5b6f14f.webp"},"footer":{"text":"Planet Earth","icon_url":"https://cdn.discordapp.com/icons/451745464480432129/ec04e2401da3b6a1c0b75dfed2beaf15.webp"}}],"attachments":[]},{"id":"747831155121979552","author":"319467558166069248","content":"fjndsg","time":1598367241412,"embeds":[],"attachments":[]},{"id":"747831156703101131","author":"319467558166069248","content":"dsg","time":1598367241789,"embeds":[],"attachments":[]},{"id":"747831158913630238","author":"319467558166069248","content":"dfg","time":1598367242316,"embeds":[],"attachments":[]},{"id":"747831160993742928","author":"319467558166069248","content":"fdg","time":1598367242812,"embeds":[],"attachments":[]},{"id":"747831162193313913","author":"319467558166069248","content":"dfgasdfdsgdfgdf","time":1598367243098,"embeds":[],"attachments":[],"edited":true},{"id":"747831163803926580","author":"319467558166069248","content":"fdg","time":1598367243482,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831165091840054","author":"319467558166069248","content":"fdg","time":1598367243789,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831166677155852","author":"319467558166069248","content":"fdg","time":1598367244167,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831168682164365","author":"319467558166069248","content":"dfg","time":1598367244645,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831178194714734","author":"319467558166069248","content":"fdg","time":1598367246913,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831180325421107","author":"319467558166069248","content":"fdg","time":1598367247421,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831209265987744","author":"319467558166069248","content":"sdg","time":1598367254321,"embeds":[],"attachments":[],"edited":false,"deleted":true},{"id":"747831222423519342","author":"319467558166069248","content":"degfdsg","time":1598367257458,"embeds":[],"attachments":[]},{"id":"747831228748529774","author":"319467558166069248","content":"-close","time":1598367258966,"embeds":[],"attachments":[]},{"id":"747831229558161488","author":"475371285531066368","content":"","time":1598367259159,"embeds":[{"title":":grey_question: Are you sure?","type":"rich","description":"You will be able to view an archived version later with `-transcript 55`\n**React with :white_check_mark: to confirm.**","timestamp":null,"color":39321,"fields":[],"thumbnail":null,"image":null,"author":{"name":"Eartharoid","icon_url":"https://cdn.discordapp.com/avatars/319467558166069248/c0a069ef452737cc75609430a5b6f14f.webp"},"footer":{"text":"Planet Earth | Expires in 15 seconds","icon_url":"https://cdn.discordapp.com/icons/451745464480432129/ec04e2401da3b6a1c0b75dfed2beaf15.webp"}}],"attachments":[]}]}