diff --git a/events/message.js b/events/message.js index acc67ae..85099be 100644 --- a/events/message.js +++ b/events/message.js @@ -56,7 +56,6 @@ module.exports = async (client, message) => { } } - console.log(settings.systemNotice) if (level < client.levelCache[cmd.conf.permLevel]) { if (settings.systemNotice === true) { return message.channel.send('You don\'t have permission to run this command!') diff --git a/file.log b/file.log new file mode 100644 index 0000000..5cdbdca --- /dev/null +++ b/file.log @@ -0,0 +1,4 @@ +2020-04-05T02:10:36 | info | index.js | Loading 3 commands. +2020-04-05T02:10:36 | info | index.js | Loading 7 events. +2020-04-05T02:10:36 | info | mongoose.js | Connected to the database. +2020-04-05T02:10:41 | ready | ready.js | Connected to Discord as WoomyDev#4547 diff --git a/index.js b/index.js index 9287de0..39d58a3 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,13 @@ const Discord = require('discord.js') const client = new Discord.Client({ disabledEvents: ['TYPING_START'] }) client.logger = require('tracer').colorConsole({ + transport: function (data) { + console.log(data.output) + fs.appendFile('./file.log', data.rawoutput + '\n', err => { + if (err) throw err + }) + }, + format: [ '{{timestamp}} | {{title}} | {{file}} | {{message}}', { diff --git a/util/functions.js b/util/functions.js index 05c0dc4..af64cd5 100644 --- a/util/functions.js +++ b/util/functions.js @@ -7,7 +7,6 @@ module.exports = client => { let permlvl = 0 const permOrder = client.config.permLevels.slice(0).sort((p, c) => p.level < c.level ? 1 : -1) - console.log(permOrder) while (permOrder.length) { const currentLevel = permOrder.shift() @@ -32,27 +31,23 @@ module.exports = client => { // Update settings client.updateGuild = async (guild, settings) => { - const data = await client.getGuild(guild) + let data = await client.getGuild(guild) + + if (typeof data !== 'object') data = {} for (const key in settings) { - // eslint-disable-next-line no-prototype-builtins - if (settings.hasOwnProperty(key)) { - if (data[key] !== settings[key]) { - data[key] = settings[key] - } else { - return - } - } - client.logger.debug(`Updated settings for ${data.guildName}: ${Object.keys(settings)}`) + if (data[key] !== settings[key]) { + data[key] = settings[key] + } else return } + + return data.updateOne(settings) } // Create new entry for new guild client.createGuild = async (settings) => { const merged = Object.assign({ _id: mongoose.Types.ObjectId() }, settings) const newGuild = await new Guild(merged) - return newGuild.save().then(g => { - client.logger.debug(`Created settings for guild ${g.guildName}`) - }) + return newGuild.save() } // Delete guild data @@ -138,6 +133,7 @@ module.exports = client => { } } + // Embed colour function client.embedColour = function (guild) { if (!guild || guild.member(client.user).displayHexColor === '#000000') { return ['#ff9d68', '#ff97cb', '#d789ff', '#74FFFF'].random() @@ -146,7 +142,7 @@ module.exports = client => { } } - // Returns a random number between min and max + // Returns a random int between min and max client.intBetween = function (min, max) { return Math.floor((Math.random() * (max - min)) + min) } @@ -208,8 +204,7 @@ module.exports = client => { } client.findRole = function (guild, search) { - var role - role = guild.roles.cache.find(r => r.name.toLowerCase() === search.toLowerCase()) + var role = guild.roles.cache.find(r => r.name.toLowerCase() === search.toLowerCase()) if (!role) { role = guild.roles.cache.get(search.toLowerCase()) }