const axios = require("axios"); const fs = require("fs"); const path = require("path"); module.exports = { config: { name: "ytstalk", aliases: ["ytinfo"], author: "Saimx69x", version: "1.0", role: 0, countDown: 5, description: "Fetch YouTube channel info including subscribers, views, join date, description, thumbnail.", category: "information", guide: "{p}ytstalk " }, onStart: async function ({ api, event, args }) { const channelName = args.join(" ").trim(); const FONT_URL = "https://raw.githubusercontent.com/Saim-x69x/sakura/main/xfont.json"; const fontRes = await axios.get(FONT_URL); const fontMap = fontRes.data; const applyFont = (text) => text.split("").map(c => { if ((c >= "A" && c <= "Z") || (c >= "a" && c <= "z") || (c >= "0" && c <= "9")) return fontMap[c] || c; return c; }).join(""); if (!channelName) { return api.sendMessage( applyFont("āš ļø Please provide a YouTube channel name.\nUsage: /ytstalk MrBeast"), event.threadID, event.messageID ); } try { const GITHUB_RAW_API = "https://raw.githubusercontent.com/Saim-x69x/sakura/main/ApiUrl.json"; const rawApiRes = await axios.get(GITHUB_RAW_API); const apiBase = rawApiRes.data.apiv1; const apiUrl = `${apiBase}/api/ytinfo?channel=${encodeURIComponent(channelName)}`; const response = await axios.get(apiUrl); const data = response.data; if (!data.status) { return api.sendMessage( applyFont(`āŒ Failed to fetch info for channel: ${channelName}`), event.threadID, event.messageID ); } const info = data.channelInfo; const message = `${applyFont("šŸ“ŗ YouTube Channel Info")}\n━━━━━━━━━━━━━━\n` + `${applyFont("šŸ·ļø Channel:")} ${applyFont(info.title)}\n` + `${applyFont("šŸ†” ID:")} ${applyFont(data.channelId || info.channelId)}\n` + `${applyFont("šŸŒ Country:")} ${info.country}\n` + `${applyFont("šŸ“… Joined:")} ${info.publishedAt}\n` + `${applyFont("šŸ‘„ Subscribers:")} ${applyFont(info.subscribers)}\n` + `${applyFont("šŸ‘ļø Views:")} ${applyFont(info.views)}\n` + `${applyFont("šŸŽ¬ Videos:")} ${applyFont(info.videos)}\n\n` + `${applyFont("šŸ“ Description:")}\n${applyFont(info.description.substring(0, 600))}${info.description.length > 600 ? "..." : ""}`; if (info.thumbnail) { const imgPath = path.join(__dirname, `yt_${data.channelId}.jpg`); const writer = fs.createWriteStream(imgPath); const imgRes = await axios.get(info.thumbnail, { responseType: "stream" }); imgRes.data.pipe(writer); writer.on("finish", () => { api.sendMessage( { body: message, attachment: fs.createReadStream(imgPath) }, event.threadID, () => { try { fs.unlinkSync(imgPath); } catch {} }, event.messageID ); }); writer.on("error", (e) => { console.error(e); api.sendMessage(message, event.threadID, event.messageID); }); } else { api.sendMessage(message, event.threadID, event.messageID); } } catch (err) { console.error(err); api.sendMessage( applyFont("āŒ Error occurred while fetching channel info. Please check the channel name or try again later."), event.threadID, event.messageID ); } } };