Skip to content

Commit

Permalink
Reduce amount of unnecessary logs
Browse files Browse the repository at this point in the history
  • Loading branch information
xsduan committed Feb 11, 2018
1 parent a582a16 commit e04a6ef
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,18 @@ function logMessage (status, message = null) {
console.log(log)
}

/**
* Convert a message object into a string in the form of guildname: message{0, 100}
*
* @param {Message} message
*/
function messageSummary (message) {
return message.guild.name + ': ' + message.content.substr(0, 100)
}

/**
* Acts for a response to a message.
* @param {Message} message Mssage to parse for responses
* @param {Message} message Message to parse for responses
*/
function parse (message) {
var x2iPromise = x2iExec(message)
Expand Down Expand Up @@ -79,9 +88,7 @@ function command (message) {
break
}

logMessage('processed:command/' + command)
} else {
logMessage('ignored:command')
logMessage('processed:command/' + command, messageSummary(message))
}

return promise
Expand All @@ -104,6 +111,8 @@ function ping (message) {
* @returns {(Promise<(Message|Array<Message>)>)|null} Whatever message needs handling
*/
function x2iExec (message) {
var promise = null

var results = x2i.grab(message.content)
if (results !== undefined && results.length !== 0) {
var response = new Discord.RichEmbed()
Expand All @@ -123,12 +132,11 @@ function x2iExec (message) {

response.setDescription(results)

logMessage('processed:x2i/' + logCode)
return embed.send(message.channel, response)
} else {
logMessage('ignored:x2i')
return null
logMessage('processed:x2i/' + logCode, messageSummary(message))
promise = embed.send(message.channel, response)
}

return promise
}

/*
Expand All @@ -145,21 +153,13 @@ bot.on('ready', () => {
.catch(err => console.log('Game couldn\'t be set. ' + err))
}
}).on('message', message => {
logMessage('-start ' + message.createdTimestamp + '-')
if (!message.author.bot) {
parse(message)
} else {
logMessage('ignored:bot')
}

logMessage('-processed ' + message.createdTimestamp + '-')

// separate message return statuses in logs
console.log()
})

if (!cfg.has('token')) {
console.error('Couldn\'t find a token to connect to the token.')
console.error('Couldn\'t find a token to connect with.')
}

bot.login(cfg.get('token'))

0 comments on commit e04a6ef

Please sign in to comment.