File size: 3,262 Bytes
2821330 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
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
);
}
}; |