Skip to content

Commit

Permalink
stable
Browse files Browse the repository at this point in the history
  • Loading branch information
besoeasy authored Nov 6, 2024
1 parent fc75efa commit 77f34d1
Showing 1 changed file with 48 additions and 51 deletions.
99 changes: 48 additions & 51 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,39 +39,36 @@ const commands = [
];

const handleAbout = (ctx) => {
ctx.reply("πŸ”— GitHub Repo: [TeleAria](https://github.com/besoeasy/telearia)");
ctx.reply("GitHub Repo: TeleAria (https://github.com/besoeasy/telearia)");
};

const handleStart = (ctx) => {
const userIdHash = cleanUser(ctx.chat.id);
const downloadUrl = process.env.TUNNELURL || "http://pi.local:6799";
ctx.replyWithMarkdown(`
**Welcome to TeleAria!** πŸŽ‰
πŸ”Ή **Version:** ${version}
πŸ”Ή **User ID:** ${userIdHash}
πŸ”Ή **Your Downloads:** [Manage here](${downloadUrl}/${userIdHash}/)
**Available Commands:**
${commands.map((cmd) => `πŸ”Έ ${cmd}`).join("\n")}
`);
ctx.reply(
`Welcome to TeleAria! πŸŽ‰\n\n` +
`Version: ${version}\n` +
`User ID: ${userIdHash}\n` +
`Your Downloads: Manage here at ${downloadUrl}/${userIdHash}/\n\n` +
`Available Commands:\n` +
commands.map((cmd) => `- ${cmd}`).join("\n")
);
};

const handleStats = async (ctx) => {
try {
const { result: stats } = await getGlobalStats();
ctx.replyWithMarkdown(`
**πŸ“Š Global Stats:**
πŸ”Ή **Download Speed:** ${bytesToSize(stats.downloadSpeed)}
πŸ”Ή **Upload Speed:** ${bytesToSize(stats.uploadSpeed)}
πŸ”Ή **Active Downloads:** ${stats.numActive}
πŸ”Ή **Waiting Downloads:** ${stats.numWaiting}
πŸ”Ή **Stopped Downloads:** ${stats.numStopped}
`);
ctx.reply(
`Global Stats:\n\n` +
`Download Speed: ${bytesToSize(stats.downloadSpeed)}\n` +
`Upload Speed: ${bytesToSize(stats.uploadSpeed)}\n` +
`Active Downloads: ${stats.numActive}\n` +
`Waiting Downloads: ${stats.numWaiting}\n` +
`Stopped Downloads: ${stats.numStopped}`
);
} catch (error) {
console.error(error);
ctx.reply("⚠️ Failed to retrieve stats. Please try again later.");
ctx.reply("Failed to retrieve stats. Please try again later.");
}
};

Expand All @@ -86,7 +83,7 @@ const handleDownload = async (ctx, url) => {
);
} catch (error) {
console.error(error);
ctx.reply("⚠️ Failed to start download. Please try again later.");
ctx.reply("Failed to start download. Please try again later.");
}
};

Expand All @@ -102,53 +99,53 @@ const handleStatus = async (ctx, downloadId) => {
2
);

let reply = `**πŸ” Download Status:**\n\n**Status:** ${downloadData.result.status}\n**Progress:** ${completedSize} MB / ${totalSize} MB`;
let reply = `Download Status:\n\nStatus: ${downloadData.result.status}\n` +
`Progress: ${completedSize} MB / ${totalSize} MB`;

if (downloadData.result.status === "active") {
reply += `\nπŸ”Έ **Cancel with** /cancel_${downloadId}`;
reply += `\nCancel with /cancel_${downloadId}`;
} else if (downloadData.result.status === "complete") {
const files = downloadData.result.files
.map((file) => file.path)
.join("\n");
reply += `\nπŸ”Ή **Downloaded Files:**\n${files}`;
reply += `\nDownloaded Files:\n${files}`;
}

ctx.replyWithMarkdown(reply);
ctx.reply(reply);
} catch (error) {
console.error(error);
ctx.reply(
`⚠️ Failed to retrieve status for download ID: ${downloadId}. Please try again later.`
`Failed to retrieve status for download ID: ${downloadId}. Please try again later.`
);
}
};

const handleCancel = async (ctx, downloadId) => {
try {
await cancelDownload(downloadId);
ctx.reply(`βœ… **Download with ID ${downloadId} canceled successfully.**`);
ctx.reply(`Download with ID ${downloadId} canceled successfully.`);
} catch (error) {
console.error(error);
ctx.reply(
`⚠️ Failed to cancel download with ID: ${downloadId}. Please try again later.`
`Failed to cancel download with ID: ${downloadId}. Please try again later.`
);
}
};

const handleIpData = async (ctx) => {
try {
const ipData = await getIpData();
ctx.replyWithMarkdown(`
**🌍 Server IP Information:**
πŸ”Ή **IP:** ${ipData.query}
πŸ”Ή **Country:** ${ipData.country}
πŸ”Ή **Region:** ${ipData.regionName}
πŸ”Ή **City:** ${ipData.city}
πŸ”Ή **ISP:** ${ipData.isp}
`);
ctx.reply(
`Server IP Information:\n\n` +
`IP: ${ipData.query}\n` +
`Country: ${ipData.country}\n` +
`Region: ${ipData.regionName}\n` +
`City: ${ipData.city}\n` +
`ISP: ${ipData.isp}`
);
} catch (error) {
console.error(error);
ctx.reply("⚠️ Failed to retrieve IP data. Please try again later.");
ctx.reply("Failed to retrieve IP data. Please try again later.");
}
};

Expand All @@ -157,7 +154,7 @@ const downloading = async (ctx) => {
const { result: ongoingDownloads } = await getOngoingDownloads();

if (ongoingDownloads.length > 0) {
let reply = "πŸ“₯ **Ongoing Downloads** πŸ“₯\n\n";
let reply = "Ongoing Downloads:\n\n";

for (const download of ongoingDownloads) {
const { gid, completedLength, totalLength, status } = download;
Expand All @@ -166,20 +163,20 @@ const downloading = async (ctx) => {
const totalSize = (totalLength / 1024 / 1024).toFixed(2);
const progress = ((completedLength / totalLength) * 100).toFixed(2);

reply += `πŸ†” **ID**: /status_${gid}\n`;
reply += `πŸ“Š **Status**: ${status}\n`;
reply += `πŸ“ˆ **Progress**: ${downloadedSize} MB / ${totalSize} MB (${progress}%)\n`;
reply += `────────────────────────────\n\n`;
reply += `ID: /status_${gid}\n`;
reply += `Status: ${status}\n`;
reply += `Progress: ${downloadedSize} MB / ${totalSize} MB (${progress}%)\n`;
reply += `-----------------------------\n\n`;
}

ctx.replyWithMarkdown(reply);
ctx.reply(reply);
} else {
ctx.reply("βœ… **No ongoing downloads.**");
ctx.reply("No ongoing downloads.");
}
} catch (error) {
console.error(error);
ctx.reply(
"⚠️ Failed to retrieve ongoing downloads. Please try again later."
"Failed to retrieve ongoing downloads. Please try again later."
);
}
};
Expand All @@ -198,7 +195,7 @@ bot.on("message", async (ctx) => {
switch (lowerCaseCommand) {
case "/clean":
deleteOldFiles(process.env.PURGEINTERVAL || 7);
ctx.reply("🧹 **Old files cleaned!**");
ctx.reply("Old files cleaned!");
break;
case "/about":
handleAbout(ctx);
Expand All @@ -218,7 +215,7 @@ bot.on("message", async (ctx) => {
case "/download":
case "/dl":
if (trimmedArgs.length > 0) handleDownload(ctx, trimmedArgs[0]);
else ctx.reply("⚠️ **Please provide a URL to download.**");
else ctx.reply("Please provide a URL to download.");
break;
default:
if (lowerCaseCommand.startsWith("/status_"))
Expand All @@ -227,12 +224,12 @@ bot.on("message", async (ctx) => {
handleCancel(ctx, lowerCaseCommand.split("_")[1]);
else
ctx.reply(
`❔ Unknown command: ${lowerCaseCommand}\n\nType /start to see available commands.`
`Unknown command: ${lowerCaseCommand}\n\nType /start to see available commands.`
);
}
} catch (error) {
console.error(error);
ctx.reply("⚠️ An error occurred. Please try again later.");
ctx.reply("An error occurred. Please try again later.");
}
}
});
Expand Down

0 comments on commit 77f34d1

Please sign in to comment.