add previous message to console and commands plugin

This commit is contained in:
ChomeNS 2022-12-06 19:04:36 +07:00
parent 69fa38a808
commit 5c27a494c6
2 changed files with 12 additions and 0 deletions

View file

@ -61,9 +61,17 @@ function inject (bot, dcclient, config) {
bot.command_handler.main(prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector)
}
}
let previousMessage = { username: '', message: '' }
bot.on('message', async (_username, _message, _sender) => {
// try catch cuz TypeError: Cannot read properties of undefined (reading 'replace')
try {
if (
previousMessage.username === _username &&
previousMessage.message === _message
) return
previousMessage = { username: _username, message: _message }
const usernameraw = _username.replace(/§.?/g, '')
const sender = _sender !== '00000000-0000-0000-0000-000000000000' ? _sender : bot.playersAddedPlayers[usernameraw]
let username

View file

@ -31,8 +31,12 @@ function inject (bot, _dcclient, config, rl) {
log(prefix('&cERROR', typeof error === 'string' ? error : error.stack))
}
// previous message is op feature to have in console :)
let previousMessage = ''
bot.on('parsed_chat', (message) => {
if (!bot.options.logging) return
if (previousMessage === message.toString()) return
previousMessage = message.toString()
bot.console.log(message.toAnsi())
})