Files
NitoriBot/src/modules/console.js
T

52 lines
2.4 KiB
JavaScript
Raw Normal View History

2024-07-20 20:27:17 -04:00
const CommandSource = require('../util/command_source');
2024-07-07 15:44:16 -04:00
function CommandConsole (bot, options, config) {
2024-07-20 20:27:17 -04:00
const ChatMessage = require('prismarine-chat')(options.version);
2024-07-07 15:44:16 -04:00
bot.console = {
readline: null,
consoleServer: 'all',
useReadlineInterface (rl) {
this.readline = rl
rl.on('line', line => {
2024-07-20 20:27:17 -04:00
if (bot.options.serverName !== this.consoleServer && this.consoleServer !== 'all') return
if (line.startsWith('c.')) {
2024-07-07 15:44:16 -04:00
return bot.commandManager.executeString(bot.console.source, line.substring(2))
} if (line.startsWith("")) {
return bot.commandManager.executeString(bot.console.source, `echo ${line.substring(0)}`)
}
})
rl.on('close', () => {
this.readline = null
})
const originalConsole = console
this.log = (...args) => {
rl.output.write('\x1b[2K\r')
originalConsole.log(args.toString())
rl._refreshLine()
}
}
}
2024-07-20 20:27:17 -04:00
bot.console.logs = function (message) {
// console.log(`[${new Date().toLocaleString("en-US", { timeZone:"America/CHICAGO" })} logs] [${options.serverName}] ${message}`)
console.log(ChatMessage.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §6logs§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
2024-07-07 15:44:16 -04:00
}
2024-07-20 20:27:17 -04:00
bot.console.source = new CommandSource(bot.options.username, { console: true, discord: false });
2024-07-07 15:44:16 -04:00
bot.console.source.sendFeedback = message => {
2024-07-20 20:27:17 -04:00
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt")
if (!options.logging) return
bot.console.logs(ansi);
2024-07-07 15:44:16 -04:00
}
bot.on('message', message => {
2024-07-20 20:27:17 -04:00
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt")
const string = bot.getMessageAsPrismarine(message)?.toString(bot.registry.language).replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt")
if (!options.logging) return
2024-07-07 15:44:16 -04:00
bot.console.logs(`${ansi}`)
2024-07-20 20:27:17 -04:00
bot.console.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ${string}`)
2024-07-07 15:44:16 -04:00
})
}
module.exports = CommandConsole;