diff --git a/src/bot.js b/src/bot.js index 7bb288a..accc2e6 100644 --- a/src/bot.js +++ b/src/bot.js @@ -1,6 +1,8 @@ const mc = require('minecraft-protocol'); const { EventEmitter } = require('events'); -EventEmitter.defaultMaxListeners = 200; +const ChatMessage = require("prismarine-chat"); +EventEmitter.defaultMaxListeners = Infinity; +let disconnectCount = 0; function createBot(options = {}, config) { const bot = new EventEmitter(); @@ -23,27 +25,44 @@ function createBot(options = {}, config) { bot.username = client.username; }) - client.on('disconnect', data => { - bot.emit("clientDisconnect", data.reason); - }) + client.on("disconnect", (data) => { + bot.console.warn(`${ChatMessage(bot._client.version).fromNotch("§8[§bClient Reconnect§8]§r")?.toAnsi()} ${ChatMessage(bot._client.version).fromNotch(data.reason)?.toAnsi()}`); + bot?.discord?.channel?.send(ChatMessage(bot._client.version).fromNotch(data.reason)?.toString()); + }); - client.on('end', reason => { - bot.emit('end', reason); - }) + client.on("end", (reason) => { + bot.emit("end", reason); + disconnectCount++; + }); - client.on('error', error => { - bot.emit('clientDisconnect', error.toString()); - }) + client.on("error", (error) => { + try { + if (disconnectCount === 10) { + bot.console.info("stopped logging disconnect messages for now..."); + bot?.discord?.channel?.send("stopped logging disconnect messages for now..."); + return; + } else if (disconnectCount > 10) { + return; + } else { + bot.console.warn(ChatMessage(bot._client.version).fromNotch(`§8[§bClient Reconnect§8]§r ${error.toString()}`)?.toAnsi()); + bot?.discord?.channel?.send(error.toString()); + } + } catch (e) { + console.log(e.stack); + } + }); - client.on("keep_alive", ({ keepAliveId }) => { - }) - - client.on('kick_disconnect', (data) => { - bot.emit("clientDisconnect", data.reason) - }) + client.on("kick_disconnect", (data) => { + bot.console.warn(`${ChatMessage(bot._client.version).fromNotch("§8[§bClient Reconnect§8]§r")?.toAnsi()} ${ChatMessage(bot._client.version).fromNotch(data.reason)?.toAnsi()}`); + bot?.discord?.channel?.send(ChatMessage(bot._client.version).fromNotch(data.reason)?.toString()); + }); process.on("uncaughtException", (e) => { + bot.console.warn(`${e.toString()}`); + }); + client.on("success", () => { + disconnectCount = 0; }); }) diff --git a/src/commands/console/console.js b/src/commands/console/console.js index b210b9b..63ca292 100644 --- a/src/commands/console/console.js +++ b/src/commands/console/console.js @@ -20,6 +20,8 @@ module.exports = { const bot = context.bot const args = context.arguments; const source = context.source; + const config = context.config; + if (!args && !args[0] && !args[1] && !args[2] && !args[3]) return; switch (args[0]?.toLowerCase()) { case "server": diff --git a/src/commands/public/wiki.js b/src/commands/public/wiki.js index f1a6ea6..886ea4a 100644 --- a/src/commands/public/wiki.js +++ b/src/commands/public/wiki.js @@ -44,6 +44,7 @@ module.exports = { const bot = context.bot; const args = context.arguments; const fixansi = context.fixansi; + const config = context.config; let component = []; @@ -59,7 +60,7 @@ module.exports = { if (e.toString() === "pageError: TypeError: Cannot read properties of undefined (reading 'pages')") { bot?.discord?.message?.reply('Article not found!'); } else { - bot?.discord?.message?.reply(`${e.toString()}`); + bot?.discord?.message?.reply(`${e.stack}`); } } } diff --git a/src/commands/trusted/validate.js b/src/commands/trusted/validate.js index bc7d089..9412635 100644 --- a/src/commands/trusted/validate.js +++ b/src/commands/trusted/validate.js @@ -30,6 +30,8 @@ module.exports = { const event = bot?.discord?.message const roles = event?.member?.roles?.cache const source = context.source; + const config = context.config; + if (roles?.some(role => role.name === `${config.discord.roles.trusted}`)) { bot.discord.message.reply('Valid trusted user') bot.chat.message(`Valid trusted user [${bot.discord.message.member.user.username}]`) diff --git a/src/data/info.json b/src/data/info.json index 14d10df..3c906d6 100644 --- a/src/data/info.json +++ b/src/data/info.json @@ -1,8 +1,8 @@ { "buildstring": { - "build": "2200", + "build": "2205", "codename": "", - "version": "v7.0.5", + "version": "v7.0.6", "url": "https://code.chipmunk.land/Parker2991/FridayNightFunkinBoyfriendBot.git" } } diff --git a/src/index.js b/src/index.js index f05cfd7..8d63ac5 100644 --- a/src/index.js +++ b/src/index.js @@ -34,28 +34,7 @@ for (const options of config.bots) { bots.push(bot); bot.bots = bots; require('./util/loadModules')(bot, options, config, discordClient); - - let disconnectCount = 0; bot.console.readlineInterface(rl); - - bot.on('clientDisconnect', (data) => { - try { - disconnectCount++ - - if (disconnectCount === 10) { - bot.console.info('stopped logging disconnect messages for now...'); - bot?.discord?.channel?.send('stopped logging disconnect messages for now...'); - return; - } else if (disconnectCount > 10) { - return; - } else { - bot.console.warn(bot.getMessageAsPrismarine(`§8[§bClient Reconnect§8]§r ${data}`)?.toAnsi()) - bot?.discord?.channel?.send(data.toString()); - } - } catch (e) { - console.log(e.stack); - } - }); } discordClient.on('messageCreate', (message) => { diff --git a/src/modules/chat.js b/src/modules/chat.js index bb87cf2..9dc0d56 100644 --- a/src/modules/chat.js +++ b/src/modules/chat.js @@ -83,7 +83,7 @@ function inject (context) { return } - if (message.translate === "advMode.notAllowed" || message?.translate?.startsWith("قيادة المجموعة")) return; + if (message.translate === "advMode.notAllowed") return; bot.emit('message', message); diff --git a/src/modules/command_core.js b/src/modules/command_core.js index f959964..5328fdd 100644 --- a/src/modules/command_core.js +++ b/src/modules/command_core.js @@ -50,11 +50,11 @@ function inject (context) { present: true, itemId: bot.registry.itemsByName.repeating_command_block.id, itemCount: 1, - nbtData: nbt.comp({ +/* nbtData: nbt.comp({ BlockEntityTag: nbt.comp({ CustomName: nbt.string(JSON.stringify(config.core.itemName)) }) - }) + })*/ } }); @@ -185,11 +185,11 @@ function inject (context) { present: true, itemId: bot.registry.itemsByName.repeating_command_block.id, itemCount: 1, - nbtData: nbt.comp({ +/* nbtData: nbt.comp({ BlockEntityTag: nbt.comp({ CustomName: nbt.string(JSON.stringify(config.core.itemName)) }) - }) + })*/ } }); diff --git a/src/modules/command_manager.js b/src/modules/command_manager.js index 70d35fd..21d6f1f 100644 --- a/src/modules/command_manager.js +++ b/src/modules/command_manager.js @@ -44,7 +44,7 @@ async function inject (context) { } } - cmdMgrUtil(bot, command, args, source); + cmdMgrUtil(bot, command, args, source, config); return command?.execute({ bot, source, arguments: args, config, discordClient }); } catch (error) { @@ -82,7 +82,7 @@ async function inject (context) { throw new CommandError(`Unknown Command: ${commandName}`); } - cmdMgrUtil(bot, command, args, source); + cmdMgrUtil(bot, command, args, source, config); if (!command?.discordExecute) { throw new CommandError(`${command.data.name} command is not supported in discord!`); @@ -93,7 +93,7 @@ async function inject (context) { if (error instanceof CommandError) { bot?.discord?.message?.reply(`${bot.getMessageAsPrismarine(error._message)}`); } else { - bot?.discord?.message?.reply(`\`\`\`${error}\`\`\``); + bot?.discord?.message?.reply(`\`\`\`${error.stack}\`\`\``); bot?.console?.warn(error.stack); } } diff --git a/src/modules/discord.js b/src/modules/discord.js index e54efb7..a5004b8 100644 --- a/src/modules/discord.js +++ b/src/modules/discord.js @@ -6,12 +6,15 @@ function inject (context) { const config = context.config; const discordClient = context.discordClient; const options = context.options; - if (!options?.channelId) { + if (!options.channelId) { bot.discord = { - invite: config.discord?.invite + invite: config.discord?.invite, + client: discordClient, + prefix: config.discord.prefix } return } + bot.discord = { client: discordClient, channel: undefined, diff --git a/src/modules/selfcare.js b/src/modules/selfcare.js index 191e710..d961570 100644 --- a/src/modules/selfcare.js +++ b/src/modules/selfcare.js @@ -88,9 +88,7 @@ function inject (context) { setTimeout(() => { positionCount-- if (positionCount > 4) { - bot.core.run('sudo * icu stop'); - } if (permissionLevel < 2 || gameMode !== 1) { - bot._client.end('anti icu :3'); + bot._client.end('anti icu') } }, 1000) }) @@ -116,7 +114,7 @@ function inject (context) { if (permissionLevel < 2) bot.chat.command('op @s[type=player]'); else if (gameMode !== 1) bot.chat.command('minecraft:gamemode creative'); else if (username) bot.chat.command(`username ${bot._client.username}`) - else if (nickname) bot.chat.command(`nick off`) +// else if (nickname) bot.chat.command(`nick off`) else if (!prefix) bot.chat.command(`prefix &8[&bPrefix&8: &3${config.prefixes[0]}&8]`); else if (!vanished && bot.vanished) bot.core.run(`essentials:vanish ${bot._client.username} on`); else if (!commandSpy) bot.core.run(`commandspy ${bot.uuid} on`); diff --git a/src/util/command_manager_util.js b/src/util/command_manager_util.js index 8da5774..996f198 100644 --- a/src/util/command_manager_util.js +++ b/src/util/command_manager_util.js @@ -1,5 +1,5 @@ const CommandError = require('./command_error'); -module.exports = (bot, command, args, source) => { +module.exports = (bot, command, args, source, config) => { const event = bot.discord.message; const roles = event?.member?.roles?.cache; switch (command?.data?.trustLevel) {