From 648f4431d761184b1f94fed919ecd2736a72b644 Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Wed, 25 Sep 2024 12:20:07 -0400 Subject: [PATCH] vanish support (credits to aaa) and somewhat working filter. v6.0.3 build: 1025 --- "src/[\"\"]" | 1 + src/[] | 1 + "src/[]\n" | 1 + ...\"},{\"ignoreCase\":true,\"name\":\"e\"}]" | 1 + ...gnoreCase\":false,\"name\":\"amogus\"}]\n" | 1 + "src/[{}]\n" | 1 + src/bot.js | 5 +- src/commands/cowsay.js | 2 +- src/commands/info.js | 9 ++- src/commands/website.js | 6 +- src/data/default_config.yml | 2 + src/data/filter.json | 1 + src/data/info.json | 4 +- src/modules/chat.js | 6 ++ src/modules/command_manager.js | 20 +++++-- src/modules/console.js | 2 +- src/modules/filterFunction.js | 57 +++++++++++++++++++ src/modules/player_list.js | 22 +++++-- src/modules/tab_complete.js | 18 ++++++ src/util/ChatParsers/Creayun.js | 8 ++- 20 files changed, 145 insertions(+), 23 deletions(-) create mode 100644 "src/[\"\"]" create mode 100644 src/[] create mode 100644 "src/[]\n" create mode 100644 "src/[{\"ignoreCase\":false,\"name\":\"a\"},{\"ignoreCase\":false,\"name\":\"b\"},{\"ignoreCase\":false,\"name\":\"c\"},{\"ignoreCase\":true,\"name\":\"e\"}]" create mode 100644 "src/[{\"ignoreCase\":false,\"name\":\"amogus\"}]\n" create mode 100644 "src/[{}]\n" create mode 100644 src/data/filter.json create mode 100644 src/modules/filterFunction.js create mode 100644 src/modules/tab_complete.js diff --git "a/src/[\"\"]" "b/src/[\"\"]" new file mode 100644 index 0000000..452b3eb --- /dev/null +++ "b/src/[\"\"]" @@ -0,0 +1 @@ +["",{"ignoreCase":false,"name":"amogus"}] \ No newline at end of file diff --git a/src/[] b/src/[] new file mode 100644 index 0000000..74c1e56 --- /dev/null +++ b/src/[] @@ -0,0 +1 @@ +[{"ignoreCase":false,"name":"amogus"}] \ No newline at end of file diff --git "a/src/[]\n" "b/src/[]\n" new file mode 100644 index 0000000..74c1e56 --- /dev/null +++ "b/src/[]\n" @@ -0,0 +1 @@ +[{"ignoreCase":false,"name":"amogus"}] \ No newline at end of file diff --git "a/src/[{\"ignoreCase\":false,\"name\":\"a\"},{\"ignoreCase\":false,\"name\":\"b\"},{\"ignoreCase\":false,\"name\":\"c\"},{\"ignoreCase\":true,\"name\":\"e\"}]" "b/src/[{\"ignoreCase\":false,\"name\":\"a\"},{\"ignoreCase\":false,\"name\":\"b\"},{\"ignoreCase\":false,\"name\":\"c\"},{\"ignoreCase\":true,\"name\":\"e\"}]" new file mode 100644 index 0000000..0637a08 --- /dev/null +++ "b/src/[{\"ignoreCase\":false,\"name\":\"a\"},{\"ignoreCase\":false,\"name\":\"b\"},{\"ignoreCase\":false,\"name\":\"c\"},{\"ignoreCase\":true,\"name\":\"e\"}]" @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git "a/src/[{\"ignoreCase\":false,\"name\":\"amogus\"}]\n" "b/src/[{\"ignoreCase\":false,\"name\":\"amogus\"}]\n" new file mode 100644 index 0000000..5c0b5d7 --- /dev/null +++ "b/src/[{\"ignoreCase\":false,\"name\":\"amogus\"}]\n" @@ -0,0 +1 @@ +[{"ignoreCase":false,"name":"amogus"},"reee"] \ No newline at end of file diff --git "a/src/[{}]\n" "b/src/[{}]\n" new file mode 100644 index 0000000..77b6648 --- /dev/null +++ "b/src/[{}]\n" @@ -0,0 +1 @@ +[{},{"ignoreCase":false,"name":"amogus"}] \ No newline at end of file diff --git a/src/bot.js b/src/bot.js index dd07886..c70a8a3 100644 --- a/src/bot.js +++ b/src/bot.js @@ -25,7 +25,8 @@ function createBot(options = {}, config) { bot.username = client.username }) client.on('disconnect', (data) => { - bot.emit("disconnect", JSON.stringify(data.reason)) + bot.emit("disconnect", data) +// bot.console.info(JSON.stringify(data)) // 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)) @@ -49,7 +50,7 @@ function createBot(options = {}, config) { client.on('kick_disconnect', (data) => { bot.emit("kick_disconnect", data.reason) - bot.console?.warn(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)) diff --git a/src/commands/cowsay.js b/src/commands/cowsay.js index 7566aca..03838b9 100644 --- a/src/commands/cowsay.js +++ b/src/commands/cowsay.js @@ -15,7 +15,7 @@ module.exports = { const bot = context.bot; const args = context.arguments; const source = context.source; - if (args[0] === "list") { + if (args[0]?.toLowerCase() === "list") { const list = Object.keys(cows); let content = []; let color = true; diff --git a/src/commands/info.js b/src/commands/info.js index 79d0711..838e503 100644 --- a/src/commands/info.js +++ b/src/commands/info.js @@ -41,7 +41,14 @@ module.exports = { switch (args[0]?.toLowerCase()) { case 'version': if (botInfo.bot.buildstring.codename === '') { - bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, `§9Friday §9Night §9Funkin §3Boyfriend §1Bot§8§r-${botInfo.bot.buildstring.version}-#${botInfo.bot.buildstring.build}\n11/22/22 - ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })}`); + if (bot.options.isSavage) { + bot.chat.message(`&9Friday &9Night &9Funkin &3Boyfriend &1Bot&8&r-${botInfo.bot.buildstring.version}-#${botInfo.bot.buildstring.build}`) + setTimeout(() => { + bot.chat.message(`11/22/22 - ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })}`) + }, 300) + } else { + bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, `§9Friday §9Night §9Funkin §3Boyfriend §1Bot§8§r-${botInfo.bot.buildstring.version}-#${botInfo.bot.buildstring.build}\n11/22/22 - ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })}`); + } } else { bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, `§9Friday §9Night §9Funkin §3Boyfriend §1Bot§8§r-${botInfo.bot.buildstring.version}-#${botInfo.bot.buildstring.build}-${botInfo.bot.buildstring.codename}\n11/22/22 - ${new Date().toLocaleDateString("en-US", { timeZone: "America/CHICAGO" })}`); } diff --git a/src/commands/website.js b/src/commands/website.js index f98ac9f..e838dc7 100644 --- a/src/commands/website.js +++ b/src/commands/website.js @@ -15,8 +15,8 @@ module.exports = { execute (context) { const bot = context.bot const args = context.arguments; - if (args.join(' ').toLowerCase().startsWith("http://")) { - http.get(args.join(' '), (res) => { + if (args.slice(1).join(' ').toLowerCase().startsWith("http://")) { + http.get(args.slice(1).join(' '), (res) => { const { statusCode } = res; const contentType = res.headers['content-type']; res.setEncoding('utf8'); @@ -33,7 +33,7 @@ module.exports = { bot.chat.message(`&4${e.toString()}`); }); } else { - https.get(args.join(' '), (res) => { + https.get(args.slice(1).join(' '), (res) => { res.on('data', (d) => { bot.tellraw("@a", { text: util.inspect(d.toString().substring(0, 32750)), color: "dark_green", }) // console.log(Object.keys(d.toString().length)); diff --git a/src/data/default_config.yml b/src/data/default_config.yml index 82b71c4..4217a99 100644 --- a/src/data/default_config.yml +++ b/src/data/default_config.yml @@ -25,6 +25,8 @@ core: y: 0 z: 15 +commandSetMessage: true + keys: trusted: "trusted key here" admin: "admin key here" diff --git a/src/data/filter.json b/src/data/filter.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/src/data/filter.json @@ -0,0 +1 @@ +[] diff --git a/src/data/info.json b/src/data/info.json index b65431a..3f24151 100644 --- a/src/data/info.json +++ b/src/data/info.json @@ -1,8 +1,8 @@ { "bot": { "buildstring": { - "version": "v6.0.2", - "build":"1000", + "version": "v6.0.3", + "build":"1025", "codename":"" }, "source": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot/" diff --git a/src/modules/chat.js b/src/modules/chat.js index a25e5ac..d737678 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -58,6 +58,12 @@ function chat (bot, options, config) { case 5: bot.emit('message', { translate: "chat.type.announcement", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ]}) break + case 3: + bot.emit('message', { translate: "commands.message.display.outgoing", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) + break + case 2: + bot.emit('message', { translate: "commands.message.display.incoming", with: [ bot.players.find(player => player.uuid === packet.senderUuid).profile.name, packet.plainMessage ], color: "gray", italic: true }) + break default: bot.emit('message', unsigned) } diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js index 5ed3287..c92251c 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -59,7 +59,7 @@ function command_manager (bot, options, config, discordClient) { const roles = event?.member?.roles?.cache; if (command?.trustLevel === 1 && !source?.sources?.discord) { const hash = args[0] - if (args.length === 0 && bot.validation.trusted && bot.validation.admin && bot.validation.owner && !source?.sources?.console) throw new CommandError({ text: "Please provide an trusted or and admin or an owner hash" }) + if (args.length === 0 && bot.validation.trusted && bot.validation.admin && bot.validation.owner && !source?.sources?.console) throw new CommandError({ text: "Please provide an trusted or an admin or an owner hash" }) if (args[0] !== bot.validation.trusted && args[0] !== bot.validation.admin && args[0] !== bot.validation.owner && !source.sources.console) throw new CommandError({ translate: 'Invalid trusted or admin or owner hash', color: 'dark_red' }) } else if (command?.trustLevel === 1 && source?.sources.discord) { const hasRole = roles?.some(role => role.name === `${config.discord.roles.trusted}` || role.name === `${config.discord.roles.owner}`) @@ -101,9 +101,21 @@ function command_manager (bot, options, config, discordClient) { ] }) } else if (!source?.sources?.discord && !source?.sources?.console) { - if (error instanceof CommandError) - bot.tellraw("@a", { text: error.message, color: "dark_red" }) - else bot.tellraw("@a", [{ translate: 'command.failed', color: "dark_red", hoverEvent: { action: 'show_text', contents: `${error.stack}` } }]) + if (error instanceof CommandError) { + if (bot.options.isSavage || bot.options.isCreayun) { + bot.chat.message(`&4${error.message}`) + } else { + bot.tellraw("@a", { text: error.message, color: "dark_red" }) + } + } else { + if (bot.options.isSavage || bot.options.isCreayun) { + bot.chat.message(`${bot.getMessageAsPrismarine({ translate: "command.failed", color: "dark_red" })?.toMotd().replaceAll('§','&')}`) + } else { + bot.tellraw("@a", [{ translate: 'command.failed', color: "dark_red", hoverEvent: { action: 'show_text', contents: `${error.stack}` } }]) + } + } +// else bot.tellraw("@a", [{ translate: 'command.failed', color: "dark_red", hoverEvent: { action: 'show_text', contents: `${error.stack}` } }]) + //} } } }, diff --git a/src/modules/console.js b/src/modules/console.js index eb87601..acca850 100644 --- a/src/modules/console.js +++ b/src/modules/console.js @@ -50,7 +50,7 @@ function Console (bot, options, config) { }, { selector: `${bot.username}`, color:'#00FFFF', - clickEvent: { action: 'suggest_command', value: '~help' } + clickEvent: { action: 'suggest_command', value: `${config.prefixes[0]}help` } }, { text: '', diff --git a/src/modules/filterFunction.js b/src/modules/filterFunction.js new file mode 100644 index 0000000..234516b --- /dev/null +++ b/src/modules/filterFunction.js @@ -0,0 +1,57 @@ +const fs = require('fs'); +const path = require('path'); +const jsonData = fs.readFileSync(path.join(__dirname, '../data/filter.json')); +function filterFunction (bot, options, config) { + bot.filter = { + list () { + try { + return JSON.parse(jsonData); + } catch (e) { + bot.chat.message(`&4${e.toString()}`); + } + }, + add (player) { + try { + const filterList = JSON.parse(jsonData); + const addData = { + ignoreCase: false, + name: player + } + filterList.push(addData); + const data = JSON.stringify(filterList); + fs.writeFile(jsonData, data, (err) => { + if (err) throw err; + }) + console.log(data); + } catch (e) { + bot.chat.message(`${e.toString()}`); + } + }, + ignoreCase (player) { + try { + const filterList = JSON.parse(jsonData); + const addData = { + ignoreCase: true, + name: player + } + filterList.push(addData); + const data = JSON.stringify(filterList); + fs.writeFile(jsonData, data, (err) => { + if (err) throw err; + }) + console.log(data); + } catch (e) { + bot.chat.message(`${e.toString()}`); + } + }, + clear () { + try { +// fs.rmSync(path.join(__dirname, '../data/filter.json')); + fs.writeFileSync(jsonData, JSON.stringify([])); + } catch (e) { + bot.chat.message(`${e.toString()}`) + } + } + } +} +module.exports = filterFunction; diff --git a/src/modules/player_list.js b/src/modules/player_list.js index a2ae2c0..7a7681a 100644 --- a/src/modules/player_list.js +++ b/src/modules/player_list.js @@ -18,11 +18,20 @@ function player_list (bot, options, config) { } }) - bot.on('packet.player_remove', ({ players }) => { - // TODO: Add player removal (with validation) - for (const player of players) { - bot.players = bot.players.filter(entry => entry.uuid !== player) - } + bot.on('packet.player_remove', async ({players}) => { // players has uuids of the players + let player_completion = (await bot.tab_complete('scoreboard players add ')).filter(_ => _.tooltip == undefined) // exclude @a, @r, @s, @e, @p -aaa + + bot.players.forEach(async player => { + if(!players.includes(player.uuid)) return + + const a = player_completion.filter(_ => _.match == player.profile.name) + + if(a.length >= 1) { + player.vanished = true + } else { + bot.players = bot.players.filter(_ => _.uuid != player.uuid) + } + }) }) function addPlayer (entry) { @@ -35,7 +44,8 @@ function player_list (bot, options, config) { gamemode: undefined, listed: undefined, latency: undefined, - displayName: undefined + displayName: undefined, + vanished: false }) } diff --git a/src/modules/tab_complete.js b/src/modules/tab_complete.js new file mode 100644 index 0000000..ab90df5 --- /dev/null +++ b/src/modules/tab_complete.js @@ -0,0 +1,18 @@ +module.exports = (bot) => { + // let aaa cook + bot.tab_complete = (str) => { + return new Promise((resolve) => { + bot._client.write('tab_complete', { + text: str, assumeCommand: false, sendBlockInSight: false + }) + + const tab_completeH = (packet) => { + bot._client.removeListener('tab_complete', tab_completeH) + + resolve(packet.matches) + } + + bot._client.once('tab_complete', tab_completeH) + }) + } +} diff --git a/src/util/ChatParsers/Creayun.js b/src/util/ChatParsers/Creayun.js index 625e839..12465b7 100644 --- a/src/util/ChatParsers/Creayun.js +++ b/src/util/ChatParsers/Creayun.js @@ -1,14 +1,16 @@ const ChatMessage = require('prismarine-chat')('1.20.2'); const util = require('util'); function creayun (messageobj, data) { + let match; + let sender; const stringify = message => new ChatMessage(message).toString() const message = stringify(messageobj); const playerWithPrefix = /^(.*?) (\S*?) » (.*?)$/; const playerWithoutPrefix = /^(\S*?) » (.*?)$/ if (playerWithPrefix.test(message)) { - let match = message.match(playerWithPrefix) - const sender = data.players.find((player) => player.uuid === player.uuid) - if (!sender) return undefined + match = message.match(playerWithPrefix) + sender = data.players.find(player => player.profile.name === match[2]) + if (!sender) return; return { sender, contents: match[3], type: 'minecraft:chat'}; } }