Files
NitoriBot/src/modules/console.js
T

94 lines
4.3 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-09-07 21:13:24 -04:00
let ratelimit = 0;
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
2024-07-25 22:57:29 -04:00
if (line.startsWith(config.console.prefix)) {
2024-08-30 11:56:58 -04:00
return bot.commandManager.executeString(bot.console.source, line.substring(config.console.prefix.length))
2024-07-07 15:44:16 -04:00
} if (line.startsWith("")) {
2024-08-30 11:56:58 -04:00
return bot.commandManager.executeString(bot.console.source, `console say ${line.substring(0)}`)
2024-07-07 15:44:16 -04:00
}
})
rl.on('close', () => {
this.readline = null
})
2024-08-09 22:08:42 -04:00
log = function (...args) {
2024-08-04 22:59:52 -04:00
rl.output.write("\x1b[2K\r");
console.log(args.toString());
rl._refreshLine();
2024-08-30 12:23:48 -04:00
}
}
2024-07-07 15:44:16 -04:00
}
2024-07-20 20:27:17 -04:00
bot.console.logs = function (message) {
2024-08-04 22:59:52 -04:00
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)
}
bot.console.info = function (message) {
log(ChatMessage.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)
}
bot.console.warn = function (message) {
console.log(ChatMessage.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() + 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
2024-08-30 12:23:48 -04:00
bot.console.logs(ChatMessage.fromNotch('§8[§6Command§8] ')?.toAnsi() + ansi);
2024-08-04 22:59:52 -04:00
}
bot.console.error = function (message) {
console.log(ChatMessage.fromNotch(`§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() + message)
2024-07-07 15:44:16 -04:00
}
2024-08-30 11:56:58 -04:00
bot.console.customChat = {
enabled: false,
chat (message) {
const prefix = {
translate: '[%s] %s \u203a %s',
color:'dark_gray',
with: [
{
text: 'FNFBoyfriendBot Console',
color:'#00FFFF'
},
{
selector: `${bot.username}`, color:'#00FFFF',
clickEvent: { action: 'suggest_command', value: '~help' }
},
{
text: '',
extra: [`${message}`],
color:'white'
},
],
hoverEvent: { action:"show_text", value: 'FNF Sky is a fangirl but a simp for boyfriend confirmed??'},
clickEvent: 'https://doin-your.mom' ?
{ action: 'open_url', value: 'https://doin-your.mom' } : undefined,
}
bot.tellraw('@a', prefix)
}
}
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-09-07 21:13:24 -04:00
//ratelimit++
setInterval(() => {
// ratelimit--
ratelimit = 0
}, 1000)
if (ratelimit > 300) {
// options.logging = false
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-09-07 21:13:24 -04:00
ratelimit++
2024-07-07 15:44:16 -04:00
})
}
module.exports = CommandConsole;