diff --git a/plugins/commands.js b/plugins/commands.js index 0d95700..8cbbb44 100644 --- a/plugins/commands.js +++ b/plugins/commands.js @@ -10,7 +10,7 @@ function inject (bot, dcclient, config) { bot.command_handler.commands = await loadFiles(path.join(__dirname, config.commandsDir)) } bot.command_handler.reload() - bot.command_handler.main = function (prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector) { + bot.command_handler.main = function (prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector, proxy) { bot.command_handler.reload() let raw let command @@ -41,7 +41,7 @@ function inject (bot, dcclient, config) { if (!command.discordExecute) throw new Error('This command is not yet supported on discord!') command.discordExecute(bot, username, usernameraw, sender, prefix, args, channeldc, message, config) } else { - command.execute(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector) + command.execute(bot, username, usernameraw, sender, prefix, args, config, hash, ownerhash, selector, proxy) } } catch (e) { if (prefix === config.discord.prefix) { @@ -55,10 +55,10 @@ function inject (bot, dcclient, config) { } } } - bot.command_handler.run = function (username, usernameraw, message, sender, channeldc, hash, ownerhash, selector = '@a') { + bot.command_handler.run = function (username, usernameraw, message, sender, channeldc, hash, ownerhash, selector = '@a', proxy) { for (const prefix of config.prefixes) { if (!message.startsWith(prefix)) continue - bot.command_handler.main(prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector) + bot.command_handler.main(prefix, username, usernameraw, message, sender, channeldc, hash, ownerhash, selector, proxy) } } let previousMessage = { username: '', message: '' } diff --git a/plugins/proxy.js b/plugins/proxy.js index d9a5905..aacc39b 100644 --- a/plugins/proxy.js +++ b/plugins/proxy.js @@ -13,6 +13,8 @@ function inject (bot, dcclient, config) { index = _index }) + bot.proxy = {} + const version = config.proxy.version const srv = mc.createServer({ 'online-mode': false, @@ -100,9 +102,15 @@ function inject (bot, dcclient, config) { target.write(meta.name, data) }) + bot.proxy[client.username] = { + target, + client + } + function endListener (reason) { - bot.off('end', endListener) + delete bot.proxy[client.username] client.end(`Bot disconnected with reason: ${util.inspect(reason)}`) + bot.off('end', endListener) } bot.on('end', endListener) }) diff --git a/plugins/proxy/custom_chat.js b/plugins/proxy/custom_chat.js index b916485..17b951e 100644 --- a/plugins/proxy/custom_chat.js +++ b/plugins/proxy/custom_chat.js @@ -15,7 +15,8 @@ function inject (bot, client, target, config, clientPacketBlacklist) { null, 'h', // real hash hardcode 'o', - client.username + client.username, + true ) }