mirror of
https://github.com/Hessenuk/DiscordTickets.git
synced 2024-12-22 15:53:08 +02:00
v2.1.1 - Paths are no longer relative
This commit is contained in:
parent
726d326656
commit
16876b1408
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@eartharoid/discordtickets",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.1",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@eartharoid/discordtickets",
|
||||
"version": "2.1.0",
|
||||
"version": "2.1.1",
|
||||
"private": true,
|
||||
"description": "An open-source & self-hosted Discord bot for ticket management.",
|
||||
"main": "src/index.js",
|
||||
|
@ -8,10 +8,9 @@
|
||||
|
||||
const Logger = require('leekslazylogger');
|
||||
const log = new Logger();
|
||||
const {
|
||||
MessageEmbed
|
||||
} = require('discord.js');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const archive = require('../modules/archive');
|
||||
|
||||
module.exports = {
|
||||
@ -74,8 +73,8 @@ module.exports = {
|
||||
);
|
||||
|
||||
let success;
|
||||
let pre = fs.existsSync(`user/transcripts/text/${channel.id}.txt`) ||
|
||||
fs.existsSync(`user/transcripts/raw/${channel.id}.log`) ?
|
||||
let pre = fs.existsSync(join(__dirname, `../../user/transcripts/text/${channel.id}.txt`)) ||
|
||||
fs.existsSync(join(__dirname, `../../user/transcripts/raw/${channel.id}.log`)) ?
|
||||
`You will be able to view an archived version later with \`${config.prefix}transcript ${ticket.id}\`` :
|
||||
'';
|
||||
|
||||
@ -136,15 +135,15 @@ module.exports = {
|
||||
.setTitle(`Ticket ${ticket.id}`)
|
||||
.setFooter(guild.name, guild.iconURL());
|
||||
|
||||
if (fs.existsSync(`user/transcripts/text/${ticket.get('channel')}.txt`)) {
|
||||
if (fs.existsSync(join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`))) {
|
||||
embed.addField('Text transcript', 'See attachment');
|
||||
res.files = [{
|
||||
attachment: `user/transcripts/text/${ticket.get('channel')}.txt`,
|
||||
attachment: join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
|
||||
name: `ticket-${ticket.id}-${ticket.get('channel')}.txt`
|
||||
}];
|
||||
}
|
||||
|
||||
if (fs.existsSync(`user/transcripts/raw/${ticket.get('channel')}.log`) && fs.existsSync(`user/transcripts/raw/entities/${ticket.get('channel')}.json`)) {
|
||||
if (fs.existsSync(join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`)) && fs.existsSync(join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`))) {
|
||||
embed.addField('Web archive', await archive.export(Ticket, channel));
|
||||
}
|
||||
|
||||
@ -154,7 +153,12 @@ module.exports = {
|
||||
|
||||
res.embed = embed;
|
||||
|
||||
dm.send(res).then();
|
||||
|
||||
try {
|
||||
dm.send(res).then();
|
||||
} catch (e) {
|
||||
message.channel.send(':x: Couldn\'t send DM');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ const {
|
||||
MessageEmbed
|
||||
} = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
name: 'delete',
|
||||
@ -117,9 +118,9 @@ module.exports = {
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
let txt = `user/transcripts/text/${ticket.get('channel')}.txt`,
|
||||
raw = `user/transcripts/raw/${ticket.get('channel')}.log`,
|
||||
json = `user/transcripts/raw/entities/${ticket.get('channel')}.json`;
|
||||
let txt = join(__dirname, `../../user/transcripts/text/${ticket.get('channel')}.txt`),
|
||||
raw = join(__dirname, `../../user/transcripts/raw/${ticket.get('channel')}.log`),
|
||||
json = join(__dirname, `../../user/transcripts/raw/entities/${ticket.get('channel')}.json`);
|
||||
|
||||
if (fs.existsSync(txt)) fs.unlinkSync(txt);
|
||||
if (fs.existsSync(raw)) fs.unlinkSync(raw);
|
||||
|
@ -10,6 +10,7 @@ const Logger = require('leekslazylogger');
|
||||
const log = new Logger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
name: 'new',
|
||||
@ -149,11 +150,10 @@ module.exports = {
|
||||
await c.send(ping + `${message.author} has created a new ticket`);
|
||||
|
||||
if (config.tickets.send_img) {
|
||||
const images = fs.readdirSync('user/images');
|
||||
const images = fs.readdirSync(join(__dirname, '../../user/images'));
|
||||
await c.send({
|
||||
files: [
|
||||
'user/images/' +
|
||||
images[Math.floor(Math.random() * images.length)]
|
||||
join(__dirname, '../../user/images', images[Math.floor(Math.random() * images.length)])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ module.exports = {
|
||||
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_GUILD',
|
||||
async execute(client, message, _args, {config, Setting}) {
|
||||
|
@ -13,7 +13,7 @@ module.exports = {
|
||||
description: 'Rename a ticket channel',
|
||||
usage: '<new name>',
|
||||
aliases: ['none'],
|
||||
example: '',
|
||||
example: 'rename important-ticket',
|
||||
args: true,
|
||||
async execute(client, message, args, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
@ -49,7 +49,7 @@ module.exports = {
|
||||
.setFooter(guild.name, guild.iconURL())
|
||||
);
|
||||
|
||||
message.channel.setName(args.join(' ')); // new channel name
|
||||
message.channel.setName(args.join('-')); // new channel name
|
||||
|
||||
message.channel.send(
|
||||
new MessageEmbed()
|
||||
|
@ -13,7 +13,7 @@ module.exports = {
|
||||
description: 'View ticket stats.',
|
||||
usage: '',
|
||||
aliases: ['data', 'statistics'],
|
||||
example: '',
|
||||
|
||||
args: false,
|
||||
async execute(client, message, _args, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
|
@ -8,13 +8,13 @@
|
||||
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
name: 'tickets',
|
||||
description: 'List your recent tickets to access transcripts / archives.',
|
||||
usage: '[@member]',
|
||||
aliases: ['list'],
|
||||
example: '',
|
||||
args: false,
|
||||
async execute(client, message, args, {config, Ticket}) {
|
||||
const guild = client.guilds.cache.get(config.guild);
|
||||
@ -88,7 +88,7 @@ module.exports = {
|
||||
let desc = closedTickets.rows[t].topic.substring(0, 30);
|
||||
let transcript = '';
|
||||
let c = closedTickets.rows[t].channel;
|
||||
if (fs.existsSync(`user/transcripts/text/${c}.txt`) || config.transcripts.web.enabled) {
|
||||
if (config.transcripts.web.enabled || fs.existsSync(join(__dirname, `../../user/transcripts/text/${c}.txt`))) {
|
||||
transcript = `\n> Type \`${config.prefix}transcript ${closedTickets.rows[t].id}\` to view.`;
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@
|
||||
*/
|
||||
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
const {
|
||||
MessageEmbed
|
||||
} = require('discord.js');
|
||||
@ -59,11 +61,12 @@ module.exports = {
|
||||
.setTitle(`Ticket ${id}`)
|
||||
.setFooter(guild.name, guild.iconURL());
|
||||
|
||||
if (fs.existsSync(`user/transcripts/text/${ticket.channel}.txt`)) {
|
||||
let file = `../../user/transcripts/text/${ticket.channel}.txt`;
|
||||
if (fs.existsSync(join(__dirname, file))) {
|
||||
embed.addField('Text transcript', 'See attachment');
|
||||
res.files = [
|
||||
{
|
||||
attachment: `user/transcripts/text/${ticket.channel}.txt`,
|
||||
attachment: join(__dirname, file),
|
||||
name: `ticket-${id}-${ticket.channel}.txt`
|
||||
}
|
||||
];
|
||||
|
@ -9,6 +9,7 @@
|
||||
const Logger = require('leekslazylogger');
|
||||
const log = new Logger();
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
event: 'messageDelete',
|
||||
@ -29,11 +30,11 @@ module.exports = {
|
||||
if (!ticket) return;
|
||||
|
||||
|
||||
let path = `user/transcripts/raw/${message.channel.id}.log`;
|
||||
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({
|
||||
fs.appendFileSync(join(__dirname, path), JSON.stringify({
|
||||
id: message.id,
|
||||
author: message.author.id,
|
||||
content: message.content, // do not use cleanContent!
|
||||
|
@ -10,6 +10,7 @@ const Logger = require('leekslazylogger');
|
||||
const log = new Logger();
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
event: 'messageReactionAdd',
|
||||
@ -148,11 +149,10 @@ module.exports = {
|
||||
await c.send(ping + `${u} has created a new ticket`);
|
||||
|
||||
if (config.tickets.send_img) {
|
||||
const images = fs.readdirSync('user/images');
|
||||
const images = fs.readdirSync(join(__dirname, '../../user/images'));
|
||||
await c.send({
|
||||
files: [
|
||||
'user/images/' +
|
||||
images[Math.floor(Math.random() * images.length)]
|
||||
join(__dirname, '../../user/images', images[Math.floor(Math.random() * images.length)])
|
||||
]
|
||||
});
|
||||
}
|
||||
|
@ -9,6 +9,7 @@
|
||||
const Logger = require('leekslazylogger');
|
||||
const log = new Logger();
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
|
||||
module.exports = {
|
||||
event: 'messageUpdate',
|
||||
@ -36,11 +37,11 @@ module.exports = {
|
||||
let ticket = await Ticket.findOne({ where: { channel: n.channel.id } });
|
||||
if (!ticket) return;
|
||||
|
||||
let path = `user/transcripts/raw/${n.channel.id}.log`;
|
||||
let path = `../../user/transcripts/raw/${n.channel.id}.log`;
|
||||
let embeds = [];
|
||||
for (let embed in n.embeds) embeds.push({ ...n.embeds[embed] });
|
||||
|
||||
fs.appendFileSync(path, JSON.stringify({
|
||||
fs.appendFileSync(join(__dirname, path), JSON.stringify({
|
||||
id: n.id,
|
||||
author: n.author.id,
|
||||
content: n.content, // do not use cleanContent!
|
||||
|
22
src/index.js
22
src/index.js
@ -15,14 +15,14 @@ const version = Number(process.version.split('.')[0].replace('v', ''));
|
||||
if (!version === 12 || !version > 12) return console.log('Please upgrade to Node v12 or higher');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { join } = require('path');
|
||||
|
||||
let dev = fs.existsSync('user/dev.env') && fs.existsSync('user/dev.config.js');
|
||||
let dev = fs.existsSync(join(__dirname, '../user/dev.env')) && fs.existsSync(join(__dirname, '../user/dev.config.js'));
|
||||
|
||||
require('dotenv').config({ path: path.join('user/', dev ? 'dev.env' : '.env') });
|
||||
require('dotenv').config({ path: join(__dirname, '../user/', dev ? 'dev.env' : '.env') });
|
||||
|
||||
module.exports.config = dev ? 'dev.config.js' : 'config.js';
|
||||
const config = require(path.join('../user/', module.exports.config));
|
||||
const config = require(join(__dirname, '../user/', module.exports.config));
|
||||
|
||||
const Discord = require('discord.js');
|
||||
const client = new Discord.Client({
|
||||
@ -91,7 +91,7 @@ default:
|
||||
log.info('Using SQLite storage');
|
||||
sequelize = new Sequelize({
|
||||
dialect: 'sqlite',
|
||||
storage: 'user/storage.db',
|
||||
storage: join(__dirname, '../user/storage.db'),
|
||||
logging: log.debug
|
||||
});
|
||||
}
|
||||
@ -122,7 +122,7 @@ Setting.sync();
|
||||
/**
|
||||
* event loader
|
||||
*/
|
||||
const events = fs.readdirSync('src/events').filter(file => file.endsWith('.js'));
|
||||
const events = fs.readdirSync(join(__dirname, 'events')).filter(file => file.endsWith('.js'));
|
||||
for (const file of events) {
|
||||
const event = require(`./events/${file}`);
|
||||
client.events.set(event.event, event);
|
||||
@ -134,7 +134,7 @@ for (const file of events) {
|
||||
/**
|
||||
* command loader
|
||||
*/
|
||||
const commands = fs.readdirSync('src/commands').filter(file => file.endsWith('.js'));
|
||||
const commands = fs.readdirSync(join(__dirname, 'commands')).filter(file => file.endsWith('.js'));
|
||||
for (const file of commands) {
|
||||
const command = require(`./commands/${file}`);
|
||||
client.commands.set(command.name, command);
|
||||
@ -144,14 +144,14 @@ for (const file of commands) {
|
||||
log.info(`Loaded ${events.length} events and ${commands.length} commands`);
|
||||
|
||||
const one_day = 1000 * 60 * 60 * 24;
|
||||
const txt = 'user/transcripts/text';
|
||||
const txt = '../user/transcripts/text';
|
||||
const clean = () => {
|
||||
const files = fs.readdirSync(txt).filter(file => file.endsWith('.txt'));
|
||||
const files = fs.readdirSync(join(__dirname, txt)).filter(file => file.endsWith('.txt'));
|
||||
let total = 0;
|
||||
for (const file of files) {
|
||||
let diff = (new Date() - new Date(fs.statSync(`${txt}/${file}`).mtime));
|
||||
let diff = (new Date() - new Date(fs.statSync(join(__dirname, txt, file)).mtime));
|
||||
if (Math.floor(diff / one_day) > config.transcripts.text.keep_for) {
|
||||
fs.unlinkSync(`${txt}/${file}`);
|
||||
fs.unlinkSync(join(__dirname, txt, file));
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ const Logger = require('leekslazylogger');
|
||||
const log = new Logger();
|
||||
const lineReader = require('line-reader');
|
||||
const fs = require('fs');
|
||||
const { join } = require('path');
|
||||
const dtf = require('@eartharoid/dtf');
|
||||
const config = require('../../user/' + require('../').config);
|
||||
const fetch = require('node-fetch');
|
||||
@ -20,23 +21,23 @@ module.exports.add = (message) => {
|
||||
if (message.type !== 'DEFAULT') return;
|
||||
|
||||
if (config.transcripts.text.enabled) { // text transcripts
|
||||
let path = `user/transcripts/text/${message.channel.id}.txt`,
|
||||
let path = `../../user/transcripts/text/${message.channel.id}.txt`,
|
||||
time = dtf('HH:mm:ss n_D MMM YY', message.createdAt),
|
||||
msg = message.cleanContent;
|
||||
message.attachments.each(a => msg += '\n' + a.url);
|
||||
let string = `[${time}] [${message.author.tag}] :> ${msg}`;
|
||||
fs.appendFileSync(path, string + '\n');
|
||||
fs.appendFileSync(join(__dirname, path), string + '\n');
|
||||
}
|
||||
|
||||
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 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] });
|
||||
|
||||
// message
|
||||
fs.appendFileSync(raw, JSON.stringify({
|
||||
fs.appendFileSync(join(__dirname, raw), JSON.stringify({
|
||||
id: message.id,
|
||||
author: message.author.id,
|
||||
content: message.content, // do not use cleanContent!
|
||||
@ -46,8 +47,8 @@ module.exports.add = (message) => {
|
||||
}) + '\n');
|
||||
|
||||
// channel entities
|
||||
if (!fs.existsSync(json))
|
||||
fs.writeFileSync(json, JSON.stringify({
|
||||
if (!fs.existsSync(join(__dirname, json)))
|
||||
fs.writeFileSync(join(__dirname, json), JSON.stringify({
|
||||
entities: {
|
||||
users: {},
|
||||
channels: {},
|
||||
@ -55,7 +56,7 @@ module.exports.add = (message) => {
|
||||
}
|
||||
})); // create new
|
||||
|
||||
let data = JSON.parse(fs.readFileSync(json));
|
||||
let data = JSON.parse(fs.readFileSync(join(__dirname, json)));
|
||||
|
||||
// if (!data.entities.users[message.author.id])
|
||||
data.entities.users[message.author.id] = {
|
||||
@ -86,7 +87,7 @@ module.exports.add = (message) => {
|
||||
color: r.color === 0 ? 7506394 : r.color
|
||||
});
|
||||
|
||||
fs.writeFileSync(json, JSON.stringify(data));
|
||||
fs.writeFileSync(join(__dirname, json), JSON.stringify(data));
|
||||
|
||||
}
|
||||
};
|
||||
@ -100,12 +101,12 @@ module.exports.export = (Ticket, channel) => new Promise((resolve, reject) => {
|
||||
}
|
||||
});
|
||||
|
||||
let raw = `user/transcripts/raw/${channel.id}.log`,
|
||||
json = `user/transcripts/raw/entities/${channel.id}.json`;
|
||||
let raw = `../../user/transcripts/raw/${channel.id}.log`,
|
||||
json = `../../user/transcripts/raw/entities/${channel.id}.json`;
|
||||
|
||||
if (!config.transcripts.web.enabled || !fs.existsSync(raw) || !fs.existsSync(json)) return reject(false);
|
||||
if (!config.transcripts.web.enabled || !fs.existsSync(join(__dirname, raw)) || !fs.existsSync(join(__dirname, json))) return reject(false);
|
||||
|
||||
let data = JSON.parse(fs.readFileSync(json));
|
||||
let data = JSON.parse(fs.readFileSync(join(__dirname, json)));
|
||||
|
||||
data.ticket = {
|
||||
id: ticket.id,
|
||||
@ -143,8 +144,8 @@ module.exports.export = (Ticket, channel) => new Promise((resolve, reject) => {
|
||||
|
||||
log.success(`Uploaded ticket #${ticket.id} archive to server`);
|
||||
|
||||
fs.unlinkSync(raw);
|
||||
fs.unlinkSync(json);
|
||||
fs.unlinkSync(join(__dirname, raw));
|
||||
fs.unlinkSync(join(__dirname, json));
|
||||
|
||||
resolve(res.url);
|
||||
}).catch(e => {
|
||||
|
Loading…
Reference in New Issue
Block a user