console rewrite and chat packet types rewrite. v6.0.1 build: 990

This commit is contained in:
Parker2991
2024-09-13 08:23:42 -04:00
parent 6eeb079ced
commit b295cc2d0f
16 changed files with 436 additions and 145 deletions
+25 -13
View File
@@ -4,8 +4,7 @@ const ChipmunkModChatParser = require('../util/ChatParsers/ChipmunkMod');
const CreayunChatParser = require('../util/ChatParsers/Creayun');
const sayConsoleChatParser = require('../util/ChatParsers/sayConsole');
const VanillaChatParser = require("../util/ChatParsers/VanillaChat");
const nbt = require('prismarine-nbt');
const yfdCustomChatParser = require('../util/ChatParsers/yfdCustomChat')
const yfdCustomChatParser = require('../util/ChatParsers/yfdCustomChat');
function tryParse (json) {
try {
return JSON.parse(json)
@@ -32,23 +31,36 @@ function chat (bot, options, config) {
type: packet.type,
sender
})
const translateMessage = bot.getMessageAsPrismarine(message)?.toMotd()
const translateUsername = bot.getMessageAsPrismarine(sender)?.toMotd()
if (packet.type === 1) bot.emit('message', bot.getMessageAsPrismarine({translate:"chat.type.emote", with:[`${translateUsername}`,`${translateMessage}`]})?.toMotd())
if (packet.type === 2) bot.emit('message', bot.getMessageAsPrismarine({"translate":"commands.message.display.incoming","with":[`${translateUsername}`,`${translateMessage}`],"color":"gray","italic":true})?.toMotd())
if (packet.type === 3) bot.emit('message', bot.getMessageAsPrismarine({"translate":"commands.message.display.outgoing","with":[`${translateUsername}`,`${translateMessage}`],"color":"gray","italic":true})?.toMotd())
if (packet.type === 4) bot.emit('message', message);
if (packet.type === 5) bot.emit('message', bot.getMessageAsPrismarine({translate:"chat.type.announcement",color:'white', with:[`${translateUsername}`,`${translateMessage}`]})?.toMotd())
switch (packet.type) {
case 1:
bot.emit('message', { translate: "chat.type.emote", with: [ sender, message ]})
break
case 2:
bot.emit('message', { translate: "commands.message.display.incoming", with: [ sender, message], color: "gray", italic: true })
break
case 3:
bot.emit('message', { translate: "commands.message.display.outgoing", with: [ sender, message ], color: "gray", italic: true })
break
case 4:
bot.emit('message', message);
break
case 5:
bot.emit('message', { translate: 'chat.type.announcement', with: [ sender, message ]})
break
}
tryParsingMessage(message, { senderName: sender, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine })
})
bot.on('packet.player_chat', (packet, data) => {
const unsigned = tryParse(packet.unsignedChatContent)
// const unsigned = JSON.parse(loadPrismarineChat.processNbtMessage(nbt.comp(nbt.string(packet.unsignedChatContent))))
// const unsigned = loadPrismarineChat.processNbtMessage(tryParse(packet.unsignedChatContent))
bot.emit('player_chat', { plain: packet.plainMessage, unsigned, senderUuid: packet.senderUuid })
if (packet.type === 5) bot.emit('message', bot.getMessageAsPrismarine({ translate: "chat.type.announcement", with: [`${bot.players.find(player => player.uuid === packet.senderUuid).profile.name}`, `${packet.plainMessage}`]})?.toMotd())
if (packet.type !== 5) bot.emit("message", unsigned)
switch (packet.type) {
case 5:
bot.emit('message', { translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]})
break
default:
bot.emit('message', unsigned)
}
tryParsingMessage(unsigned, { senderUuid: packet.senderUuid, players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine })
})
+1 -3
View File
@@ -34,7 +34,6 @@ function command_manager (bot, options, config, discordClient) {
translate: "command.context.here"
}
])
//}
} else if (source?.sources?.console && !source?.sources?.discord) {
if (!command || !command.execute)
bot.console.warn(bot.getMessageAsPrismarine([
@@ -56,7 +55,7 @@ function command_manager (bot, options, config, discordClient) {
])?.toAnsi())
}
if (command?.trustLevel > 0) {
const event = bot?.discord?.message;
const event = bot.discord.message;
const roles = event?.member?.roles?.cache;
if (command?.trustLevel === 1 && !source?.sources?.discord) {
const hash = args[0]
@@ -91,7 +90,6 @@ function command_manager (bot, options, config, discordClient) {
}
} catch (error) {
console.error(error.stack)
bot?.console?.filelogging(error.stack);
if (source?.sources?.discord && !source?.sources?.console) {
const Embed = new EmbedBuilder()
.setColor(`${config.colors.discord.error}`)
+63 -82
View File
@@ -1,93 +1,74 @@
const CommandSource = require('../util/command_source');
function CommandConsole (bot, options, config) {
const ChatMessage = require('prismarine-chat')(options.version);
let ratelimit = 0;
const prismarineChat = require('prismarine-chat')('1.20.2');
function Console (bot, options, config) {
bot.console = {
readline: null,
consoleServer: 'all',
useReadlineInterface (rl) {
server: 'all',
readlineInterface (rl) {
this.readline = rl
rl.on('line', line => {
if (bot.options.serverName !== this.consoleServer && this.consoleServer !== 'all') return
if (line.startsWith(config.console.prefix)) {
return bot.commandManager.executeString(bot.console.source, line.substring(config.console.prefix.length))
} if (line.startsWith("")) {
return bot.commandManager.executeString(bot.console.source, `console say ${line.substring(0)}`)
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)}`);
}
rl.on('close', () => {
this.readline = null;
})
})
rl.on('close', () => {
this.readline = null
})
log = function (...args) {
rl.output.write("\x1b[2K\r");
console.log(args.toString());
rl._refreshLine();
},
source: new CommandSource(bot.options.username, { console: true, discord: false }),
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) {
this.refreshLine(bot.getMessageAsPrismarine(`§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)
},
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)
}
}
}
bot.console.logs = function (message) {
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)
}
bot.console.source = new CommandSource(bot.options.username, { console: true, discord: false });
bot.console.source.sendFeedback = message => {
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(ChatMessage.fromNotch('§8[§6Command§8] ')?.toAnsi() + ansi);
}
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)
}
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)
}
}
bot.on('message', message => {
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
//ratelimit++
setInterval(() => {
// ratelimit--
ratelimit = 0
}, 1000)
if (ratelimit > 300) {
// options.logging = false
return
}
bot.console.logs(`${ansi}`)
bot.console.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ${string}`)
ratelimit++
bot.on('message', (message) => {
if (!options.logging) return;
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()}`);
})
}
module.exports = CommandConsole;
module.exports = Console;
+1 -5
View File
@@ -20,7 +20,7 @@ function discord(bot, options, config, discordClient) {
invite: config.discord.invite || undefined,
prefix: config.discord.prefix,
// presence: bot.discord.presence,
token: config.discord.token,
// token: config.discord.token,
}
discordClient.once('ready', (context) => {
bot.discord.channel = discordClient.channels.cache.get(options.channelId)
@@ -149,9 +149,5 @@ function discord(bot, options, config, discordClient) {
}
discordClient.on('messageCreate', messageCreate)
process.on("uncaughtException", (e) => {
// sendDiscordMessage("uncaught " + e.stack);
});
}
module.exports = discord;
@@ -3,7 +3,7 @@ const path = require("path");
const { createGzip } = require("zlib");
const readline = require('readline');
const { Console } = require("console");
function consolefilelogger(bot, options, message) {
function fileLogger(bot, options, message) {
const currentDate = new Date();
const timestamp = `${currentDate.getFullYear()}-${(currentDate.getMonth() + 1)
.toString()
@@ -53,8 +53,8 @@ function consolefilelogger(bot, options, message) {
}
compressFile(logFilePath, newFileName);
}
bot.console.filelogging = function logging (message) {
bot.console.fileLogger = function logging (message) {
logStream.write(message + "\n");
};
}
module.exports = consolefilelogger;
module.exports = fileLogger;