Jonell01's picture
Upload 64 files
2821330 verified
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
);
}
};