From bfbe6dab8127d2b7f3912dc65b760f2541928ae8 Mon Sep 17 00:00:00 2001 From: Eartharoid Date: Mon, 6 May 2019 17:18:43 +0100 Subject: [PATCH] update --- commands/add.js | 2 +- commands/close.js | 4 +- commands/example-command.js.example | 2 +- commands/help.js | 2 +- commands/new.js | 2 +- commands/ping.js | 2 +- commands/remove.js | 2 +- handlers/logger.js | 118 ---------------------------- index.js | 12 +-- package.json | 3 +- 10 files changed, 16 insertions(+), 133 deletions(-) delete mode 100644 handlers/logger.js diff --git a/commands/add.js b/commands/add.js index b14698a..48c73b0 100644 --- a/commands/add.js +++ b/commands/add.js @@ -1,6 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); module.exports = { name: 'add', description: 'Add a member to a ticket channel', diff --git a/commands/close.js b/commands/close.js index 24a58fe..e6e0b2e 100644 --- a/commands/close.js +++ b/commands/close.js @@ -1,6 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); module.exports = { name: 'close', description: 'Close a ticket', @@ -43,7 +43,7 @@ module.exports = { log.info(`${message.author.tag} closed a ticket (#${message.channel.name})`) } catch(error) { - log.error(leeks.colours.red(error)); + log.error(log.colour.red(error)); } } diff --git a/commands/example-command.js.example b/commands/example-command.js.example index e87f037..11fc162 100644 --- a/commands/example-command.js.example +++ b/commands/example-command.js.example @@ -1,6 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); module.exports = { name: 'example-command', description: 'An example command', diff --git a/commands/help.js b/commands/help.js index f726c99..52f0ccb 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,7 +1,7 @@ const Discord = require('discord.js'); const { version } = require('../package.json'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); module.exports = { name: 'help', description: 'Displays help menu', diff --git a/commands/new.js b/commands/new.js index 6ebb73b..d4a278a 100644 --- a/commands/new.js +++ b/commands/new.js @@ -1,6 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); // const randomString = require('random-string'); module.exports = { name: 'new', diff --git a/commands/ping.js b/commands/ping.js index bb1470c..33b27f0 100644 --- a/commands/ping.js +++ b/commands/ping.js @@ -1,6 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); module.exports = { name: 'ping', description: 'Calculate latency', diff --git a/commands/remove.js b/commands/remove.js index 6040790..2cede68 100644 --- a/commands/remove.js +++ b/commands/remove.js @@ -1,6 +1,6 @@ const Discord = require('discord.js'); const config = require('../config.json'); -const log = require(`../handlers/logger.js`); +const log = require(`leekslazylogger`); module.exports = { name: 'remove', description: 'Remove a member from a ticket', diff --git a/handlers/logger.js b/handlers/logger.js deleted file mode 100644 index 960cf38..0000000 --- a/handlers/logger.js +++ /dev/null @@ -1,118 +0,0 @@ -const fs = require('fs'); -const leeks = require('leeks.js'); // ultra light weight alternative to chalk -const now = new Date(); -let date = now.getDate(); - -function time() { - const n = new Date(); - const h = n.getHours(); - const m = n.getMinutes(); - const s = n.getSeconds(); - return `${h}:${('0' + m).slice(-2)}:${('0' + s).slice(-2)}`; -} -let d = ('0' + date).slice(-2); -if (!fs.existsSync('./logs')) { - fs.mkdirSync(`./logs`); - console.log(`[INFO | ${time()}] No logs directory found, creating one for you.`); -} -const files = fs.readdirSync('./logs/').filter(file => file.endsWith('.log')); -// let path = `./logs/${d}-${time().replace(':', '-').replace(':', '-')}.log`; -let path = `./logs/${d}-${('0' + now.getMonth()).slice(-2)}-${now.getFullYear()}.${time().replace(':', '-').replace(':', '-')}.log`; -// const log = require(path); - - -function init(x) { - // console.log(leeks.colours.cyan(`[INFO | ${time()}] Setting up...`)); - console.log(`[INFO | ${time()}] Initialising logger`); - - console.log(`[INFO | ${time()}] Cleaning up...`); - for (const file of files) { - // if(!file.startsWith(`${d}-`)) { - if(parseInt(file.substr(0,2)) < parseInt(d-7) || parseInt(file.substr(0,2)) > parseInt(d)) { - fs.unlinkSync(`./logs/${file}`) - console.log(`[INFO | ${time()}] Deleting './logs/${file}'`); - }; - }; - try { - if(x){ - fs.appendFileSync(path, `${x} | Log File (${d}/${('0' + now.getMonth()).slice(-2)}/${now.getFullYear()}) -->\n`, function (error) { - if (error) throw error; - }); - } else { - fs.appendFileSync(path, `Log File (${d}/${('0' + now.getMonth()).slice(-2)}/${now.getFullYear()}) -->\n`, function (error) { - if (error) throw error; - }); - } - - console.log(`[INFO | ${time()}] Creating new log file (${path})`); - } catch(error) { - console.error(leeks.colours.red(error)); - } -}; - -exports.init = x => { - init(x) -}; - -exports.basic = (m, c) => { - if(c){console.log(leeks.colours[c](`[${time()}] ${m}`))} else {console.log(`[${time()}] ${m}`)}; - - fs.writeFileSync(path, `[${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; - -exports.console = (m, c) => { - if(c){console.log(leeks.colours[c](`[${time()}] ${m}`))} else {console.log(`[INFO | ${time()}] ${m}`)}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; - -exports.info = (m, c) => { - if(c){console.info(leeks.colours[c](`[INFO | ${time()}] ${m}`))} else {console.info(leeks.colours.cyan(`[INFO | ${time()}] ${m}`))}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; -exports.success = (m, c) => { - if(c){console.info(leeks.colours[c](`[INFO | ${time()}] ${m}`))} else {console.info(leeks.colours.green(`[INFO | ${time()}] ${m}`))}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[INFO | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; -exports.debug = (m, c) => { - if(c){console.info(leeks.colours[c](`[DEBUG | ${time()}] ${m}`))} else {console.info(leeks.colours.blueBright(`[DEBUG | ${time()}] ${m}`))}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[DEBUG | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; -exports.warn = (m, c) => { - if(c){console.warn(leeks.colours[c](`[WARN | ${time()}] ${m}`))} else {console.warn(leeks.colours.yellowBright(`[WARN | ${time()}] ${m}`))}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[WARN | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; -exports.error = (m, c) => { - if(c){console.error(leeks.colours[c](`[ERROR | ${time()}] ${m}`))} else {console.error(leeks.colours.red(`[ERROR | ${time()}] ${m}`))}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[ERROR | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; -exports.custom = (t, m, c) => { - if(c){console.log(leeks.colours[c](`[${t} | ${time()}] ${m}`))} else {console.log(`[${t} | ${time()}] ${m}`)}; - let data = fs.readFileSync(path); - fs.writeFileSync(path, data + `[${t} | ${time()}] ${m}\n`, function (error) { - if (error) throw error; - }); -}; -module.exports.colors = leeks.colors; -module.exports.colours = leeks.colours; -module.exports.color = leeks.colors; -module.exports.colour = leeks.colours; diff --git a/index.js b/index.js index 447f75a..fa820d5 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ const fs = require('fs'); const Discord = require('discord.js'); const leeks = require('leeks.js'); -const log = require(`./handlers/logger.js`); +const log = require(`leekslazylogger`); const config = require('./config.json'); const { version, homepage } = require('./package.json'); const client = new Discord.Client(); @@ -57,7 +57,7 @@ const cooldowns = new Discord.Collection(); const now = Date.now(); const commands = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); -console.log(leeks.colours.magentaBright(` +console.log(log.colour.magentaBright(` ######## #### ###### ###### ####### ######## ######## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## @@ -75,10 +75,10 @@ console.log(leeks.colours.magentaBright(` ## #### ###### ## ## ######## ## ###### `)); // banner appears in console -console.log(leeks.colours.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`))); -console.log(leeks.colours.yellow(leeks.styles.bold(homepage))); +console.log(log.colour.yellow(leeks.styles.bold(`DiscordTickets v${version} - Made By Eartharoid`))); +console.log(log.colour.yellow(leeks.styles.bold(homepage))); console.log('\n\n'); -console.log(leeks.colours.bgGrey(leeks.colours.grey(`\n\n==========================================================================\n\n`))) +console.log(log.colour.bgGrey(log.colour.grey(`\n\n==========================================================================\n\n`))) console.log('\n\n'); log.init('DiscordTickets (bot created by Eartharoid)') // all log.* functions are logged to ./log/file.log from here onwards @@ -270,7 +270,7 @@ process.on('unhandledRejection', error => { log.error(`Uncaught error: \n${error.stack}`); }); process.on('beforeExit', (code) => { - log.basic(leeks.colours.yellowBright(`Disconected from Discord API`)); + log.basic(log.colour.yellowBright(`Disconected from Discord API`)); log.basic(`Exiting (${code})`); }); diff --git a/package.json b/package.json index b7292d7..fe12a24 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "index.js", "dependencies": { "discord.js": "^11.4.2", - "leeks.js": "^0.0.1" + "leeks.js": "^0.0.1", + "leekslazylogger": "0.0.4" }, "devDependencies": {}, "scripts": {