2024-07-20 20:27:17 -04:00
|
|
|
const CommandSource = require('../util/command_source');
|
2024-09-13 08:23:42 -04:00
|
|
|
const prismarineChat = require('prismarine-chat')('1.20.2');
|
2024-11-22 12:49:22 -05:00
|
|
|
|
2025-01-15 11:32:27 -05:00
|
|
|
function inject (context) {
|
2024-11-22 12:49:22 -05:00
|
|
|
const bot = context.bot;
|
|
|
|
|
const config = context.config;
|
|
|
|
|
const options = context.options;
|
2024-10-30 19:07:14 -04:00
|
|
|
let ratelimit = 0;
|
2024-07-07 15:44:16 -04:00
|
|
|
bot.console = {
|
|
|
|
|
readline: null,
|
2024-09-13 08:23:42 -04:00
|
|
|
server: 'all',
|
|
|
|
|
readlineInterface (rl) {
|
2024-07-07 15:44:16 -04:00
|
|
|
this.readline = rl
|
2024-09-13 08:23:42 -04:00
|
|
|
rl.on('line', (args) => {
|
|
|
|
|
if (bot.options.serverName !== this.server && this.server !== 'all') return
|
|
|
|
|
if (args.startsWith(config.console.prefix)) {
|
|
|
|
|
return bot.commandManager.executeString(bot.console.source, args.substring(config.console.prefix.length))
|
|
|
|
|
} else if (args.startsWith("")) {
|
|
|
|
|
return bot.commandManager.executeString(bot.console.source, `console say ${args.substring(0)}`);
|
2024-07-07 15:44:16 -04:00
|
|
|
}
|
2024-09-13 08:23:42 -04:00
|
|
|
rl.on('close', () => {
|
|
|
|
|
this.readline = null;
|
|
|
|
|
})
|
2024-07-07 15:44:16 -04:00
|
|
|
})
|
2024-09-13 08:23:42 -04:00
|
|
|
},
|
2024-10-24 10:48:45 -04:00
|
|
|
source: new CommandSource(bot._client.username, { console: true, discord: false }),
|
2024-09-13 08:23:42 -04:00
|
|
|
refreshLine (...args) {
|
|
|
|
|
this.readline.output.write("\x1b[2K\r");
|
|
|
|
|
console.log.apply(console, arguments);
|
|
|
|
|
this.readline._refreshLine();
|
|
|
|
|
},
|
|
|
|
|
log (message) {
|
|
|
|
|
this.refreshLine(bot.getMessageAsPrismarine(`§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)
|
|
|
|
|
},
|
|
|
|
|
warn (error) {
|
|
|
|
|
this.refreshLine(prismarineChat.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §ewarn§8] §8[${options.serverName}§8] `)?.toAnsi() + error)
|
|
|
|
|
},
|
|
|
|
|
error (error) {
|
|
|
|
|
this.refreshLine(bot.getMessageAsPrismarine(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §4error§8] §8[${options.serverName}§8] `)?.toAnsi() + error)
|
|
|
|
|
},
|
|
|
|
|
info (message) {
|
2024-09-19 11:30:06 -04:00
|
|
|
this.refreshLine(prismarineChat.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §2info§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
2024-09-13 08:23:42 -04:00
|
|
|
},
|
2025-01-15 11:32:27 -05:00
|
|
|
debug (message) {
|
|
|
|
|
console.log(prismarineChat.fromNotch(`§8[§1${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} §3${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} §6debug§8] §8[${options.serverName}§8] `)?.toAnsi() + message)
|
2024-08-30 11:56:58 -04:00
|
|
|
}
|
|
|
|
|
}
|
2024-10-30 19:07:14 -04:00
|
|
|
setInterval(() => ratelimit = 0, 1000 * 2);
|
|
|
|
|
|
2025-01-15 11:32:27 -05:00
|
|
|
bot.on('message', (message) => {
|
2024-10-30 19:07:14 -04:00
|
|
|
if (!options.logging) return;
|
2025-02-25 19:53:19 +00:00
|
|
|
|
|
|
|
|
if (ratelimit > 10) return
|
2024-10-30 19:07:14 -04:00
|
|
|
bot.console.log(bot.getMessageAsPrismarine(message)?.toAnsi());
|
|
|
|
|
bot.console.fileLogger(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ${bot.getMessageAsPrismarine(message)?.toString()}`);
|
|
|
|
|
ratelimit++
|
2025-01-15 11:32:27 -05:00
|
|
|
});
|
2024-12-06 11:04:23 -05:00
|
|
|
|
2024-07-07 15:44:16 -04:00
|
|
|
}
|
2025-01-15 11:32:27 -05:00
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
|
data: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
name: "console",
|
|
|
|
|
type: "logging"
|
|
|
|
|
},
|
|
|
|
|
inject
|
|
|
|
|
};
|