soon ™️

This commit is contained in:
Isaac (eartharoid) 2020-08-23 15:35:24 +01:00
parent b50215404c
commit 6425e3930c
11 changed files with 64 additions and 14 deletions

6
package-lock.json generated
View File

@ -1452,9 +1452,9 @@
"integrity": "sha512-e6UVJ1fj8f2clpHy+KpXVWVxjzB3XYFGyKRJHDlT8Gy/75BT+9bYUacpHSCoXp7RTtyMSr4eBjZrp0nHyyQVbg=="
},
"leekslazylogger": {
"version": "2.0.0-alpha.6",
"resolved": "https://registry.npmjs.org/leekslazylogger/-/leekslazylogger-2.0.0-alpha.6.tgz",
"integrity": "sha512-DqOSsd8r9ks9ddCTxI34p41SGCX8+QvVij8/NDNe//yTHo2+JlipWYfnUR2UNMvXTXaIAtGYguTxhMaU4ibs4w==",
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/leekslazylogger/-/leekslazylogger-2.0.0.tgz",
"integrity": "sha512-VKaf8RSyJSp8hbMqZ9nInLs29Ix7FbfdteT4yd2jWSz+A7E4eGKqyEG0r/usiAiEd7u0aX4IJv/8I6BEwrGYhw==",
"requires": {
"@eartharoid/dtf": "^1.0.7",
"leeks.js": "0.0.9"

View File

@ -9,7 +9,7 @@
"boxen": "^4.2.0",
"discord.js": "^12.3.1",
"dotenv": "^8.2.0",
"leekslazylogger": "^2.0.0-alpha.6",
"leekslazylogger": "^2.0.0",
"line-reader": "^0.4.0",
"node-fetch": "^2.6.0",
"sequelize": "^6.3.4",

View File

@ -11,7 +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');
const archive = require('../modules/archive');
module.exports = {
name: 'close',

View File

@ -132,7 +132,7 @@ module.exports = {
await m.delete();
}, 15000);
// require('../utils/archive').create(client, c); // create files
// require('../modules/archive').create(client, c); // create files
let ping;
switch (config.tickets.ping) {

View File

@ -10,7 +10,7 @@ const { Collection, MessageEmbed } = require('discord.js');
const ChildLogger = require('leekslazylogger').ChildLogger;
const log = new ChildLogger();
const config = require('../../user/config');
const archive = require('../utils/archive');
const archive = require('../modules/archive');
module.exports = {
event: 'message',

View File

@ -134,7 +134,7 @@ module.exports = {
}
});
// require('../utils/archive').create(client, c); // create files
// require('../modules/archive').create(client, c); // create files
let ping;
switch (config.tickets.ping) {

View File

@ -17,8 +17,8 @@ const client = new Discord.Client({
client.events = new Discord.Collection();
client.commands = new Discord.Collection();
client.cooldowns = new Discord.Collection();
require('./utils/banner')(leeks); // big coloured text thing
const utils = require('./modules/utils');
require('./modules/banner')(leeks); // big coloured text thing
const config = require('../user/config');
const Logger = require('leekslazylogger');
@ -30,7 +30,7 @@ const log = new Logger({
});
log.multi(log); // required to allow other files to access the logger
require('./utils/updater')(); // check for updates
require('./modules/updater')(); // check for updates
/**
@ -103,6 +103,27 @@ 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 clean = () => {
const files = fs.readdirSync(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));
if (Math.floor(diff / one_day) > config.transcripts.text.keep_for) {
fs.unlinkSync(`${txt}/${file}`);
total++;
}
}
if (total > 0)
log.info(`Deleted ${total} old text ${utils.plural('transcript', total)}`);
};
if (config.transcripts.text.enabled) {
clean();
setInterval(clean, one_day);
}
process.on('unhandledRejection', error => {
log.warn('An error was not caught');
log.warn(`Uncaught ${error.name}: ${error.message}`);

View File

@ -68,13 +68,23 @@ module.exports.add = (client, message) => {
};
}
message.mentions.channels.each(c => data.entities.channels[c.id] = {
// mentions.users
message.mentions.members.each(m => data.entities.users[m.id] = { // for mentions
avatar: m.user.avatarURL(),
username: m.user.username,
discriminator: m.user.discriminator,
displayName: m.user.displayName,
color: m.displayColor,
badge: m.user.bot ? 'bot' : null
});
message.mentions.channels.each(c => data.entities.channels[c.id] = { // for mentions only
name: c.name
});
message.mentions.roles.each(r => data.entities.roles[r.id] = {
message.mentions.roles.each(r => data.entities.roles[r.id] = { // for mentions only
name: r.name,
color: r.color
color: r.color === 0 ? 7506394 : r.color
});
fs.writeFileSync(json, JSON.stringify(data));
@ -106,6 +116,7 @@ module.exports.export = (client, channel) => new Promise((resolve, reject) => {
}, () => {
// fs.writeFileSync('user/data.json', JSON.stringify(data)); // FOR TESTING
// post(data).then()
// delete raw .json and .log
resolve(config.transcripts.web.server); // json.url
});
});

18
src/modules/utils.js Normal file
View File

@ -0,0 +1,18 @@
/**
*
* @name DiscordTickets
* @author eartharoid <contact@eartharoid.me>
* @license GNU-GPLv3
*
*/
module.exports = {
/**
* @description Appends 's' to a word if plural number
* @param {string} word - singular version of word
* @param {number} num - integer
*/
plural(word, num) {
return num !== 1 ? word + 's' : word;
}
};