2022-11-27 02:35:28 -05:00
|
|
|
const moment = require('moment-timezone')
|
2022-11-09 07:04:14 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
function inject (bot, _dcclient, config, rl) {
|
2022-11-20 02:29:11 -05:00
|
|
|
// readline > fix on log
|
2022-11-27 02:35:28 -05:00
|
|
|
function log (...args) {
|
|
|
|
rl.output.write('\x1b[2K\r')
|
|
|
|
console.log(args.toString())
|
|
|
|
rl._refreshLine()
|
2022-11-20 02:29:11 -05:00
|
|
|
};
|
2022-11-09 07:04:14 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
const chatMessage = require('prismarine-chat')(bot.version)
|
2022-11-13 01:52:37 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
function prefix (prefix, _message) {
|
2023-03-14 05:12:37 -04:00
|
|
|
const message = `[${moment().format('DD/MM/YY HH:mm:ss')} ${prefix}§r] [${bot.server.host}] `
|
2022-11-27 02:35:28 -05:00
|
|
|
const component = chatMessage.MessageBuilder.fromString(message).toJSON()
|
|
|
|
return chatMessage.fromNotch(component).toAnsi() + _message
|
2022-11-13 01:52:37 -05:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.console = {}
|
|
|
|
bot.console.host = 'all'
|
|
|
|
bot.console.log = function (message) {
|
|
|
|
log(prefix('&6LOG', message))
|
|
|
|
}
|
|
|
|
bot.console.info = function (message) {
|
|
|
|
log(prefix('&aINFO', message))
|
|
|
|
}
|
|
|
|
bot.console.error = function (error) {
|
|
|
|
log(prefix('&cERROR', typeof error === 'string' ? error : error.stack))
|
|
|
|
}
|
2022-11-13 01:52:37 -05:00
|
|
|
|
2022-12-06 07:04:36 -05:00
|
|
|
// previous message is op feature to have in console :)
|
|
|
|
let previousMessage = ''
|
2022-12-12 03:06:50 -05:00
|
|
|
bot.on('message', (message) => {
|
2022-12-03 07:53:47 -05:00
|
|
|
if (!bot.options.logging) return
|
2022-12-06 07:04:36 -05:00
|
|
|
if (previousMessage === message.toString()) return
|
|
|
|
previousMessage = message.toString()
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.console.log(message.toAnsi())
|
|
|
|
})
|
2022-11-20 00:41:35 -05:00
|
|
|
|
2022-11-29 08:01:37 -05:00
|
|
|
if (!config.console) return
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
function handleLine (line) {
|
2022-11-26 06:39:48 -05:00
|
|
|
try {
|
|
|
|
if (line.toLowerCase() === '' ||
|
2022-11-27 02:35:28 -05:00
|
|
|
line.toLowerCase().startsWith(' ')) return
|
2022-11-14 06:53:52 -05:00
|
|
|
|
2022-11-26 06:39:48 -05:00
|
|
|
if (line.startsWith('.csvr ')) {
|
2022-11-27 02:35:28 -05:00
|
|
|
const host = line.substring(6)
|
2023-01-23 07:19:49 -05:00
|
|
|
for (const eachBot of bot.getBots()) eachBot.console.host = host
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.console.info(`Host set to: ${host}`)
|
|
|
|
return
|
2022-11-26 06:39:48 -05:00
|
|
|
}
|
2022-11-20 01:00:00 -05:00
|
|
|
|
2023-01-19 05:13:25 -05:00
|
|
|
if (bot.server.host !== bot.console.host && bot.console.host !== 'all') return
|
2022-11-27 02:35:28 -05:00
|
|
|
if (line === '.kill') process.exit()
|
2022-11-14 05:45:49 -05:00
|
|
|
|
2022-11-26 06:39:48 -05:00
|
|
|
if (line.startsWith('.')) {
|
|
|
|
return bot.command_handler.run(
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.username,
|
2023-03-15 04:06:49 -04:00
|
|
|
config.prefixes[0] + line.substring(1),
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.uuid,
|
|
|
|
null,
|
|
|
|
'h',
|
|
|
|
'o'
|
|
|
|
)
|
2022-11-09 07:04:14 -05:00
|
|
|
}
|
2022-11-26 06:39:48 -05:00
|
|
|
bot.tellraw('@a', [
|
|
|
|
{
|
|
|
|
text: '[',
|
2022-11-27 02:35:28 -05:00
|
|
|
color: 'dark_gray'
|
2022-11-26 06:39:48 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: `${bot.username} Console`,
|
2022-11-27 02:35:28 -05:00
|
|
|
color: 'gray'
|
2022-11-26 06:39:48 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: '] ',
|
2022-11-27 02:35:28 -05:00
|
|
|
color: 'dark_gray'
|
2022-11-26 06:39:48 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: 'chayapak ',
|
2022-11-27 02:35:28 -05:00
|
|
|
color: 'green'
|
2022-11-26 06:39:48 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
text: '\u203a ',
|
2022-11-27 02:35:28 -05:00
|
|
|
color: 'dark_gray'
|
2022-11-26 06:39:48 -05:00
|
|
|
},
|
2022-11-27 02:35:28 -05:00
|
|
|
chatMessage.MessageBuilder.fromString('&7' + line)
|
|
|
|
])
|
2022-11-26 06:39:48 -05:00
|
|
|
} catch (e) {
|
2022-11-27 02:35:28 -05:00
|
|
|
bot.console.error(e)
|
2022-11-26 06:39:48 -05:00
|
|
|
}
|
2022-11-26 06:44:00 -05:00
|
|
|
}
|
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
rl.on('line', handleLine)
|
2022-11-26 06:44:00 -05:00
|
|
|
|
2022-11-30 04:45:20 -05:00
|
|
|
bot.on('end', () => {
|
2022-11-27 02:35:28 -05:00
|
|
|
rl.off('line', handleLine)
|
|
|
|
})
|
2022-11-26 06:39:48 -05:00
|
|
|
}
|
2022-11-09 07:04:14 -05:00
|
|
|
|
2022-11-27 02:35:28 -05:00
|
|
|
module.exports = { inject }
|