| const localtunnel = require('localtunnel'); | |
| const axios = require('axios'); | |
| let tunnel = null; | |
| module.exports.config = { | |
| name: "lt", | |
| version: "1.0.0", | |
| hasPermssion: 2, | |
| credits: "Jonell Magallanes", | |
| description: "Manage LocalTunnel connection", | |
| usePrefix: false, | |
| commandCategory: "System", | |
| usages: "lt <start|stop|pause> [subdomain] [port]", | |
| cooldowns: 5, | |
| }; | |
| module.exports.run = async function ({ api, event, args }) { | |
| const { threadID, messageID } = event; | |
| const action = args[0]?.toLowerCase(); | |
| const subdomain = args[1]; | |
| const port = args[2] ? parseInt(args[2]) : 25622; | |
| if (action === 'start') { | |
| if (tunnel) { | |
| return api.sendMessage('β οΈ *Tunnel is already running!*\nUse `/lt stop` first to restart.', threadID, messageID); | |
| } | |
| if (isNaN(port) || port <= 0 || port > 65535) { | |
| return api.sendMessage('β *Invalid port number.* Please provide a valid port (1β65535).', threadID, messageID); | |
| } | |
| try { | |
| const statusMessage = await api.sendMessage("β³ *Starting LocalTunnel...*", threadID, messageID); | |
| tunnel = await localtunnel({ | |
| port: port, | |
| subdomain: subdomain || undefined | |
| }); | |
| const publicUrl = tunnel.url; | |
| const passwordResponse = await axios.get('https://loca.lt/mytunnelpassword'); | |
| const password = passwordResponse.data || 'No password provided'; | |
| api.editMessage(`π *LocalTunnel Started!*\n\nπ *URL:* ${publicUrl}\nπ *Port:* ${port}\nπ *Password:* ${password}`, statusMessage.messageID, threadID); | |
| tunnel.on('close', () => { | |
| api.sendMessage('π *LocalTunnel connection closed.*', threadID); | |
| tunnel = null; | |
| }); | |
| } catch (error) { | |
| console.error(error); | |
| return api.sendMessage('β *Failed to start LocalTunnel.* Make sure the custom subdomain and port are available or try again later.', threadID, messageID); | |
| } | |
| } else if (action === 'stop') { | |
| if (tunnel) { | |
| tunnel.close(); | |
| return api.sendMessage('π *LocalTunnel stopped successfully.*', threadID, messageID); | |
| } else { | |
| return api.sendMessage('β οΈ *No active LocalTunnel connection to stop.*', threadID, messageID); | |
| } | |
| } else if (action === 'pause') { | |
| return api.sendMessage('βΈοΈ *LocalTunnel paused.* You can restart it with `/lt start`.', threadID, messageID); | |
| } else { | |
| return api.sendMessage( | |
| 'β‘ *LocalTunnel Command Guide:*\n\n' + | |
| '`/lt start` β Start a tunnel with a random subdomain and default port (25622).\n' + | |
| '`/lt start <subdomain>` β Start a tunnel with a custom subdomain and default port (25622).\n' + | |
| '`/lt start <subdomain> <port>` β Start a tunnel with a custom subdomain and custom port.\n' + | |
| '`/lt stop` β Stop the current tunnel.\n' + | |
| '`/lt pause` β Pause the tunnel connection (temporarily).', | |
| threadID, | |
| messageID | |
| ); | |
| } | |
| }; |