Created
December 16, 2025 09:20
-
-
Save ONLym22/48ecf6badcf4fb744cb0197357ec19f1 to your computer and use it in GitHub Desktop.
ONLym BOT Gist Uploaded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fs = require("fs"); | |
| const axios = require("axios"); | |
| const crypto = require("crypto"); | |
| const githubToken = "Isi_Github_Token"; // Ganti dengan token GitHub-mu | |
| const owner = "Isi_Username_Github"; // Ganti dengan username GitHub-mu | |
| const branch = "main"; | |
| const repoDefault = "uploader"; // Nama repo default kalau belum ada | |
| // ====== Fungsi cek dan buat repo ====== | |
| async function ensureRepoExists(repoName) { | |
| try { | |
| await axios.get(`https://api.github.com/repos/${owner}/${repoName}`, { | |
| headers: { Authorization: `Bearer ${githubToken}` } | |
| }); | |
| return repoName; | |
| } catch (err) { | |
| if (err.response && err.response.status === 404) { | |
| // Repo belum ada, buat repo baru | |
| const res = await axios.post( | |
| "https://api.github.com/user/repos", | |
| { name: repoName, private: false }, | |
| { headers: { Authorization: `Bearer ${githubToken}` } } | |
| ); | |
| return res.data.name; | |
| } else { | |
| throw err; | |
| } | |
| } | |
| } | |
| // ====== Fungsi Upload ====== | |
| async function uploadFile(filePath) { | |
| const buffer = fs.readFileSync(filePath); | |
| const ext = filePath.split(".").pop() || "jpg"; | |
| const fileName = `${crypto.randomBytes(3).toString("hex")}-${Date.now()}.${ext}`; | |
| const filePathGitHub = `uploads/${fileName}`; | |
| const base64Content = buffer.toString("base64"); | |
| const actualRepo = await ensureRepoExists(repoDefault); | |
| await axios.put( | |
| `https://api.github.com/repos/${owner}/${actualRepo}/contents/${filePathGitHub}`, | |
| { | |
| message: `Upload file ${fileName}`, | |
| content: base64Content, | |
| branch: branch | |
| }, | |
| { | |
| headers: { | |
| Authorization: `Bearer ${githubToken}`, | |
| "X-GitHub-Api-Version": "2022-11-28", | |
| "Accept": "application/vnd.github+json" | |
| } | |
| } | |
| ); | |
| fs.unlinkSync(filePath); | |
| return `https://raw.githubusercontent.com/${owner}/${actualRepo}/${branch}/${filePathGitHub}`; | |
| } | |
| // ====== Handler Bot ====== | |
| let handler = async (m, { vellia }) => { | |
| try { | |
| const q = m.quoted ? m.quoted : m; | |
| const mime = q.mimetype || ""; | |
| if (!mime || !/image|video|audio|webp/.test(mime)) | |
| return m.reply("⚠️ Reply file yang valid (foto/video/audio/sticker)"); | |
| m.reply("⏳ Sedang mengunggah..."); | |
| const tempFile = await vellia.downloadAndSaveMediaMessage(q); | |
| const url = await uploadFile(tempFile); | |
| await vellia.sendMessage( | |
| m.chat, | |
| { | |
| text: `✅ *Uploader Sukses*\n\n📎 URL:\n${url}`, | |
| interactiveButtons: [ | |
| { | |
| name: "cta_copy", | |
| buttonParamsJson: JSON.stringify({ | |
| display_text: "📋 Salin URL", | |
| copy_code: url | |
| }), | |
| }, | |
| ], | |
| footer: "© GitHub Uploader", | |
| }, | |
| { quoted: m } | |
| ); | |
| } catch (e) { | |
| console.error("PLUGIN tourl ERROR:", e); | |
| m.reply(`❌ Error: ${e.response?.data?.message || e.message || e}`); | |
| } | |
| }; | |
| handler.help = ["tourl", "tourlgithub", "upload"]; | |
| handler.tags = ["tools"]; | |
| handler.command = ["tourl"]; | |
| module.exports = handler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment