mirror of
https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot.git
synced 2024-11-24 08:08:23 -05:00
console rewrite and chat packet types rewrite. v6.0.1 build: 990
This commit is contained in:
parent
6eeb079ced
commit
b295cc2d0f
16 changed files with 436 additions and 145 deletions
23
src/bot.js
23
src/bot.js
|
@ -1,16 +1,17 @@
|
|||
const mc = require('minecraft-protocol')
|
||||
const { EventEmitter } = require('events')
|
||||
require("events").EventEmitter.defaultMaxListeners = Infinity;
|
||||
//require("events").EventEmitter.defaultMaxListeners = Infinity;
|
||||
EventEmitter.defaultMaxListeners = Infinity
|
||||
const util = require('util');
|
||||
function createBot(options = {}, config) {
|
||||
const bot = new EventEmitter()
|
||||
const bot = new EventEmitter();
|
||||
bot.options = {
|
||||
// Set some default values in options
|
||||
host: options.host ??= 'localhost',
|
||||
username: options.username ??= 'Player',
|
||||
hideErrors: options.hideErrors ??= true, // HACK: Hide errors by default as a lazy fix to console being spammed with them
|
||||
};
|
||||
bot.options = options
|
||||
bot.options = options;
|
||||
const ChatMessage = require('prismarine-chat')(bot.options.version);
|
||||
// Create our client object, put it on the bot, and register some events
|
||||
bot.on('init_client', client => {
|
||||
|
@ -25,9 +26,9 @@ function createBot(options = {}, config) {
|
|||
})
|
||||
client.on('disconnect', (data) => {
|
||||
bot.emit("disconnect", JSON.stringify(data.reason))
|
||||
bot?.discord?.channel?.send(util.inspect(data.reason))
|
||||
// bot?.discord?.channel?.send(util.inspect(data.reason))
|
||||
if (config.console.filelogger) {
|
||||
bot?.console?.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ` + '[Client Reconnect] ' + util.inspect(data.reason))
|
||||
// bot?.console?.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ` + '[Client Reconnect] ' + util.inspect(data.reason))
|
||||
}
|
||||
})
|
||||
client.on('end', reason => {
|
||||
|
@ -35,10 +36,10 @@ function createBot(options = {}, config) {
|
|||
})
|
||||
|
||||
client.on('error', error => {
|
||||
bot.console.logs(ChatMessage.fromNotch('§8[§bClient Reconnect§8]§r ')?.toAnsi() + util.inspect(error.toString()))
|
||||
bot?.discord?.channel?.send(error.toString())
|
||||
bot.console.warn(ChatMessage.fromNotch('§8[§bClient Reconnect§8]§r ')?.toAnsi() + util.inspect(error.toString()))
|
||||
// bot?.discord?.channel?.send(error.toString())
|
||||
if (config.console.filelogger) {
|
||||
bot?.console?.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ` + '[Client Reconnect] ' + util.inspect(error.toString()))
|
||||
// bot?.console?.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ` + '[Client Reconnect] ' + util.inspect(error.toString()))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -48,10 +49,10 @@ function createBot(options = {}, config) {
|
|||
|
||||
client.on('kick_disconnect', (data) => {
|
||||
bot.emit("kick_disconnect", data.reason)
|
||||
bot.console.logs(ChatMessage.fromNotch('§8[§bClient Reconnect§8]§r ')?.toAnsi() + util.inspect(data.reason))
|
||||
bot.console?.warn(ChatMessage.fromNotch('§8[§bClient Reconnect§8]§r ')?.toAnsi() + util.inspect(data.reason))
|
||||
bot?.discord?.channel?.send(util.inspect(data.reason))
|
||||
if (config.console.filelogger) {
|
||||
bot?.console?.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ` + '[Client Reconnect] ' + util.inspect(data.reason))
|
||||
// bot?.console?.filelogging(`[${new Date().toLocaleTimeString("en-US", { timeZone: "America/CHICAGO", })} ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO", })} logs] [${options.serverName}] ` + '[Client Reconnect] ' + util.inspect(data.reason))
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -60,7 +61,7 @@ function createBot(options = {}, config) {
|
|||
});
|
||||
})
|
||||
|
||||
const client = options.client ?? mc.createClient(options)
|
||||
const client = options.client ?? new mc.createClient(options)
|
||||
bot._client = client
|
||||
bot.emit('init_client', client)
|
||||
bot.bots = options.bots ?? [bot]
|
||||
|
|
|
@ -15,17 +15,17 @@ module.exports = {
|
|||
const servers = bot.bots.map(eachBot => eachBot.options.serverName);
|
||||
for (const eachBot of bot.bots) {
|
||||
if (args.slice(1).join(' ').toLowerCase() === 'all') {
|
||||
eachBot.console.consoleServer = 'all'
|
||||
bot.console.logs("Set the console server to all");
|
||||
eachBot.console.server = 'all'
|
||||
bot.console.info("Set the console server to all");
|
||||
continue
|
||||
}
|
||||
const server = servers.find(server => server.toLowerCase().includes(args[1]))
|
||||
if (!server) {
|
||||
bot.console.logs("Invalid server");
|
||||
bot.console.info("Invalid server");
|
||||
return
|
||||
}
|
||||
bot.console.logs(`Set the console server to ` + server);
|
||||
eachBot.console.consoleServer = server;
|
||||
bot.console.info(`Set the console server to ` + server);
|
||||
eachBot.console.server = server;
|
||||
}
|
||||
break
|
||||
case 'customchat':
|
||||
|
|
|
@ -9,19 +9,12 @@ module.exports = {
|
|||
usages: [
|
||||
""
|
||||
],
|
||||
async execute (context) {
|
||||
execute (context) {
|
||||
const bot = context.bot;
|
||||
// ik theres a better way to do but shut the fuck up about it
|
||||
await bot.chat.message("killing process");
|
||||
await bot.console.info("killing process");
|
||||
await bot.discord.channel?.send("killing process");
|
||||
await process.kill(0);
|
||||
process.exit(69);
|
||||
},
|
||||
async discordExecute (context) {
|
||||
discordExecute (context) {
|
||||
const bot = context.bot;
|
||||
await bot.chat.message("killing process");
|
||||
await bot.console.info("killing process");
|
||||
await bot.discord.channel?.send("killing process");
|
||||
await process.exit(0);
|
||||
process.exit(69);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module.exports = {
|
||||
name: 'reload',
|
||||
trustLevel: 0,
|
||||
trustLevel: 3,
|
||||
aliases: [
|
||||
],
|
||||
description: 'reloads commands',
|
||||
|
|
|
@ -5,7 +5,7 @@ const fixansi = require('../util/ansi');
|
|||
const CommandError = require('../util/command_error')
|
||||
module.exports = {
|
||||
name: 'website',
|
||||
trustLevel: 0,
|
||||
trustLevel: 4,
|
||||
aliases: [
|
||||
],
|
||||
description: 'look up website data',
|
||||
|
|
91
src/console.js
Normal file
91
src/console.js
Normal file
|
@ -0,0 +1,91 @@
|
|||
const CommandSource = require('../util/command_source');
|
||||
function CommandConsole (bot, options, config) {
|
||||
const ChatMessage = require('prismarine-chat')(options.version);
|
||||
// let ratelimit = 0;
|
||||
bot.console = {
|
||||
readline: null,
|
||||
consoleServer: 'all',
|
||||
useReadlineInterface (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('close', () => {
|
||||
this.readline = null
|
||||
})
|
||||
log = function (...args) {
|
||||
rl.output.write("\x1b[2K\r");
|
||||
console.log.apply(console, arguments);
|
||||
rl._refreshLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
// setInterval(() => ratelimit = 0, 1000)
|
||||
bot.on('message', message => {
|
||||
/* if (ratelimit > 300) {
|
||||
// bot.console.warn('WTF spam detected not logging')
|
||||
bot.options.logging = false;
|
||||
return;
|
||||
}*/
|
||||
// options.logging = true;
|
||||
// if (ratelimit++ >= 300) return
|
||||
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
|
||||
// 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}`)
|
||||
})
|
||||
}
|
||||
module.exports = CommandConsole;
|
|
@ -1,9 +1,9 @@
|
|||
{
|
||||
"bot": {
|
||||
"buildstring": {
|
||||
"version": "v6.0.0",
|
||||
"build":"950",
|
||||
"codename":"§#fe019aGraffiti §7Groovin"
|
||||
"version": "v6.0.1",
|
||||
"build":"990",
|
||||
"codename":""
|
||||
},
|
||||
"source": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot/"
|
||||
}
|
||||
|
|
159
src/discord.js
Normal file
159
src/discord.js
Normal file
|
@ -0,0 +1,159 @@
|
|||
// TODO: Maybe move client creation elsepwhere
|
||||
const { Client, GatewayIntentBits, interaction } = require('discord.js')
|
||||
const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits
|
||||
const fixansi = require('../util/ansi');
|
||||
const CommandSource = require('../util/command_source')
|
||||
|
||||
const client = new Client({ intents: [Guilds, GuildMessages, MessageContent] })
|
||||
const util = require('util')
|
||||
|
||||
function discord(bot, options, config) {
|
||||
if (!config.discord.enabled) return;
|
||||
client.login(config.discord.token)
|
||||
if (!options?.channelId) {
|
||||
bot.discord = {
|
||||
invite: config.discord?.invite
|
||||
}
|
||||
return
|
||||
}
|
||||
bot.discord = {
|
||||
client,
|
||||
channel: undefined,
|
||||
invite: config.discord.invite || undefined,
|
||||
prefix: config.discord.prefix,
|
||||
// presence: bot.discord.presence,
|
||||
// token: config.discord.token,
|
||||
}
|
||||
client.once('ready', (context) => {
|
||||
bot.discord.channel = client.channels.cache.get(options.discord.channelId)
|
||||
client.user.setPresence({
|
||||
activities: [{
|
||||
name: `your mother`,
|
||||
type: 0
|
||||
}],
|
||||
status: `dnd`
|
||||
});
|
||||
})
|
||||
|
||||
let discordQueue = []
|
||||
setInterval(() => {
|
||||
if (discordQueue.length === 0) return
|
||||
try {
|
||||
bot?.discord?.channel?.send(`\`\`\`ansi\n${discordQueue.join('\n').substring(0, 1984)}\n\`\`\``)
|
||||
} catch (error) {
|
||||
bot.console.warn(error.toString())
|
||||
}
|
||||
discordQueue = []
|
||||
}, 2000)
|
||||
|
||||
function sendDiscordMessage(message) {
|
||||
discordQueue.push(message)
|
||||
}
|
||||
|
||||
function sendComponent(message) {
|
||||
const ansi = bot.getMessageAsPrismarine(message)?.toAnsi(bot.registry.language).replaceAll('```\u001b[9```' + '```\u001b[3```').replaceAll('https://discord','https:\rdiscord')?.replaceAll('discord.gg', 'discord.\rgg').replaceAll('BlackStone Mafia On Top!', "Fuck off you god damn cunt");
|
||||
try {
|
||||
sendDiscordMessage(fixansi(ansi?.replaceAll('`', '`\u200b')))
|
||||
} catch (e) {
|
||||
bot.console.error(`Error sending a message to Discord:\n${e.message}`)
|
||||
sendDiscordMessage(e.message)
|
||||
}
|
||||
}
|
||||
bot.on('message', message => {
|
||||
sendComponent(message)
|
||||
})
|
||||
|
||||
function messageCreate(message, source) {
|
||||
bot.discord.message = message;
|
||||
if (message.author.id === bot.discord.client.user.id) return
|
||||
|
||||
if (message.channel.id !== bot.discord.channel.id) return
|
||||
|
||||
if (message.content.startsWith(config.discord.prefix)) { // TODO: Don't hardcode this
|
||||
const source = new CommandSource({
|
||||
profile: {
|
||||
name: message?.member?.displayName
|
||||
}
|
||||
}, {
|
||||
discord: true,
|
||||
console: false
|
||||
}, false, message)
|
||||
|
||||
bot.sendFeedback = message => {
|
||||
sendComponent(message)
|
||||
}
|
||||
|
||||
bot.commandManager.executeString(source, message.content.substring(config.discord.prefix.length))
|
||||
return
|
||||
}
|
||||
const tag = {
|
||||
translate: '[%s] %s \u203a %s',
|
||||
with: [{
|
||||
translate: '%s%s%s %s',
|
||||
bold: false,
|
||||
with: [{
|
||||
text: 'FNF',
|
||||
bold: false,
|
||||
color: 'blue'
|
||||
},
|
||||
{
|
||||
text: 'Boyfriend',
|
||||
bold: false,
|
||||
color: 'dark_aqua'
|
||||
},
|
||||
{
|
||||
text: 'Bot',
|
||||
bold: false,
|
||||
color: 'dark_blue'
|
||||
},
|
||||
{
|
||||
text: 'Discord',
|
||||
bold: false,
|
||||
color: 'dark_blue'
|
||||
}
|
||||
],
|
||||
clickEvent: bot.discord.invite ? {
|
||||
action: 'open_url',
|
||||
value: bot.discord.invite
|
||||
} : undefined,
|
||||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
contents: 'Click to join the discord'
|
||||
}
|
||||
},
|
||||
{
|
||||
text: message?.member?.displayName
|
||||
},
|
||||
message.content
|
||||
]
|
||||
}
|
||||
if (message.attachments.size > 0) {
|
||||
message.attachments.forEach(Attachment => {
|
||||
bot.tellraw('@a', [tag, {
|
||||
text: ' ' ? ' [Attachment] ' : ' [Attachment] ',
|
||||
hoverEvent: {
|
||||
action: 'show_text',
|
||||
contents: 'Click here to view attachment'
|
||||
},
|
||||
clickEvent: {
|
||||
action: 'open_url',
|
||||
value: `${Attachment.url}`
|
||||
}
|
||||
}])
|
||||
})
|
||||
} else {
|
||||
if (options.useChat || options.isSavage || options.isCreayun) {
|
||||
bot.chat.message(bot.getMessageAsPrismarine(`&7[&9FNF&3Boyfriend&1Bot Discord&7] ${message?.member?.displayName} \u203a ${message?.content}`)?.toMotd().replaceAll('§','&'))
|
||||
} else {
|
||||
bot.tellraw('@a', tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
client.on('messageCreate', messageCreate)
|
||||
|
||||
process.on("uncaughtException", (e) => {
|
||||
// sendDiscordMessage("uncaught " + e.stack);
|
||||
});
|
||||
|
||||
}
|
||||
module.exports = discord;
|
|
@ -27,9 +27,9 @@ const rl = readline.createInterface({
|
|||
if (config.discord.enabled) discordClient.login(config.discord.token);
|
||||
const bots = [];
|
||||
for (const options of config.bots) {
|
||||
const bot = createBot(options, config);
|
||||
const bot = new createBot(options, config);
|
||||
bots.push(bot);
|
||||
bot.bots = bots;
|
||||
loadModules(bot, options, config, discordClient);
|
||||
bot.console.useReadlineInterface(rl);
|
||||
bot.console.readlineInterface(rl);
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
})
|
||||
|
||||
|
|
|
@ -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}`)
|
||||
|
|
|
@ -1,50 +1,42 @@
|
|||
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
|
||||
this.readline = null;
|
||||
})
|
||||
log = function (...args) {
|
||||
rl.output.write("\x1b[2K\r");
|
||||
console.log(args.toString());
|
||||
rl._refreshLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
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 = {
|
||||
})
|
||||
},
|
||||
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 = {
|
||||
|
@ -72,22 +64,11 @@ function CommandConsole (bot, options, config) {
|
|||
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;
|
||||
|
|
|
@ -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;
|
||||
|
|
60
src/modules/fileLogger.js
Normal file
60
src/modules/fileLogger.js
Normal file
|
@ -0,0 +1,60 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { createGzip } = require("zlib");
|
||||
const readline = require('readline');
|
||||
const { Console } = require("console");
|
||||
function fileLogger(bot, options, message) {
|
||||
const currentDate = new Date();
|
||||
const timestamp = `${currentDate.getFullYear()}-${(currentDate.getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")}-${currentDate.getDate().toString().padStart(2, "0")}`;
|
||||
const logFolder = path.join(__dirname, "../../logs");
|
||||
const logFileName = "latest.log";
|
||||
const logFilePath = path.join(logFolder, logFileName);
|
||||
const logStream = fs.createWriteStream(logFilePath, { flags: "a" });
|
||||
if (!fs.existsSync(path.join(__dirname, "../../logs"))) {
|
||||
fs.mkdirSync(path.join(__dirname, "../../logs"))
|
||||
}
|
||||
try {
|
||||
if (!fs.existsSync(logFolder)) {
|
||||
fs.mkdirSync(logFolder);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`Unable to create log folder: ${e}`);
|
||||
}
|
||||
|
||||
function compressFile(input, output) {
|
||||
// if (!bot.Console.filelogging) return
|
||||
const plainOutput = output.slice(0, -3);
|
||||
|
||||
fs.renameSync(input, plainOutput);
|
||||
const gzip = createGzip();
|
||||
fs.createReadStream(plainOutput)
|
||||
.pipe(gzip)
|
||||
.pipe(fs.createWriteStream(output + ".tmp"))
|
||||
.once("finish", () => {
|
||||
fs.unlinkSync(plainOutput);
|
||||
fs.renameSync(output + ".tmp", output);
|
||||
});
|
||||
}
|
||||
|
||||
if (fs.existsSync(logFilePath)) {
|
||||
const plainName = fs
|
||||
.statSync(logFilePath)
|
||||
.ctime.toISOString()
|
||||
.split("T")[0];
|
||||
let name = plainName;
|
||||
let counter = 1;
|
||||
let newFileName = path.join(logFolder, `${name}.log.gz`);
|
||||
while (fs.existsSync(newFileName)) {
|
||||
name = `${plainName}-${counter}`;
|
||||
newFileName = path.join(logFolder, `${name}.log.gz`);
|
||||
counter++;
|
||||
}
|
||||
compressFile(logFilePath, newFileName);
|
||||
}
|
||||
bot.console.fileLogger = function logging (message) {
|
||||
logStream.write(message + "\n");
|
||||
};
|
||||
}
|
||||
module.exports = fileLogger;
|
Loading…
Reference in a new issue