diff --git a/src/commands/admin/kick.js b/src/commands/admin/kick.js new file mode 100644 index 0000000..ca9ba39 --- /dev/null +++ b/src/commands/admin/kick.js @@ -0,0 +1,55 @@ +const CommandError = require('../../util/command_error'); + + +module.exports = { + data: { + name: "kick", + description: "kick a player from the server", + aliases: [ + + ], + trustLevel: 2, + usages: [ + "invalidstring", + "item" + ] + }, + execute (context) { + const bot = context.bot; + const args = context.arguments; + const config = context.config; + + if (!args && !args[0] && !args[1] && !args[2]) return; + switch (args[1]?.toLowerCase()) { + case "invalidstring": + bot.exploits.crashes.invalidString(args[2]); + bot.chat.message(`crashing ${args[2]}`) + break; + case "item": + bot.exploits.kicks.item(args[2]); + bot.chat.message(`kicking ${args[2]}`) + break; + default: + throw new CommandError('invalid argument') + } + }, + discordExecute (context) { + const bot = context.bot; + const args = context.arguments; + const config = context.config; + + if (!args && !args[0] && !args[1] && !args[2]) return; + switch (args[0]?.toLowerCase()) { + case "invalidstring": + bot.exploits.crashes.invalidString(args[1]); + bot?.discord?.message?.reply(`crashing ${args[1]}`) + break; + case "item": + bot.exploits.kicks.item(args[1]); + bot?.discord?.message?.reply(`kicking ${args[1]}`) + break; + default: + throw new CommandError('invalid argument') + } + } +} \ No newline at end of file diff --git a/src/commands/owner/servereval.js b/src/commands/owner/servereval.js index bd6bf50..980cdfa 100644 --- a/src/commands/owner/servereval.js +++ b/src/commands/owner/servereval.js @@ -24,31 +24,24 @@ module.exports = { try { if (source.sources.console) { bot.console.log(bot.getMessageAsPrismarine({ text: util.inspect(eval(args.join(' ')), { stylize })})?.toAnsi()) - } else if (bot.options.useChat || bot.options.isSavage) { + } else if (bot.options.mode === "savageFriends") { bot.chat.message(bot.getMessageAsPrismarine({ text: util.inspect(eval(script), { stylize }).substring(0, 32700) })?.toMotd().replaceAll('§','&')) } else { - bot.tellraw(`@a[name="${source.player.profile.name}"]`, new MessageBuilder() - .setText(util.inspect(eval(script), { stylize }).substring(0, 32700)) - ) -/* bot.tellraw(`@a[name="${source.player.profile.name}"]`, [ - { - text: util.inspect(eval(script), { stylize }).substring(0, 32700), - hoverEvent: { - action: 'show_text', - contents: [{ - text: 'click here to copy the code input', - color: 'gray' - }] - }, - clickEvent: { - action: 'copy_to_clipboard', - value: `${script}` - } - } - ]);*/ + bot.tellraw(`@a[name="${source.player.profile.name}"]`, { + text: `${util.inspect(eval(script), { stylize }).substring(0, 32700)}` + }); } } catch (e) { throw new CommandError(e.toString()) } + }, + discordExecute (context) { + const bot = context.bot; + const args = context.arguments; + try { + bot?.discord?.message?.reply(`\`\`\`js\n${util.inspect(eval(args.join(' '))).toString().substring(0, 1980)}\`\`\``); + } catch (e) { + throw new CommandError(e.toString()); + } } } diff --git a/src/commands/public/echo.js b/src/commands/public/echo.js index 135b08f..4037889 100644 --- a/src/commands/public/echo.js +++ b/src/commands/public/echo.js @@ -19,6 +19,7 @@ module.exports = { discordExecute (context) { const bot = context.bot; const args = context.arguments; + bot.discord.message.channel.send(args.join(' ')); bot.chat.send(args.join(' ')); } } diff --git a/src/commands/public/help.js b/src/commands/public/help.js index 38386fc..72e45ac 100644 --- a/src/commands/public/help.js +++ b/src/commands/public/help.js @@ -118,6 +118,8 @@ module.exports = { const EmbedBuilder = context.EmbedBuilder const fixansi = context.fixansi; const args = context.arguments; + let infoComponent = []; + let usagesComponent = []; let public = []; let trusted = []; let admin = []; @@ -142,6 +144,38 @@ module.exports = { Console.push(commands.data.name); break; } + if (args[0] === commands.data.name) { + for (const usages of commands.data.usages) { + usagesComponent.push({ + translate: "%s%s %s", + with: [ + { text: `${config.prefixes[0]}`, color: config.colors.commands.primary }, + { text: `${commands.data.name}`, color: config.colors.commands.secondary }, + { text: `${usages}`, color: config.colors.commands.secondary }, + ] + }) + usagesComponent.push('\n'); + } + + infoComponent.push({ + translate: "%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s:\n", + color: config.colors.commands.tertiary, + with: [ + { text: "Name", color: config.colors.commands.primary }, + { text: `${commands.data.name}`, color: config.colors.commands.secondary }, + { text: "Aliases", color: config.colors.commands.primary }, + { text: `${commands.data.aliases.toString().replaceAll(',',' ')}`, color: config.colors.commands.secondary }, + { text: "Description", color: config.colors.commands.primary }, + { text: `${commands.data.description}`, color: config.colors.commands.secondary }, + { text: "Trust Level", color: config.colors.commands.primary }, + { text: `${commands.data.trustLevel}`, color: config.colors.integer }, + { text: "Usages", color: config.colors.commands.primary }, + ] + }); + infoComponent.push(usagesComponent); + bot?.discord?.message?.reply(`\`\`\`ansi\n${fixansi(bot.getMessageAsPrismarine(infoComponent)?.toAnsi()?.replaceAll('`', '`\u200b'))}\`\`\``); + return; + } } let commandsEmbed = new EmbedBuilder() diff --git a/src/commands/public/info.js b/src/commands/public/info.js index a5e2e5c..a045178 100644 --- a/src/commands/public/info.js +++ b/src/commands/public/info.js @@ -17,6 +17,336 @@ function format(seconds) { pad(`${seconds} Seconds`)) } +function componentPush (bot, args, config, discordClient, source, component) { + switch (args[0]?.toLowerCase()) { + case "about": + component.push({ + text: `FNFBoyfriendBot is a kaboom bot created by Parker2991\nThe source code and changelog can be found here ${botInfo.buildstring.url}`, + color: `${config.colors.commands.primary}`, + translate: "", + hoverEvent: { + action: "show_text", + value: [ + { text: "click here to view bots source code", color: `${config.colors.commands.primary}` } + ] + }, + clickEvent: { + action: "open_url", + value: `${botInfo.buildstring.url}` + } + }) + break; + case "config": + if (bot.options.isKaboom) { + mode = "Kaboom"; + } if (bot.options.useChat && bot.options.isKaboom) { + mode = "Kaboom/Coreless"; + } if (bot.options.isSavage) { + mode = "Savage"; + } if (bot.options.isCreayun) { + mode = "Creayun"; + } + switch (args.slice(1).join(' ')?.toLowerCase()) { + case "client": + component.push({ + translate: "%s: %s:%s\n%s: %s\n%s: %s\n%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Server", color: config.colors.commands.primary }, + { text: `${bot.options.host}`, color: config.colors.commands.secondary }, + { text: `${bot.options.port}`, color: config.colors.integer }, + { text: "Server Name", color: config.colors.commands.primary }, + { text: `${bot.options.serverName}`, color: config.colors.commands.secondary }, + { text: "Minecraft Username", color: config.colors.commands.primary }, + { text: `${bot.options.username}`, color: config.colors.commands.secondary }, + { text: "Version", color: config.colors.commands.primary }, + { text: `${bot.options.version}`, color: config.colors.integer }, + ] + }) + break; + case "discord": + if (!config.discord.enabled || discordClient.user === null) { + throw new CommandError('Token is incorrect or discord isnt enabled!') + } else { + component.push({ + translate: "%s: %s\n%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Discord Username", color: config.colors.commands.primary }, + { text: `${discordClient.user.tag}`, color: config.colors.commands.secondary }, + { text: "Discord Channel", color: config.colors.commands.primary }, + { text: `${bot.discord?.channel?.name}`, color: config.colors.commands.secondary }, + ] + }) + } + break; + case "options": + component.push({ + translate: "%s: %s\n%s: %s\n%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Server Count", color: config.colors.commands.primary }, + { text: `${bot.bots.length}`, color: config.colors.integer }, + { text: "Prefixes", color: config.colors.commands.primary }, + { text: `${config.prefixes.map((e) => e + " ").join(' ')}`, color: config.colors.commands.secondary }, + { text: "Mode", color: config.colors.commands.primary }, + { text: `${bot.options.mode}`, color: config.colors.commands.secondary }, + ] + }) + break; + case "all": + component.push({ + translate: "%s: %s:%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Server", color: config.colors.commands.primary }, + { text: `${bot.options.host}`, color: config.colors.commands.secondary }, + { text: `${bot.options.port}`, color: config.colors.integer }, + { text: "Server Name", color: config.colors.commands.primary }, + { text: `${bot.options.serverName}`, color: config.colors.commands.secondary }, + { text: "Minecraft Username", color: config.colors.commands.primary }, + { text: `${bot.options.username}`, color: config.colors.commands.secondary }, + { text: "Version", color: config.colors.commands.primary }, + { text: `${bot.options.version}`, color: config.colors.commands.secondary }, + { text: "Discord Username", color: config.colors.commands.primary }, + { text: `${discordClient.user?.tag}`, color: config.colors.commands.secondary }, + { text: "Discord Channel", color: config.colors.commands.primary }, + { text: `${bot.discord.channel?.name}`, color: config.colors.commands.secondary }, + { text: "Server Count", color: config.colors.commands.primary }, + { text: `${bot.bots.length}`, color: config.colors.integer }, + { text: "Prefixes", color: config.colors.commands.primary }, + { text: `${config.prefixes.map((e) => e + " ").join(' ')}`, color: config.colors.commands.secondary }, + { text: "Mode", color: config.colors.commands.primary }, + { text: `${bot.options.mode}`, color: config.colors.commands.secondary } + ] + }) + break; + default: + throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); + } + break; + case "contributors": + case "credits": + component.push({ + translate: "%s%s - %s\n%s:\n%s\n%s\n%s\n%s\n%s %s\n%s\n%s", + color: config.colors.commands.tertiary, + with: [ + { text: "Parker", color: "dark_red" }, + { text: "2991", color: "black" }, + { text: "Owner" }, + { text: "Contributors" }, + { text: "_ChipMC_", color: "dark_blue" }, + { text: "chayapak", color: "yellow" }, + { text: "_yfd", color: "light_purple" }, + { text: "aaa", color: "gold" }, + { text: "Morgan", color: "green" }, + { text: "Ankan", color: "dark_green" }, + { text: "TurtleKid", color: "green" }, + { text: "Ploat/ImGloriz", color: "#cd8ccb" }, + ] + }) + break; + case "discord": + component.push({ + text: `the discord server invite is ${config.discord.invite}`, + color: config.colors.commands.primary, + translate: "", + hoverEvent: { + action: "show_text", + value: [ + { + text: "click here to join the discord server!", + color: config.colors.commands.secondary, + } + ] + }, + clickEvent: { + action: "open_url", + value: `${config.discord.invite}` + } + }) + break; + case "loaded": + component.push({ + translate: "%s %s\n%s %s", + color: config.colors.commands.tertiary, + with: [ + { text: `${bot.commandManager.commandlist.length}`, color: config.colors.integer }, + { text: "Commands", color: config.colors.commands.primary }, + { text: `${bot.modules.length}`, color: config.colors.integer }, + { text: "Modules", color: config.colors.commands.primary } + ] + }); + break; + case "usages": + case "usage": + switch (args.slice(1).join(' ')?.toLowerCase()) { + case "bot": + component.push({ + translate: "%s: %s %s / %s %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Bot Memory Usage", color: config.colors.commands.primary }, + { text: `${Math.floor(process.memoryUsage().heapUsed / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: `${Math.floor(process.memoryUsage().heapTotal / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary } + ] + }) + break; + case "server": + component.push({ + translate: "%s: %s %s / %s %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Free Server Memory", color: config.colors.commands.primary }, + { text: `${Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: `${Math.floor(os.totalmem() / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + ] + }) + break; + case "all": + component.push({ + translate: "%s: %s %s / %s %s\n%s: %s %s / %s %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Free Server Memory", color: config.colors.commands.primary }, + { text: `${Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: `${Math.floor(os.totalmem() / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: "Bot Memory Usage", color: config.colors.commands.primary }, + { text: `${Math.floor(process.memoryUsage().heapUsed / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: `${Math.floor(process.memoryUsage().heapTotal / 1048576 )}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary } + ] + }) + break; + default: + throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); + } + break; + case "uptimes": + switch (args.slice(1).join(' ')?.toLowerCase()) { + case "bot": + component.push({ + translate: "%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Bot Uptime", color: config.colors.commands.primary }, + { text: `${format(process.uptime())}`, color: config.colors.commands.secondary }, + ] + }) + break; + case "server": + component.push({ + translate: "%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Server Uptime", color: config.colors.commands.primary }, + { text: `${format(os.uptime())}`, color: config.colors.commands.secondary }, + ] + }) + break; + case "all": + component.push({ + translate: "%s: %s\n%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Bot Uptime", color: config.colors.commands.primary }, + { text: `${format(process.uptime())}`, color: config.colors.commands.secondary }, + { text: "Server Uptime", color: config.colors.commands.primary }, + { text: `${format(os.uptime())}`, color: config.colors.commands.secondary }, + ] + }) + break; + throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); + } + break; + case "server": + component.push({ + translate: "%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", + color: config.colors.commands.tertiary, + with: [ + { text: "Hostname", color: config.colors.commands.primary }, + { text: `${os.hostname()}`, color: config.colors.commands.secondary }, + { text: "User", color: config.colors.commands.primary }, + { text: `${os.userInfo().username}`, color: config.colors.commands.secondary }, + { text: "Working Directory", color: config.colors.commands.primary }, + { text: `${require.main.path}`, color: config.colors.commands.secondary }, + { text: "Arch", color: config.colors.commands.primary }, + { text: `${os.arch()}`, color: config.colors.commands.secondary }, + { text: "OS", color: config.colors.commands.primary }, + { text: `${os.platform}`, color: config.colors.commands.secondary }, + { text: "OS Version", color: config.colors.commands.primary }, + { text: `${os.version()}`, color: config.colors.commands.secondary }, + { text: "Kernel Version", color: config.colors.commands.primary }, + { text: `${os.release()}`, color: config.colors.commands.secondary }, + { text: "CPU", color: config.colors.commands.primary }, + { text: `${os.cpus()[0].model}`, color: config.colors.commands.secondary }, + { text: "CPU cores", color: config.colors.commands.primary }, + { text: `${os.cpus().length}`, color: config.colors.integer }, + { text: "Node Version", color: config.colors.commands.primary }, + { text: `${process.version}`, color: config.colors.commands.secondary }, + { text: "NPM Version", color: config.colors.commands.primary }, + { text: `${execSync('npm -v').toString().replaceAll('\n', '')}`, color: config.colors.commands.secondary }, + ] + }) + break; + case "version": + case "ver": + if (botInfo.buildstring.codename.length > 0) { + component.push({ + translate: "%s %s %s-%s-%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s-%s", + color: config.colors.commands.tertiary, + with: [ + { text: "Friday Night Funkin", color: "dark_blue" }, + { text: "Boyfriend", color: "dark_aqua" }, + { text: "Bot", color: "blue" }, + { text: `${botInfo.buildstring.version}`, color: config.colors.integer }, + botInfo.buildstring.codename, + { text: "Build", color: config.colors.commands.primary }, + { text: `${botInfo.buildstring.build}`, color: config.colors.integer }, + { text: "Repo Build", color: config.colors.commands.primary }, + { text: `${execSync('git rev-list --count --all').toString().replaceAll('\n','')}`, color: config.colors.integer }, + { text: "Version Release Date", color: config.colors.commands.primary }, + { text: `${new Date(execSync('git log -1 --format=%ci').toString()).toLocaleString("en-US", {timeZone: "America/CHICAGO"})}`, color: config.colors.commands.secondary }, + { text: "Commit", color: config.colors.commands.primary }, + { text: `${execSync("git rev-parse HEAD").toString().substring(0, 10)}`, color: config.colors.commands.secondary }, + { text: "11/22/22", color: config.colors.commands.primary }, + { text: `${new Date().toLocaleDateString("en-US",{timeZone:"America/CHICAGO"})}`, color: config.colors.commands.secondary }, + ] + }); + } else { + component.push({ + translate: "%s %s %s-%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s-%s", + color: config.colors.commands.tertiary, + with: [ + { text: "Friday Night Funkin", color: "dark_blue" }, + { text: "Boyfriend", color: "dark_aqua" }, + { text: "Bot", color: "blue" }, + { text: `${botInfo.buildstring.version}`, color: config.colors.integer }, + { text: "Build", color: config.colors.commands.primary }, + { text: `${botInfo.buildstring.build}`, color: config.colors.integer }, + { text: "Repo Build", color: config.colors.commands.primary }, + { text: `${execSync('git rev-list --count --all').toString().replaceAll('\n','')}`, color: config.colors.integer }, + { text: "Version Release Date", color: config.colors.commands.primary }, + { text: `${new Date(execSync('git log -1 --format=%ci').toString()).toLocaleString("en-US", {timeZone: "America/CHICAGO"})}`, color: config.colors.commands.secondary }, + { text: "Commit", color: config.colors.commands.primary }, + { text: `${execSync("git rev-parse HEAD").toString().substring(0, 10)}`, color: config.colors.commands.secondary }, + { text: "11/22/22", color: config.colors.commands.primary }, + { text: `${new Date().toLocaleDateString("en-US",{timeZone:"America/CHICAGO"})}`, color: config.colors.commands.secondary }, + ] + }); + } + break; + default: + throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); + } +} module.exports = { data: { name: 'info', @@ -44,338 +374,28 @@ module.exports = { const discordClient = context.discordClient; const source = context.source; let component = []; - switch (args[0]?.toLowerCase()) { - case "about": - component.push({ - text: `FNFBoyfriendBot is a kaboom bot created by Parker2991\nThe source code and changelog can be found here ${botInfo.buildstring.url}`, - color: `${config.colors.commands.primary}`, - translate: "", - hoverEvent: { - action: "show_text", - value: [ - { text: "click here to view bots source code", color: `${config.colors.commands.primary}` } - ] - }, - clickEvent: { - action: "open_url", - value: `${botInfo.buildstring.url}` - } - }) - break; - case "config": - if (bot.options.isKaboom) { - mode = "Kaboom"; - } if (bot.options.useChat && bot.options.isKaboom) { - mode = "Kaboom/Coreless"; - } if (bot.options.isSavage) { - mode = "Savage"; - } if (bot.options.isCreayun) { - mode = "Creayun"; - } - switch (args.slice(1).join(' ')?.toLowerCase()) { - case "client": - component.push({ - translate: "%s: %s:%s\n%s: %s\n%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Server", color: config.colors.commands.primary }, - { text: `${bot.options.host}`, color: config.colors.commands.secondary }, - { text: `${bot.options.port}`, color: config.colors.integer }, - { text: "Server Name", color: config.colors.commands.primary }, - { text: `${bot.options.serverName}`, color: config.colors.commands.secondary }, - { text: "Minecraft Username", color: config.colors.commands.primary }, - { text: `${bot.options.username}`, color: config.colors.commands.secondary }, - { text: "Version", color: config.colors.commands.primary }, - { text: `${bot.options.version}`, color: config.colors.integer }, - ] - }) - break; - case "discord": - if (!config.discord.enabled || discordClient.user === null) { - throw new CommandError('Token is incorrect or discord isnt enabled!') - } else { - component.push({ - translate: "%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Discord Username", color: config.colors.commands.primary }, - { text: `${discordClient.user.tag}`, color: config.colors.commands.secondary }, - { text: "Discord Channel", color: config.colors.commands.primary }, - { text: `${bot.discord?.channel?.name}`, color: config.colors.commands.secondary }, - ] - }) - } - break; - case "options": - component.push({ - translate: "%s: %s\n%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Server Count", color: config.colors.commands.primary }, - { text: `${bot.bots.length}`, color: config.colors.integer }, - { text: "Prefixes", color: config.colors.commands.primary }, - { text: `${config.prefixes.map((e) => e + " ").join(' ')}`, color: config.colors.commands.secondary }, - { text: "Mode", color: config.colors.commands.primary }, - { text: `${mode}`, color: config.colors.commands.secondary }, - ] - }) - break; - case "all": - component.push({ - translate: "%s: %s:%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Server", color: config.colors.commands.primary }, - { text: `${bot.options.host}`, color: config.colors.commands.secondary }, - { text: `${bot.options.port}`, color: config.colors.integer }, - { text: "Server Name", color: config.colors.commands.primary }, - { text: `${bot.options.serverName}`, color: config.colors.commands.secondary }, - { text: "Minecraft Username", color: config.colors.commands.primary }, - { text: `${bot.options.username}`, color: config.colors.commands.secondary }, - { text: "Version", color: config.colors.commands.primary }, - { text: `${bot.options.version}`, color: config.colors.commands.secondary }, - { text: "Discord Username", color: config.colors.commands.primary }, - { text: `${discordClient.user?.tag}`, color: config.colors.commands.secondary }, - { text: "Discord Channel", color: config.colors.commands.primary }, - { text: `${bot.discord.channel?.name}`, color: config.colors.commands.secondary }, - { text: "Server Count", color: config.colors.commands.primary }, - { text: `${bot.bots.length}`, color: config.colors.integer }, - { text: "Prefixes", color: config.colors.commands.primary }, - { text: `${config.prefixes.map((e) => e + " ").join(' ')}`, color: config.colors.commands.secondary }, - { text: "Mode", color: config.colors.commands.primary }, - { text: `${mode}`, color: config.colors.commands.secondary } - ] - }) - break; - default: - throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); - } - break; - case "contributors": - case "credits": - component.push({ - translate: "%s%s - %s\n%s:\n%s\n%s\n%s\n%s\n%s %s\n%s\n%s", - color: config.colors.commands.tertiary, - with: [ - { text: "Parker", color: "dark_red" }, - { text: "2991", color: "black" }, - { text: "Owner" }, - { text: "Contributors" }, - { text: "_ChipMC_", color: "dark_blue" }, - { text: "chayapak", color: "yellow" }, - { text: "_yfd", color: "light_purple" }, - { text: "aaa", color: "gold" }, - { text: "Morgan", color: "green" }, - { text: "Ankan", color: "dark_green" }, - { text: "TurtleKid", color: "green" }, - { text: "Ploat/ImGloriz", color: "#cd8ccb" }, - ] - }) - break; - case "discord": - component.push({ - text: `the discord server invite is ${config.discord.invite}`, - color: config.colors.commands.primary, - translate: "", - hoverEvent: { - action: "show_text", - value: [ - { - text: "click here to join the discord server!", - color: config.colors.commands.secondary, - } - ] - }, - clickEvent: { - action: "open_url", - value: `${config.discord.invite}` - } - }) - break; - case "loaded": - component.push({ - translate: "%s %s\n%s %s", - color: config.colors.commands.tertiary, - with: [ - { text: `${bot.commandManager.commandlist.length}`, color: config.colors.integer }, - { text: "Commands", color: config.colors.commands.primary }, - { text: `${bot.modules.length}`, color: config.colors.integer }, - { text: "Modules", color: config.colors.commands.primary } - ] - }); - break; - case "usages": - case "usage": - switch (args.slice(1).join(' ')?.toLowerCase()) { - case "bot": - component.push({ - translate: "%s: %s %s / %s %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Bot Memory Usage", color: config.colors.commands.primary }, - { text: `${Math.floor(process.memoryUsage().heapUsed / 1048576)}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary }, - { text: `${Math.floor(process.memoryUsage().heapTotal / 1048576 )}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary } - ] - }) - break; - case "server": - component.push({ - translate: "%s: %s %s / %s %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Free Server Memory", color: config.colors.commands.primary }, - { text: `${Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary }, - { text: `${Math.floor(os.totalmem() / 1048576)}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary }, - ] - }) - break; - case "all": - component.push({ - translate: "%s: %s %s / %s %s\n%s: %s %s / %s %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Free Server Memory", color: config.colors.commands.primary }, - { text: `${Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary }, - { text: `${Math.floor(os.totalmem() / 1048576)}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary }, - { text: "Bot Memory Usage", color: config.colors.commands.primary }, - { text: `${Math.floor(process.memoryUsage().heapUsed / 1048576)}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary }, - { text: `${Math.floor(process.memoryUsage().heapTotal / 1048576 )}`, color: config.colors.integer }, - { text: "MiB", color: config.colors.commands.secondary } - ] - }) - break; - default: - throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); - } - break; - case "uptimes": - switch (args.slice(1).join(' ')?.toLowerCase()) { - case "bot": - component.push({ - translate: "%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Bot Uptime", color: config.colors.commands.primary }, - { text: `${format(process.uptime())}`, color: config.colors.commands.secondary }, - ] - }) - break; - case "server": - component.push({ - translate: "%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Server Uptime", color: config.colors.commands.primary }, - { text: `${format(os.uptime())}`, color: config.colors.commands.secondary }, - ] - }) - break; - case "all": - component.push({ - translate: "%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Bot Uptime", color: config.colors.commands.primary }, - { text: `${format(process.uptime())}`, color: config.colors.commands.secondary }, - { text: "Server Uptime", color: config.colors.commands.primary }, - { text: `${format(os.uptime())}`, color: config.colors.commands.secondary }, - ] - }) - break; - throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); - } - break; - case "server": - component.push({ - translate: "%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s: %s", - color: config.colors.commands.tertiary, - with: [ - { text: "Hostname", color: config.colors.commands.primary }, - { text: `${os.hostname()}`, color: config.colors.commands.secondary }, - { text: "User", color: config.colors.commands.primary }, - { text: `${os.userInfo().username}`, color: config.colors.commands.secondary }, - { text: "Working Directory", color: config.colors.commands.primary }, - { text: `${require.main.path}`, color: config.colors.commands.secondary }, - { text: "Arch", color: config.colors.commands.primary }, - { text: `${os.arch()}`, color: config.colors.commands.secondary }, - { text: "OS", color: config.colors.commands.primary }, - { text: `${os.platform}`, color: config.colors.commands.secondary }, - { text: "OS Version", color: config.colors.commands.primary }, - { text: `${os.version()}`, color: config.colors.commands.secondary }, - { text: "Kernel Version", color: config.colors.commands.primary }, - { text: `${os.release()}`, color: config.colors.commands.secondary }, - { text: "CPU", color: config.colors.commands.primary }, - { text: `${os.cpus()[0].model}`, color: config.colors.commands.secondary }, - { text: "CPU cores", color: config.colors.commands.primary }, - { text: `${os.cpus().length}`, color: config.colors.integer }, - { text: "Node Version", color: config.colors.commands.primary }, - { text: `${process.version}`, color: config.colors.commands.secondary }, - { text: "NPM Version", color: config.colors.commands.primary }, - { text: `${execSync('npm -v').toString().replaceAll('\n', '')}`, color: config.colors.commands.secondary }, - ] - }) - break; - case "version": - case "ver": - if (botInfo.buildstring.codename.length > 0) { - component.push({ - translate: "%s %s %s-%s-%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s-%s", - color: config.colors.commands.tertiary, - with: [ - { text: "Friday Night Funkin", color: "dark_blue" }, - { text: "Boyfriend", color: "dark_aqua" }, - { text: "Bot", color: "blue" }, - { text: `${botInfo.buildstring.version}`, color: config.colors.integer }, - botInfo.buildstring.codename, - { text: "Build", color: config.colors.commands.primary }, - { text: `${botInfo.buildstring.build}`, color: config.colors.integer }, - { text: "Repo Build", color: config.colors.commands.primary }, - { text: `${execSync('git rev-list --count --all').toString().replaceAll('\n','')}`, color: config.colors.integer }, - { text: "Version Release Date", color: config.colors.commands.primary }, - { text: `${new Date(execSync('git log -1 --format=%ci').toString()).toLocaleString("en-US", {timeZone: "America/CHICAGO"})}`, color: config.colors.commands.secondary }, - { text: "Commit", color: config.colors.commands.primary }, - { text: `${execSync("git rev-parse HEAD").toString().substring(0, 10)}`, color: config.colors.commands.secondary }, - { text: "11/22/22", color: config.colors.commands.primary }, - { text: `${new Date().toLocaleDateString("en-US",{timeZone:"America/CHICAGO"})}`, color: config.colors.commands.secondary }, - ] - }); - } else { - component.push({ - translate: "%s %s %s-%s\n%s: %s\n%s: %s\n%s: %s\n%s: %s\n%s-%s", - color: config.colors.commands.tertiary, - with: [ - { text: "Friday Night Funkin", color: "dark_blue" }, - { text: "Boyfriend", color: "dark_aqua" }, - { text: "Bot", color: "blue" }, - { text: `${botInfo.buildstring.version}`, color: config.colors.integer }, - { text: "Build", color: config.colors.commands.primary }, - { text: `${botInfo.buildstring.build}`, color: config.colors.integer }, - { text: "Repo Build", color: config.colors.commands.primary }, - { text: `${execSync('git rev-list --count --all').toString().replaceAll('\n','')}`, color: config.colors.integer }, - { text: "Version Release Date", color: config.colors.commands.primary }, - { text: `${new Date(execSync('git log -1 --format=%ci').toString()).toLocaleString("en-US", {timeZone: "America/CHICAGO"})}`, color: config.colors.commands.secondary }, - { text: "Commit", color: config.colors.commands.primary }, - { text: `${execSync("git rev-parse HEAD").toString().substring(0, 10)}`, color: config.colors.commands.secondary }, - { text: "11/22/22", color: config.colors.commands.primary }, - { text: `${new Date().toLocaleDateString("en-US",{timeZone:"America/CHICAGO"})}`, color: config.colors.commands.secondary }, - ] - }); - } - break; - default: - throw new CommandError({ translate: "command.unknown.argument", color: "dark_red" }); - } - if (bot.options.isSavage) { + + componentPush(bot, args, config, discordClient, source, component); + + if (bot.options.mode === "savageFriends") { bot.chat.message(bot.getMessageAsPrismarine(component)?.toMotd().replaceAll('§','&')); } else { bot.tellraw(`@a`, component); } }, + discordExecute (context) { + const bot = context.bot; + const config = context.config; + const EmbedBuilder = context.EmbedBuilder + const fixansi = context.fixansi; + const args = context.arguments; + const discordClient = context.discordClient; + const source = context.source; + + let component = []; + + componentPush(bot, args, config, discordClient, source, component); + + bot?.discord?.message?.reply(`\`\`\`ansi\n${fixansi(bot.getMessageAsPrismarine(component)?.toAnsi()?.replaceAll('`', '`\u200b'))}\`\`\``); + } } diff --git a/src/commands/public/list.js b/src/commands/public/list.js index 743dfd5..8b3ca3e 100644 --- a/src/commands/public/list.js +++ b/src/commands/public/list.js @@ -1,4 +1,5 @@ const CommandError = require('../../util/command_error'); + module.exports = { data: { name: "list", diff --git a/src/commands/public/netmsg.js b/src/commands/public/netmsg.js index ed4a75e..7666789 100644 --- a/src/commands/public/netmsg.js +++ b/src/commands/public/netmsg.js @@ -43,7 +43,7 @@ module.exports = { } for (const eachBot of bot.bots) { - if (eachBot.options.isSavage === true || eachBot.options.isCreayun === true) { + if (eachBot.options.mode === "savageFriends" || eachBot.options.mode === "creayun") { eachBot.chat.message(`${bot.getMessageAsPrismarine(component)?.toMotd()?.replaceAll('§','&')}`) } else { eachBot.tellraw("@a", component) diff --git a/src/commands/public/urban.js b/src/commands/public/urban.js index 3eade94..6c94e2e 100644 --- a/src/commands/public/urban.js +++ b/src/commands/public/urban.js @@ -1,19 +1,81 @@ -const CommandError = require('../../util/command_error'); +const CommandError = require('../../util/command_error') +const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, StringSelectMenuBuilder, StringSelectMenuOptionBuilder, SlashCommandBuilder } = require('discord.js'); const { request } = require('undici'); - module.exports = { data: { - name: "urban", + name: 'urban', + description: 'urban dictionary', aliases: [ - "urbandictionary" + 'urbandictionary' ], - description: "look up definitions on urban dictionary", trustLevel: 0, usages: [ - "" - ] + "", + ], }, async execute (context) { - + const source = context.source + const args = context.arguments + const bot = context.bot + const prefix = [ + { text: '[', color: 'dark_gray' }, + { text: 'Urban', color: '#B72A00' }, + { text: '] ', color: 'dark_gray'} + ] + let component = []; + let term = `${args.join(' ')}` + const query = new URLSearchParams({ term }); + const dictResult = await request(`https://api.urbandictionary.com/v0/define?${query}`); + const { list } = await dictResult.body.json(); + if (!list.length) { + bot.tellraw('@a', { text: 'No results found', color: 'dark_red' }); + } + for (definitions of list) { + component.push(prefix, [ + { + text: `${definitions.definition.replaceAll('\r','').replaceAll('[', '\xa71\xa7n\xa7o').replaceAll(']','\xa7r\xa77')}\n`, + color: 'gray', + underlined: false, + italic: false, + translate: "", + hoverEvent: { + action:"show_text", + value: [ + { + text: `Example \u203a \n ${definitions.example.replaceAll('\r', '').replaceAll('[', '\xa71\xa7n\xa7o').replaceAll(']','\xa7r\xa77')}\n`, + color: 'gray' + }, + { + text: `Word \u203a ${definitions.word.replaceAll('\r', '').replaceAll('[', '\xa71\xa7n\xa7o').replaceAll(']','\xa7r\xa77')}\n`, + color: 'gray', + }, + { + text: `Author \u203a ${definitions.author.replaceAll('\r', '').replaceAll('[', '\xa71\xa7n\xa7o').replaceAll(']','\xa7r\xa77')}\n`, + color: 'gray' + }, + { + text: `written on \u203a ${definitions.written_on.replaceAll('\r', '').replaceAll('[', '\xa71\xa7n\xa7o').replaceAll(']','\xa7r\xa77')}\n`, + color: 'gray' + }, + { + text: `Rating \u203a Thumbs-Up ${definitions.thumbs_up} / Thumbs-Down ${definitions.thumbs_down}`, + color: 'gray' + } + ] + }, + clickEvent: { + action: 'open_url', + value: `${definitions.permalink}` + } + }, + ]) + } + bot.tellraw(`@a[name="${source?.player?.profile?.name}"]`, component) + }, + async discordExecute (context) { + const bot = context.bot; + const args = context.arguments; + const component = []; } -} \ No newline at end of file +} + diff --git a/src/commands/public/wiki.js b/src/commands/public/wiki.js index 6d1aa7e..6f42d5b 100644 --- a/src/commands/public/wiki.js +++ b/src/commands/public/wiki.js @@ -1,16 +1,55 @@ +const wiki = require('wikipedia'); +const CommandError = require('../../util/command_error'); + +async function components (config, summary, component) { + component.push({ text: summary, color: config.colors.commands.primary }) +} + module.exports = { data: { - name: "wiki", + name: 'wiki', + description: 'wikipedia', + trustLevel: 0, aliases: [ - "wikipedia" + 'wikipedia' ], - description: "look up articles on wikipedia", - usages: [ + usages:[ "
" ], - trustLevel: 0 }, async execute (context) { + const source = context.source; + const args = context.arguments; + const bot = context.bot; + const config = context.config; + let component = []; + try { + const page = await wiki.page(args.join(' ')); + const summary = await page.intro(); + + components(config, summary, component); + + bot.tellraw("@a", component); + + } catch (e) { + if (e.toString() === "pageError: TypeError: Cannot read properties of undefined (reading 'pages')") { + bot.chat.message('&cArticle not found!'); + } else { + bot.tellraw(`@a`, `${e.toString()}`) + } + } + +/* try { + const page = await wiki.page(args.join(' ')) + const summary = await page.intro(); + bot.tellraw(`@a`, { text: `${summary}`, color: 'gray' }); + } catch (error) { + if (error.toString() === "pageError: TypeError: Cannot read properties of undefined (reading 'pages')") { + bot.chat.message('&cArticle not found!'); + } else { + bot.tellraw(`@a`, `${error.toString()}`) + } + }*/ } -} \ No newline at end of file +} diff --git a/src/data/info.json b/src/data/info.json index 102fa70..e556677 100644 --- a/src/data/info.json +++ b/src/data/info.json @@ -1,7 +1,8 @@ { "buildstring": { - "build": "2010", + "build": "2030", "codename": "§aGame §aTheory", - "version": "v7.0.0-alpha" + "version": "v7.0.0-beta", + "url":"https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot" } } diff --git a/src/index.js b/src/index.js index 236d20f..d97c382 100644 --- a/src/index.js +++ b/src/index.js @@ -6,6 +6,7 @@ const path = require('path'); const { Client, GatewayIntentBits } = require('discord.js'); const { MessageContent, GuildMessages, Guilds } = GatewayIntentBits; const discordClient = new Client({ intents: [Guilds, GuildMessages, MessageContent] }); +const CommandSource = require('./util/command_source'); console.log('Starting FNFBoyfriendBot'); process.stdout.write('\x1b]2;Starting FNFBoyfriendBot please wait,.....\x1b\x5c'); @@ -32,10 +33,40 @@ const rl = readline.createInterface({ if (config.discord.enabled) discordClient.login(config.discord.token); const bots = []; +let bot; + for (const options of config.bots) { - const bot = new createBot(options, config); + bot = new createBot(options, config); bots.push(bot); bot.bots = bots; require('./util/loadModules')(bot, options, config, discordClient); bot.console.readlineInterface(rl); } + +discordClient.on('messageCreate', (message) => { + try { + if (message.author.id === bot.discord.client.user.id) return; + + const ChatMessage = require('prismarine-chat')('1.20.2'); + bot.getMessageAsPrismarine = (message) => { + return new ChatMessage(message); + } + config.prefixes.map((prefix) => { + if (message.content.startsWith(prefix)) { + const source = new CommandSource({ + profile: { + name: `${message?.member.nickname || message?.author.displayName}` + } + }, { + discord: true, + console: false + }, false, message); + + bot.commandManager.executeString(source, message.content.substring(prefix.length)); + return; + } + }); + } catch (e) { + console.log(e.stack); + } +}); diff --git a/src/modules/boot.js b/src/modules/boot.js index 3487085..a0a20a2 100644 --- a/src/modules/boot.js +++ b/src/modules/boot.js @@ -4,7 +4,7 @@ function inject (context) { const options = context.options; const info = require('../data/info.json'); bot.on("packet.login", (data) => { - if (bot.options.isCreayun === true) return + if (bot.options.mode === "creayun") return if (new Date().getDay() === 5) { bot.chat.message('Gettin\' freaky on a friday night!'); } else { diff --git a/src/modules/command_core.js b/src/modules/command_core.js index 43b26e0..81c4e0d 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -24,7 +24,7 @@ function inject (context) { const { start, end } = bot.core.area if (!pos) return - if (bot.options.useChat || bot.options.isCreayun || bot.options.isSavage) return + if (bot.options.mode === "creayun" || bot.options.mode === "savageFriends") return; if (isNaN(pos.x + start.x)) { bot.chat.command('spawn'); return @@ -44,7 +44,7 @@ function inject (context) { const itemPosition = bot.core.itemPosition; if (!pos) return; - if (bot.options.useChat || bot.options.isCreayun || bot.options.isSavage) return; + if (bot.options.mode === "creayun" || bot.options.mode === "savageFriends") return; if (isNaN(pos.x + pos.x)) { bot.chat.command('spawn'); return @@ -149,7 +149,7 @@ function inject (context) { const itemPosition = bot.core.itemPosition; if (!location) return; - if (bot.options.isCreayun || bot.options.useChat || bot.options.isSavage) { + if (bot.options.mode === "creayun" || bot.options.mode === "savageFriends") { return } else { if (bot.core.usePlacedCommandBlock) { diff --git a/src/modules/command_handler.js b/src/modules/command_handler.js index 23787d3..b5234a6 100644 --- a/src/modules/command_handler.js +++ b/src/modules/command_handler.js @@ -19,8 +19,7 @@ function inject (context) { ratelimit-- }, 1000) if (ratelimit > 2) { - 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'}) + 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_manager.js b/src/modules/command_manager.js index 39db1d5..93aa571 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -4,6 +4,8 @@ const CommandError = require('../util/command_error.js'); const CommandSource = require('../util/command_source'); const { EmbedBuilder } = require('discord.js'); const fixansi = require('../util/ansi'); +const cmdMgrUtil = require('../util/command_manager_util'); + async function inject (context) { const bot = context.bot; const config = context.config; @@ -16,100 +18,48 @@ async function inject (context) { execute (source, commandName, args) { const command = this.getCommand(commandName.toLowerCase()); try { - if (source?.sources?.discord && !source?.sources?.console) { - if (!command || !command?.execute) { - const Embed = new EmbedBuilder() - .setColor(`${config.colors.discord.error}`) - .setTitle("Unknown command") - .setDescription(`Unknown command: ${commandName}`) - bot?.discord?.message?.reply({ embeds: [Embed] }) - } - } else if (!source?.sources?.discord && !source?.sources?.console) { - if (!command || !command.execute) - if (bot.options.isSavage) { - bot.chat.message(bot.getMessageAsPrismarine({ - translate: "%s", + if (!command) { + if (source?.sources?.console) { + bot.console.warn(bot.getMessageAsPrismarine({ + translate: "%s%s%s %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: "\n" }, { text: `${commandName}` }, { translate: "command.context.here", color: "red" } ] - })?.toMotd().replaceAll('§','&')); + })?.toAnsi()); } 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({ - 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" } - ] - })?.toAnsi()) - }; - - require('../util/command_manager_util')(bot, command, args, source); - -// require('../util/command_manager_arguments')(bot, args, command); - - if (!command?.discordExecute && command && source?.sources?.discord) { - throw new CommandError(`${command.data.name} command is not supported in discord!`) - } else if (command?.discordExecute && command && source?.sources?.discord) { - return command.discordExecute({ bot, source, arguments: args, config, discordClient, EmbedBuilder, fixansi }) - } else if (!command?.execute && command && !source?.sources?.discord) { - throw new CommandError(`${command.data.name} command is not supported in game!`) - } else if (command?.execute && command && !source?.sources?.discord) { - return command?.execute({ bot, source, arguments: args, config, discordClient }); - } - } catch (error) { - console.error(error) - if (source?.sources?.discord && !source?.sources?.console) { - const Embed = new EmbedBuilder() - .setColor(`${config.colors.discord.error}`) - .setTitle(`${command?.data?.name} command`) - .setDescription(`\`\`\`${error}\`\`\``) - bot?.discord?.message?.reply({ - embeds: [ - Embed + 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" } ] - }) - } else if (!source?.sources?.discord && !source?.sources?.console) { - if (error instanceof CommandError) { - if (bot.options.isSavage || bot.options.isCreayun) { - bot.chat.message(`&4${error.message}`) - } else { - if (error.toString().length > 256) { - bot.tellraw("@a", error._message); - } else if (error.toString().length < 256) { - bot.chat.message(`${bot.getMessageAsPrismarine(error._message)?.toMotd().replaceAll('§','&')}`) - } else { - bot.tellraw("@a", error._message); - } - } + }); + } + } + + cmdMgrUtil(bot, command, args, source); + + return command?.execute({ bot, source, arguments: args, config, discordClient }); + } catch (error) { + console.error(error); + + if (error instanceof CommandError) { + if (options.mode !== "kaboom") { + bot.chat.message(`&4${error._message}`); } else { - if (bot.options.isSavage || bot.options.isCreayun) { - bot.chat.message(`${bot.getMessageAsPrismarine({ translate: "command.failed", color: "dark_red" })?.toMotd().replaceAll('§','&')}`) + if (error.toString().length > 256) { + bot.tellraw("@a", error._message); + } else if (error.toString().length < 256) { + bot.chat.message(`${bot.getMessageAsPrismarine(error._message)?.toMotd().replaceAll('§','&')}`); } else { - bot.tellraw("@a", [{ translate: 'command.failed', color: "dark_red", hoverEvent: { action: 'show_text', contents: `${error.stack}` } }]) + bot.tellraw("@a", error._message); } } } @@ -117,14 +67,36 @@ async function inject (context) { }, executeString (source, command) { - const [commandName, ...args] = command.split(' ') - return this.execute(source, commandName, args) + const [commandName, ...args] = command.split(' '); + if (source?.sources?.discord) { + return this.discordExecute(source, commandName, args); + } else { + return this.execute(source, commandName, args); + } }, - discordExecute(source, command) { - const [commandName, ...args] = command.split(" "); - if (source?.sources?.discord && !source?.sources?.console) { - return this.discordExecute(source, commandName, args) + discordExecute(source, commandName, args) { + const command = this.getCommand(commandName.toLowerCase()); + + try { + if (!command) { + throw new CommandError(`Unknown Command: ${commandName}`); + } + + cmdMgrUtil(bot, command, args, source); + + if (!command?.discordExecute) { + throw new CommandError(`${command.data.name} command is not supported in discord!`); + } else { + return command?.discordExecute({ bot, source, arguments: args, config, discordClient, EmbedBuilder, fixansi }); + } + } catch (error) { + console.error(error); + if (error instanceof CommandError) { + bot?.discord?.message?.reply(`${bot.getMessageAsPrismarine(error._message)}`); + } else { + bot?.discord?.message?.reply(`\`\`\`${error}\`\`\``); + } } }, diff --git a/src/modules/discord.js b/src/modules/discord.js index 4a6e4a2..53c7190 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -154,7 +154,7 @@ function inject (context) { } else if (message?.reference?.type === 1) { // this is for messages that are forwarded } else { - if (options.useChat || options.isSavage || options.isCreayun) { + if (options.mode === "savageFriends" || options.mode === "creayun") { bot.chat.message(bot.getMessageAsPrismarine(`&7[&9FNF&3Boyfriend&1Bot Discord&7] ${message?.member?.displayName} \u203a ${message?.content}`)?.toMotd().replaceAll('§','&')) } else { bot.tellraw('@a', [tag, message.content]); diff --git a/src/modules/memusage.js b/src/modules/memusage.js index c2f39e4..29d56f8 100644 --- a/src/modules/memusage.js +++ b/src/modules/memusage.js @@ -2,71 +2,32 @@ const os = require('os'); function inject (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 = 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: [ + { text: "FNF", color: "dark_blue" }, + { text: "Boyfriend", color: "dark_aqua" }, + { text: "Bot", color: "blue" }, + { text: "Memory Usage" }, + { text: "Free Server Memory", color: config.colors.commands.primary }, + { text: `${Math.floor(os.freemem() / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: `${Math.floor(os.totalmem() / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { text: "Bot Memory Usage", color: config.colors.commands.primary }, + { text: `${Math.floor(process.memoryUsage().heapUsed / 1048576)}`, color: config.colors.integer }, + { text: "MiB", color: config.colors.commands.secondary }, + { 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) @@ -75,6 +36,7 @@ function inject (context) { }) } + module.exports = { data: { enabled: true, diff --git a/src/modules/selfcare.js b/src/modules/selfcare.js index ae9e130..873617a 100644 --- a/src/modules/selfcare.js +++ b/src/modules/selfcare.js @@ -21,7 +21,7 @@ function inject (context) { bot.vanished = true bot.on('system_chat', (data) => { const stringMessage = bot.getMessageAsPrismarine(data.message)?.toString(); - if (options.isSavage) { + if (options.mode === "savageFriends") { if (stringMessage === "Please, login with the command: /login ") login = true; else if (stringMessage === "Successful login!") login = false; else if (stringMessage === "You're already logged in!") login = false; @@ -33,7 +33,7 @@ function inject (context) { else if (stringMessage === "You're already logged in!") register = false; else if (stringMessage === "Successful login!") register = false; - } else if (options.isKaboom) { + } else if (options.mode === "kaboom") { if (stringMessage === "Successfully enabled CommandSpy") commandSpy = true; else if (stringMessage === "Successfully enabled CommandSpy.") commandSpy = true; else if (stringMessage === "Successfully disabled CommandSpy") commandSpy = false; @@ -94,7 +94,7 @@ function inject (context) { gameMode = packet.gameMode; clientLock = packet.gameMode; timer = setInterval(() => { - if (bot.options.isSavage && !bot.options.isKaboom && !bot.options.isCreayun) { + if (bot.options.mode === "savageFriends") { if (login) bot.chat.command('login amogusissus'); else if (register) bot.chat.command('register amogusissus amogusissus'); else if (gameMode !== 1) bot.chat.command('minecraft:gamemode creative'); @@ -102,7 +102,7 @@ function inject (context) { else if (clientLock !== 4) bot._client.write("client_command", { actionId: 0 }); } else if (bot.options.isCreayun && !bot.options.isKaboom && !bot.options.isSavage) { - } else if (bot.options.isKaboom && !bot.options.isSavage) { + } else if (bot.options.mode === "kaboom") { if (permissionLevel < 2) bot.chat.command('op @s[type=player]'); else if (gameMode !== 1) bot.chat.command('minecraft:gamemode creative'); else if (!commandSpy) bot.chat.command('commandspy on'); diff --git a/src/modules/team.js b/src/modules/team.js index ee9b653..604e0a7 100644 --- a/src/modules/team.js +++ b/src/modules/team.js @@ -5,9 +5,9 @@ function inject (context) { const options = context.options; const config = context.config; - if (options.isKaboom === false || config.team.enabled === false) return; + if (options.mode !== "kaboom" || config.team.enabled === false) return; bot.on("packet.login", async () => { - if (options.isKaboom) { + if (options.mode === "kaboom") { await sleep(100); bot.chat.command(`minecraft:team add ${config.team.name}`); await sleep(100); diff --git a/src/modules/validation.js b/src/modules/validation.js index e10df2f..1152a5d 100644 --- a/src/modules/validation.js +++ b/src/modules/validation.js @@ -4,9 +4,9 @@ function inject (context) { const config = context.config; setInterval(() => { bot.validation = { - trusted: crypto.createHash('sha256').update(Math.floor(Date.now() / 1000) + config.keys.trusted).digest('hex').substring(0, 16), - admin: crypto.createHash('sha256').update(Math.floor(Date.now() / 1000) + config.keys.admin).digest('hex').substring(0, 16), - owner: crypto.createHash('sha256').update(Math.floor(Date.now() / 1000) + config.keys.owner).digest('hex').substring(0, 16), + trusted: crypto.createHash('sha256').update(Math.floor(Date.now() / 2000) + config.keys.trusted).digest('hex').substring(0, 16), + admin: crypto.createHash('sha256').update(Math.floor(Date.now() / 2000) + config.keys.admin).digest('hex').substring(0, 16), + owner: crypto.createHash('sha256').update(Math.floor(Date.now() / 2000) + config.keys.owner).digest('hex').substring(0, 16), } }, 100) } diff --git a/src/util/command_manager_util.js b/src/util/command_manager_util.js index 54193dd..1f74103 100644 --- a/src/util/command_manager_util.js +++ b/src/util/command_manager_util.js @@ -10,7 +10,7 @@ module.exports = (bot, command, args, source) => { case 1: if (source?.sources?.discord) { const hasRole = roles?.some(role => role.name === `${config.discord.roles.trusted}` || role.name === `${config.discord.roles.admin}` || role.name === `${config.discord.roles.fullAccess}` || role.name === `${config.discord.roles.owner}`) - if (!hasRole) throw new CommandError({ translate: 'You are not trusted or the owner!', color: "dark_red" }) + if (!hasRole) throw new CommandError({ translate: 'You dont have the trusted, admin, or owner role!', color: "dark_red" }) } else if (!source?.sources.console) { if (args.length === 0) throw new CommandError({ text: "Please provide a trusted, admin or owner hash", color: "dark_red" }); if (args[0] !== bot.validation.trusted && args[0] !== bot.validation.admin && args[0] !== bot.validation.owner) throw new CommandError({ translate: 'Invalid trusted, admin or owner hash', color: 'dark_red' }); @@ -19,7 +19,7 @@ module.exports = (bot, command, args, source) => { case 2: if (source?.sources?.discord) { const hasRole = roles?.some(role => role.name === `${config.discord.roles.admin}` || role.name === `${config.discord.roles.fullAccess}` ||role.name === `${config.discord.roles.owner}`) - if (!hasRole) throw new CommandError({ translate: 'You are not trusted or the owner!', color: "dark_red" }) + if (!hasRole) throw new CommandError({ translate: 'You dont have the admin, or owner role!', color: "dark_red" }) } else if (!source?.sources?.console) { if (args.length === 0) throw new CommandError({ text: "Please provide an admin or owner hash", color: 'dark_red' }) if (args[0] !== bot.validation.admin && args[0] !== bot.validation.owner) throw new CommandError({ translate: 'Invalid admin or owner hash', color: 'dark_red' }); @@ -28,7 +28,7 @@ module.exports = (bot, command, args, source) => { case 3: if (source?.sources?.discord) { const hasRole = roles?.some(role => role.name === `${config.discord.roles.owner}` || role.name === `${config.discord.roles.fullAccess}`) - if (!hasRole) throw new CommandError({ translate: 'You are not the owner!', color: "dark_red" }) + if (!hasRole) throw new CommandError({ translate: 'You do not have the owner role!', color: "dark_red" }) } else if (!source?.sources?.console) { if (args.length === 0 && bot.validation.owner) throw new CommandError({ text: "Please provide an owner hash", color: "dark_red" }) if (args[0] !== bot.validation.owner) throw new CommandError({ translate: 'Invalid owner hash', color: 'dark_red' }) diff --git a/src/util/usernameGen.js b/src/util/usernameGen.js index 39c906d..c94fc4c 100644 --- a/src/util/usernameGen.js +++ b/src/util/usernameGen.js @@ -1,6 +1,6 @@ function usernameGen (bot, config) { // const characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; - if (bot.options.isSavage || bot.options.isCreayun && !bot.options.isKaboom) { + if (bot.options.mode === "savageFriends" || bot.options.mode === "creayun") { characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; } else { characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_-+={]}[|\\:;>.<,/?ඞ♋'