From 122e8e7df0140aa42fb57bb187a93b4dbe3c4905 Mon Sep 17 00:00:00 2001 From: Parker2991 Date: Mon, 16 Dec 2024 13:48:50 -0500 Subject: [PATCH] v6.1.5 build: 1225 --- package-lock.json | 4 +- src/commands/public/info.js | 20 +++- src/commands/public/mcserver.js | 52 ++------- src/commands/public/netmsg.js | 26 ++--- src/commands/public/weather.js | 173 ++++++++++++++++++++++------ src/commands/public/wiki.js | 11 +- src/data/default_config.yml | 5 + src/index.js | 14 ++- src/modules/chat.js | 9 +- src/modules/chat_command_handler.js | 6 +- src/modules/command_core.js | 14 +-- src/modules/command_manager.js | 38 ++++-- src/modules/command_suggestion.js | 44 +++++++ src/modules/discord.js | 5 - src/modules/fileLogger.js | 7 +- src/modules/memusage.js | 63 +++++++++- src/modules/reconnect.js | 4 - src/modules/team.js | 4 +- src/util/checks.js | 23 ---- 19 files changed, 348 insertions(+), 174 deletions(-) create mode 100644 src/modules/command_suggestion.js delete mode 100644 src/util/checks.js diff --git a/package-lock.json b/package-lock.json index e0c27c7..3f447ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3,8 +3,8 @@ "lockfileVersion": 3, "requires": true, "buildstring": { - "version": "v6.1.4", - "build": "1215", + "version": "v6.1.5", + "build": "1225", "codename": "", "url": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot" }, diff --git a/src/commands/public/info.js b/src/commands/public/info.js index ab75cea..fb8f5d3 100644 --- a/src/commands/public/info.js +++ b/src/commands/public/info.js @@ -358,6 +358,24 @@ module.exports = { default: throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); } - bot.tellraw(`@a[name="${source.player.profile.name}"]`, component); + if (bot.options.isSavage) { + bot.chat.message(bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&')); +// bot.chat.message(bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&')); +// console.log(component.includes('\n')); +// if (component.includes('\n')) { +// console.log('e'); +// } +// console.log(bot.getMessageAsPrismarine(component)?.toString()?.find) +// bot.chat.message(bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&').replaceAll('\n','\n')); +// bot.chat.message(bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('\n','\n')?.replaceAll('§','&')); +// console.log(component.toString()); +// console.log(component.toString().replaceAll) + //console.log(component.find((e) => e).with) +// for (const componentText of component.find((e) => e).with) { +// bot.chat.message(bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&')) + // } + } else { + bot.tellraw(`@a[name="${source.player.profile.name}"]`, component); + } }, } diff --git a/src/commands/public/mcserver.js b/src/commands/public/mcserver.js index ce1503d..1f4e699 100644 --- a/src/commands/public/mcserver.js +++ b/src/commands/public/mcserver.js @@ -44,49 +44,15 @@ module.exports = { server.description ] }) - bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, component); -/* bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, [ - { - text: `Ip \u203a ${host}:${Number(port ?? 25565)}\n`, - color: 'gray', - hoverEvent: { - action: 'show_text', - contents: [{ - text: 'click here for the servers ip', - color: 'gray' - }] - }, - clickEvent: { - action: 'copy_to_clipboard', - value: `${host}:${Number(port ?? 25565)}` - } - }, - { - text: `Players \u203a `, - color: 'gray' - }, - { - text: `${server.players.online}`, - color: "gold" - }, - { - text: ' / ', - color: 'gray' - }, - { - text: `${server.players.max}\n`, - color: "gold" - }, - { - text: `Version \u203a ${server.version.name}\n`, - color: 'gray', - }, - { - text: "Motd \u203a\n", - color: 'gray', - }, - server.description, - ])*/ + + if (bot.options.isSavage) { + bot.chat.message(`Ip \u203a ${host}:${Number(port ?? 25565)}`); + bot.chat.message(`Players \u203a ${server.players.online} / ${server.players.max}`); + bot.chat.message(`Version \u203a ${server.version.name}`); + bot.chat.message(bot.getMessageAsPrismarine(server.description)?.toMotd().replaceAll('§','&')); + } else { + bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, component); + } } catch (e) { bot.chat.message(`${e.toString()}`) } diff --git a/src/commands/public/netmsg.js b/src/commands/public/netmsg.js index dbd63a6..3f88c6b 100644 --- a/src/commands/public/netmsg.js +++ b/src/commands/public/netmsg.js @@ -39,20 +39,14 @@ module.exports = { } } bot.bots.filter((eachBot) => { - if (eachBot.options.isSavage && !eachBot.options.useChat && !eachBot.options.isKaboom || eachBot.options.isCreayun && !eachBot.options.isSavage && !eachBot.options.useChat && !eachBot.options.isKaboom) { - eachBot.chat.message(`[${bot.options.serverName}] ${bot.getMessageAsPrismarine(source.player.displayName ?? source.player.profile.name)?.toMotd().replaceAll('§','&')} \u203a ${args.join(' ')}`) - } else if (!eachBot.options.serverName !== "Savage Friends" && !eachBot.options.isSavage && !eachBot.options.useChat && eachBot.options.isKaboom) { - eachBot.tellraw("@a", component); - } else if (!eachBot.options.serverName !== "Savage Friends" && !eachBot.options.isSavage && eachBot.options.useChat && eachBot.options.isKaboom) { - eachBot.chat.message(`&7[&7${bot.options.serverName}&7] ${bot.getMessageAsPrismarine(source.player.displayName ?? source.player.profile.name)?.toMotd().replaceAll('§','&')} &7\u203a ${args.join(' ')}`) - } else if (eachBot.options.useChat && !eachBot.options.isSavage) { -// eachBot.chat.message(bot.getMessageAsPrismarine(`[${bot.options.host}:${bot.options.port}] ${source.player.displayName ?? source.player.profile.name} \u203a ${args.join(' ')}`)?.toMotd().replaceAll('§','&')) - eachBot.chat.message(`&7[&7${bot.options.serverName}&7] ${bot.getMessageAsPrismarine(source.player.displayName ?? source.player.profile.name)?.toMotd().replaceAll('§','&')} &7\u203a ${args.join(' ')}`) - } else if (!eachBot.options.useChat && !eachBot.options.isSavage) { + if (!eachBot.options.isKaboom || eachBot.options.useChat) { + eachBot.chat.message(`${bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&')}`); + } else if (eachBot.options.isKaboom && !eachBot.options.useChat) { eachBot.tellraw("@a", component); } }) }, + discordExecute (context) { const bot = context.bot; const args = context.arguments; @@ -80,15 +74,9 @@ module.exports = { } } bot.bots.filter((eachBot) => { - if (eachBot.options.serverName === "Savage Friends" && eachBot.options.isSavage && !eachBot.options.useChat && !eachBot.options.isKaboom) { - eachBot.chat.message(`[${bot.options.serverName}] ${bot.getMessageAsPrismarine(source.player.displayName ?? source.player.profile.name)?.toMotd().replaceAll('§','&')} \u203a ${args.join(' ')}`) - } else if (!eachBot.options.serverName !== "Savage Friends" && !eachBot.options.isSavage && !eachBot.options.useChat && eachBot.options.isKaboom) { - eachBot.tellraw("@a", component); - } else if (!eachBot.options.serverName !== "Savage Friends" && !eachBot.options.isSavage && eachBot.options.useChat && eachBot.options.isKaboom) { - eachBot.chat.message(`&7[&7${bot.options.serverName}&7] ${bot.getMessageAsPrismarine(source.player.displayName ?? source.player.profile.name)?.toMotd().replaceAll('§','&')} &7\u203a ${args.join(' ')}`) - } else if (eachBot.options.useChat && !eachBot.options.isSavage) { - eachBot.chat.message(`&7[&7${bot.options.serverName}&7] ${bot.getMessageAsPrismarine(source.player.displayName ?? source.player.profile.name)?.toMotd().replaceAll('§','&')} &7\u203a ${args.join(' ')}`) - } else if (!eachBot.options.useChat && !eachBot.options.isSavage) { + if (!eachBot.options.isKaboom || eachBot.options.useChat) { + eachBot.chat.message(`${bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&')}`); + } else if (eachBot.options.isKaboom && !eachBot.options.useChat) { eachBot.tellraw("@a", component); } }) diff --git a/src/commands/public/weather.js b/src/commands/public/weather.js index fcc291e..21394c7 100644 --- a/src/commands/public/weather.js +++ b/src/commands/public/weather.js @@ -16,43 +16,146 @@ module.exports = { const args = context.arguments; const config = context.config; const source = context.source; + const { MessageBuilder } = require('prismarine-chat')(bot.options.version); try { - let component = []; - const weather = await request(`https://api.weatherapi.com/v1/current.json?key=${config.weatherApiKey}&q=${args.join(' ')?.replaceAll(' ', ',')}`); + let component; + const weather = await request(`https://api.weatherapi.com/v1/current.json?key=${config.weatherApiKey}&q=${args.join(' ').replaceAll(' ','&')}`); const info = await weather.body.json(); - component.push({ - translate: "%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s%s (%s%s)\n%s: %s %s %s (%s %s %s)\n%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Location", color: config.colors.commands.primary }, - { text: `${info.location.name}, ${info.location.region}, ${info.location.country}`, color: config.colors.commands.secondary }, - { text: "Latitude", color: config.colors.commands.primary }, - { text: `${info.location.lat}`, color: config.colors.integer }, - { text: "Longitude", color: config.colors.commands.primary }, - { text: `${info.location.lon}`, color: config.colors.integer }, - { text: "Time zone", color: config.colors.commands.primary }, - { text: `${info.location.tz_id}`, color: config.colors.commands.secondary }, - { text: "Time", color: config.colors.commands.primary }, - { text: `${new Date().toLocaleTimeString("en-US", { timeZone: info.location.tz_id, })}`, color: config.colors.integer }, - { text: "Temp", color: config.colors.commands.primary }, - { text: `${info.current.temp_c}`, color: config.colors.integer }, - { text: "\u00b0C", color: config.colors.commands.secondary }, - { text: `${info.current.temp_f}`, color: config.colors.integer }, - { text: "\u00b0F", color: config.colors.commands.secondary }, - { text: "Wind speed" , color: config.colors.commands.primary }, - { text: `${info.current.wind_kph}`, color: config.colors.integer }, - { text: `kph`, color: config.colors.commands.secondary }, - { text: `${info.current.wind_dir}`, color: config.colors.commands.secondary }, - { text: `${info.current.wind_mph}`, color: config.colors.integer }, - { text: `mph`, color: config.colors.commands.secondary }, - { text: `${info.current.wind_dir}`, color: config.colors.commands.secondary }, - { text: "Condition", color: config.colors.commands.primary }, - { text: `${info.current.condition.text}`, color: config.colors.commands.secondary }, - { text: "Humidity", color: config.colors.commands.primary }, - { text: `${info.current.humidity}`, color: config.colors.integer }, - ] - }) - bot.tellraw("@a", component) + component = new MessageBuilder() + .setTranslate("%s\n%s\n%s: %s (%s)\n%s\n%s\n%s: %s\n%s: %s") + .setColor(config.colors.commands.tertiary) + .addWith(new MessageBuilder() + .setTranslate("%s: %s, %s %s") + .setColor(config.colors.commands.tertiary) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Location") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(info.location.name) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(info.location.region) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(info.location.country) + ) + ) + .addWith(new MessageBuilder() + .setTranslate("%s: %s, %s") + .setColor(config.colors.commands.tertiary) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Coords") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${info.location.lat}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${info.location.lon}`) + ) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Time") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(`${new Date().toLocaleTimeString("en-US", { timeZone: info.location.tz_id, })}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(`${info.location.tz_id}`) + ) + .addWith(new MessageBuilder() + .setTranslate("%s: %s (%s), %s (%s)") + .setColor(config.colors.commands.tertiary) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Temp") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(info.current.temp_c)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("\u00b0C") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(info.current.temp_f)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("\u00b0F") + ) + ) + .addWith(new MessageBuilder() + .setTranslate("%s: %s (%s, %s), %s (%s, %s)") + .setColor(config.colors.commands.tertiary) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Wind Speed") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(info.current.wind_kph)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("kph") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(info.current.wind_dir) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(info.current.wind_mph)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("mph") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(info.current.wind_dir) + ) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Condition") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText(info.current.condition.text) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Humidity") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(info.current.humidity)}`) + ) + if (bot.options.isSavage) { + bot.chat.message(`Location: ${info.location.name}, ${info.location.region}, ${info.location.country}`); + bot.chat.message(`Latitude: ${info.location.lat}`); + bot.chat.message(`Longitude: ${info.location.lon}`); + bot.chat.message(`Time: ${new Date().toLocaleTimeString("en-US", { timeZone: info.location.tz_id, })}(${info.location.tz_id})`); + bot.chat.message(`Temp: ${info.current.temp_c}(\u00b0C), ${info.current.temp_f}(\u00b0F)`); + bot.chat.message(`Wind speed: ${info.current.wind_kph}(KPH), ${info.current.wind_mph}(MPH)`); + bot.chat.message(`Condition: ${info.current.condition.text}`); + bot.chat.message(`Humidity: ${info.current.humidity}`); + } else { + bot.tellraw("@a", component); + } } catch (e) { if (e.toString() === "TypeError: Cannot read properties of undefined (reading 'name')" && args.length !== 0) { bot.chat.message('The location is invalid please try a valid location'); diff --git a/src/commands/public/wiki.js b/src/commands/public/wiki.js index 83f8276..4aaccfe 100644 --- a/src/commands/public/wiki.js +++ b/src/commands/public/wiki.js @@ -17,13 +17,20 @@ module.exports = { const source = context.source; const args = context.arguments; const bot = context.bot; + const { MessageBuilder } = require('prismarine-chat')(bot.options.version); try { const page = await wiki.page(args.join(' ')) const summary = await page.intro(); - bot.tellraw(`@a`, { text: `${summary}`, color: 'gray' }); + bot.tellraw("@a", new MessageBuilder() + .setText(summary) + .setColor("gray") + ) } catch (error) { if (error.toString() === "pageError: TypeError: Cannot read properties of undefined (reading 'pages')") { - bot.tellraw(`@a`, { text: 'Article not found!', color: 'dark_red' }) + bot.tellraw("@a", new MessageBuilder() + .setText("Article not found!") + .setColor("red") + ) } else { bot.tellraw(`@a`, `${error.toString()}`) } diff --git a/src/data/default_config.yml b/src/data/default_config.yml index 603199f..b96f5f4 100644 --- a/src/data/default_config.yml +++ b/src/data/default_config.yml @@ -78,6 +78,11 @@ colors: console: prefix: "c." +logsFolder: + path: "../../" + # this is being loaded from the log folder so make sure it starts with ../../ + name: "logs" + bots: - host: "localhost" username: "FNFBoyfriendBot" diff --git a/src/index.js b/src/index.js index 06123e7..0ac5376 100644 --- a/src/index.js +++ b/src/index.js @@ -1,19 +1,25 @@ const createBot = require('./bot.js'); const readline = require('readline'); -const loadModules = require('./util/loadModules'); const js_yaml = require('js-yaml'); const fs = require('fs'); const path = require('path'); const { Client, GatewayIntentBits } = require('discord.js'); const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits; const discordClient = new Client({ intents: [Guilds, GuildMessages, MessageContent] }); -require('./util/checks')(); console.log('Starting FNFBoyfriendBot'); process.stdout.write('\x1b]2;Starting FNFBoyfriendBot please wait,.....\x1b\x5c'); +if (!fs.existsSync(path.join(__dirname, "../config.yml"))) { + console.warn("Config not found creating config from the default config"); + fs.copyFileSync( + path.join(__dirname, "./data/default_config.yml"), + path.join(__dirname, "../config.yml") + ) +} + try { - config = js_yaml.load(fs.readFileSync(path.join(__dirname, '../', 'config.yml'))) + config = require('js-yaml').load(fs.readFileSync(path.join(__dirname, '../', 'config.yml'))) } catch (e) { console.log(e.stack); } @@ -29,6 +35,6 @@ for (const options of config.bots) { const bot = new createBot(options, config); bots.push(bot); bot.bots = bots; - loadModules(bot, options, config, discordClient); + require('./util/loadModules')(bot, options, config, discordClient); bot.console.readlineInterface(rl); } diff --git a/src/modules/chat.js b/src/modules/chat.js index be7c323..2708a00 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -89,9 +89,11 @@ function chat (context) { return } - bot.emit('systemChat', message) + if (message.translate === "advMode.notAllowed") return; - tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }) + bot.emit('systemChat', message); + + tryParsingMessage(message, { players: bot.players, getMessageAsPrismarine: bot.getMessageAsPrismarine }); }) bot.on('packet.action_bar', (message) => { @@ -165,8 +167,9 @@ function chat (context) { acknowledged: Buffer.alloc(3), previousMessages: [] }) - } + }, } + bot.tellraw = (selector, message) => { bot.core.run(`minecraft:tellraw ${selector} ` + JSON.stringify(message)) } diff --git a/src/modules/chat_command_handler.js b/src/modules/chat_command_handler.js index eb41e1d..e5e9e38 100644 --- a/src/modules/chat_command_handler.js +++ b/src/modules/chat_command_handler.js @@ -4,6 +4,7 @@ module.exports = (context) => { const bot = context.bot; const config = context.config; const options = context.options; + const { MessageBuilder } = require('prismarine-chat')(bot.options.version); bot.on("parsed_message", (data) => { if (data.type !== "minecraft:chat") return; const prefixes = config.prefixes; @@ -16,8 +17,9 @@ module.exports = (context) => { setTimeout(() => { ratelimit-- }, 1000) - if (ratelimit > 2) { - bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, { text: 'You are using commands too fast!', color: 'dark_red'}) + if (ratelimit > 2) { // new e.MessageBuilder().setText("e").toJSON() + bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, new MessageBuilder().setText("You are using commands too fast!").setColor("dark_red").toJSON()) +// bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, { text: 'You are using commands too fast!', color: 'dark_red'}) } else if (command.split(" ")[0].length === 0) { } else { bot.commandManager.executeString(source, command) diff --git a/src/modules/command_core.js b/src/modules/command_core.js index 6456629..0a2470e 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -49,11 +49,7 @@ function core (context) { bot.chat.command('spawn'); return } - /*^^^ - for checking is the core pos is null and if so - it will not refill core until the pos is not NaN - instead of tping to a set cords cuz fuck you im not doing that - */ + const command = `minecraft:fill ${pos.x + start.x} ${pos.y + start.y} ${pos.z + start.z} ${pos.x + end.x} ${pos.y + end.y} ${pos.z + end.z} repeating_command_block{CustomName:'${JSON.stringify(config.core.name)}'} destroy` bot._client.write('set_creative_slot', { @@ -185,13 +181,7 @@ function core (context) { }) bot.on('packet.block_change', (data) => { -// console.log('data pos ' + JSON.stringify(data.location)) -// console.log('core pos ' +JSON.stringify(bot.core.position)); - // if (data.type === 0) { -// console.log('data pos ' + JSON.stringify(data.location)); -// console.log('core position ' + JSON.stringify(bot.core.position)); -// bot.core.refill(); - //} + }) } module.exports = core; diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js index b456e20..04e02cd 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -9,6 +9,7 @@ async function command_manager (context) { const config = context.config; const discordClient = context.discordClient; const options = context.options; + const { MessageBuilder } = require('prismarine-chat')(bot.options.version); bot.commandManager = { commands: {}, commandlist: [], @@ -25,16 +26,33 @@ async function command_manager (context) { } } else if (!source?.sources?.discord && !source?.sources?.console) { if (!command || !command.execute) - bot.tellraw("@a", { - translate: "%s%s%s %s", - color: "dark_gray", - with: [ - { translate: "command.unknown.command", color: "red" }, - { text: "\n" }, - { text: `${commandName}` }, - { translate: "command.context.here", color: "red" } - ] - }) + if (bot.options.isSavage) { + bot.chat.message(bot.getMessageAsPrismarine({ + translate: "%s", + color: "dark_gray", + with: [ + { translate: "command.unknown.command", color: "red" }, + ] + })?.toMotd().replaceAll('§','&')); + + bot.chat.message(bot.getMessageAsPrismarine({ + translate: "%s %s", + color: "dark_gray", + with: [ + { text: `${commandName}` }, + { translate: "command.context.here", color: "red" } + ] + })?.toMotd().replaceAll('§','&')); + } else { + bot.tellraw("@a", new MessageBuilder() + .setTranslate("%s%s%s %s") + .setColor("dark_gray") + .addWith(new MessageBuilder().setTranslate("command.unknown.command").setColor("red")) + .addWith(new MessageBuilder().setText("\n")) + .addWith(new MessageBuilder().setText(`${commandName}`)) + .addWith(new MessageBuilder().setTranslate("command.context.here").setColor("red")) + ) + } } else if (source?.sources?.console && !source?.sources?.discord) { if (!command || !command.execute) bot.console.warn(bot.getMessageAsPrismarine({ diff --git a/src/modules/command_suggestion.js b/src/modules/command_suggestion.js new file mode 100644 index 0000000..3efcdcf --- /dev/null +++ b/src/modules/command_suggestion.js @@ -0,0 +1,44 @@ +function commandsuggestions(context) { + const bot = context.bot + if (!bot.options.isKaboom) return + bot.on('systemChat',(data)=>{ + try { + const message = data; + if (message.text === "fnfboyfriendbot_request_command_suggestion") { + const extra = message.extra; + const uuidString = extra[0]?.text; + const uuidMatch = uuidString.match(/UUID:\[I;(-?\d+),(-?\d+),(-?\d+),(-?\d+)\]/); + if (!uuidMatch) return; + if (Array.isArray(extra) && extra.length > 0) { + const commandSuggestions = { + extra: [ + { text: "fnfboyfriendbot_request_command_suggestion" }, + ...bot.commandManager.commandlist.map((c) => { + const aliases = c.data.aliases.length > 0 ? c.data.aliases : []; + return { + extra: [ + c.data.trustLevel === 0 ? "PUBLIC" : + c.data.trustLevel === 1 ? "TRUSTED" : + c.data.trustLevel === 2 ? "ADMIN" : + c.data.trustLevel === 3 ? "OWNER" : + "OWNER", + "true", + ...aliases + ], + text: c.data.name + }; + }) + ], + text: "" + }; + const jsonString = (commandSuggestions); + bot.tellraw(`@a[nbt={UUID:[I;${uuidMatch.slice(1).map(Number)}]}]`, jsonString) + } + } + } catch (e) { + if (e.toString() === "TypeError: Cannot read properties of undefined (reading '0')") return + else console.log(e.toString()) + } + }) +} +module.exports = commandsuggestions diff --git a/src/modules/discord.js b/src/modules/discord.js index 8731171..b15551b 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -22,8 +22,6 @@ function discord (context) { channel: undefined, invite: config.discord.invite || undefined, prefix: config.discord.prefix, -// presence: bot.discord.presence, -// token: config.discord.token, } discordClient.once('ready', (context) => { bot.discord.channel = discordClient.channels.cache.get(options.channelId) @@ -72,9 +70,6 @@ function discord (context) { bot.on('playerChat', (message) => { sendComponent(message); }) -/* bot.on('message', message => { - sendComponent(message) - })*/ function messageCreate(message, source) { bot.discord.message = message; diff --git a/src/modules/fileLogger.js b/src/modules/fileLogger.js index 11fa9b3..693c152 100644 --- a/src/modules/fileLogger.js +++ b/src/modules/fileLogger.js @@ -11,15 +11,13 @@ function fileLogger(context) { const timestamp = `${currentDate.getFullYear()}-${(currentDate.getMonth() + 1) .toString() .padStart(2, "0")}-${currentDate.getDate().toString().padStart(2, "0")}`; - const logFolder = path.join(__dirname, "../../logs"); + const logFolder = path.join(__dirname, `${config.logsFolder.path}`, `${config.logsFolder.name}`); 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)) { + console.info(`logs folder not found recreating it at ${config.logsFolder.path}${config.logsFolder.name}`); fs.mkdirSync(logFolder); } } catch (e) { @@ -27,7 +25,6 @@ function fileLogger(context) { } function compressFile(input, output) { -// if (!bot.Console.filelogging) return const plainOutput = output.slice(0, -3); fs.renameSync(input, plainOutput); diff --git a/src/modules/memusage.js b/src/modules/memusage.js index f38d783..1063fe5 100644 --- a/src/modules/memusage.js +++ b/src/modules/memusage.js @@ -2,13 +2,72 @@ const os = require('os'); module.exports = (context) => { const bot = context.bot; const config = context.config; + const { MessageBuilder } = require('prismarine-chat')(bot.options.version); let timer; bot.memUsage = { enabled: false } timer = setInterval(() => { - component = { + component = new MessageBuilder() + .setTranslate("%s%s%s %s | %s: %s%s / %s%s | %s: %s%s / %s%s |") + .setColor(config.colors.commands.tertiary) + .addWith(new MessageBuilder() + .setColor("dark_blue") + .setText("FNF") + ) + .addWith(new MessageBuilder() + .setColor("dark_aqua") + .setText("Boyfriend") + ) + .addWith(new MessageBuilder() + .setColor("blue") + .setText("Bot") + ) + .addWith(new MessageBuilder() + .setText("Memory Usage") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Free Server Memory") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(os.freemem() / 1048576)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("MiB") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(os.totalmem() / 1048576)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("MiB") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.primary) + .setText("Bot Memory Usage") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(process.memoryUsage().heapUsed / 1048576)}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("MiB") + ) + .addWith(new MessageBuilder() + .setColor(config.colors.integer) + .setText(`${Math.floor(process.memoryUsage().heapTotal / 1048576 )}`) + ) + .addWith(new MessageBuilder() + .setColor(config.colors.commands.secondary) + .setText("MiB") + ) +/* component = { translate: "%s%s%s %s | %s: %s%s / %s%s | %s: %s%s / %s%s |", color: config.colors.commands.tertiary, with: [ @@ -27,7 +86,7 @@ module.exports = (context) => { { text: `${Math.floor(process.memoryUsage().heapTotal / 1048576 )}`, color: config.colors.integer }, { text: "MiB", color: config.colors.commands.secondary } ] - } + }*/ if (!bot.memUsage.enabled) return; bot.core.run(`minecraft:title @a[tag=!memusage] actionbar ${JSON.stringify(component)}`) }, 100) diff --git a/src/modules/reconnect.js b/src/modules/reconnect.js index 67e8fb3..94929a8 100644 --- a/src/modules/reconnect.js +++ b/src/modules/reconnect.js @@ -5,11 +5,7 @@ function reconnect (context) { const config = context.config; const options = context.options; bot.on('end', () => { - //bot = undefined; - bot._client.removeAllListeners(); - //client = undefined; - //bot._client = undefined; if (bot.reconnectDelay < 0) return setTimeout(() => { if (options.usernameGen) { diff --git a/src/modules/team.js b/src/modules/team.js index ee9c85a..108e262 100644 --- a/src/modules/team.js +++ b/src/modules/team.js @@ -21,9 +21,9 @@ module.exports = (context) => { data?.players?.map(async (player) => { if (player !== bot.options.username) { await sleep(100); - bot.core.run(`minecraft:team empty ${config.team.name}`); +// bot.core.run(`minecraft:team empty ${config.team.name}`); await sleep(100); - bot.core.run(`minecraft:team join ${config.team.name} @a[name="${bot.options.username}"]`); +// bot.core.run(`minecraft:team join ${config.team.name} @a[name="${bot.options.username}"]`); // this removes players who are not the bot } }); diff --git a/src/util/checks.js b/src/util/checks.js deleted file mode 100644 index 29c8e99..0000000 --- a/src/util/checks.js +++ /dev/null @@ -1,23 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const { execSync } = require('child_process'); -const { request } = require('undici'); -module.exports = async () => { - let url = await request('https://code.chipmunk.land/api/v1/repos/Parker2991/FridayNightFunkinBoyfriendBot/commits'); - let data = await url.body.json(); - let output = data[0] - let gitCommit = execSync('git rev-parse HEAD').toString().replaceAll('\n', '').substring(0, 10); - let urlCommit = output.sha.substring(0, 10); - if (gitCommit !== urlCommit) { - console.log('This build of the bot is not up to date! please update the bot at "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot" for the latest patches and new addons'); - // this will check if the copy of the bot is up to date - } // i got bored and made this check now cry about it - - if (!fs.existsSync(path.join(__dirname, "../../config.yml"))) { - console.warn("Config not found creating config from the default config"); - fs.copyFileSync( - path.join(__dirname, "../data/default_config.yml"), - path.join(__dirname, "../../config.yml") - ) - } -}