Last active
December 20, 2025 09:42
-
-
Save manzxy/77463e28e9e14cd71bdad9404dd1681f to your computer and use it in GitHub Desktop.
Uploaded via YogiriMD
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
| import fetch from "node-fetch" | |
| const GITHUB_API = "https://api.github.com" | |
| let handler = async (m, { text, command, isOwner }) => { | |
| if (!isOwner) return m.reply("β Khusus owner") | |
| if (!setting?.gittoken) | |
| return m.reply("β GitHub token belum di-set di setting.gittoken") | |
| if (!text) | |
| return m.reply( | |
| `π *GIST MANAGER* | |
| Buat gist: | |
| .upgist <nama_file> <public|private> | |
| <kode> | |
| Edit gist: | |
| .upgist edit <gist_id> | |
| <kode baru> | |
| Delete gist: | |
| .upgist delete <gist_id> | |
| List gist: | |
| .upgist list | |
| Preview gist: | |
| .upgist preview <gist_id>` | |
| ) | |
| const token = setting.gittoken // setting token dsni! sesuaikan saja , dan ambol token di https://github.com/settings/tokens | |
| const headers = { | |
| Authorization: `token ${token}`, | |
| "Content-Type": "application/json", | |
| "User-Agent": "YogiriMD" | |
| } | |
| // ========================= | |
| // RAW MULTILINE | |
| // ========================= | |
| const raw = m.text.replace(/^\.upgist\s*/i, "") | |
| const lines = raw.split("\n") | |
| const firstLine = lines.shift().trim() | |
| const bodyText = lines.join("\n").trim() | |
| const args = firstLine.split(/\s+/) | |
| // ========================= | |
| // LIST | |
| // ========================= | |
| if (args[0] === "list") { | |
| const res = await fetch(`${GITHUB_API}/gists`, { headers }) | |
| const data = await res.json() | |
| if (!Array.isArray(data) || !data.length) | |
| return m.reply("π Tidak ada gist") | |
| let out = "π *DAFTAR GIST*\n\n" | |
| data.slice(0, 10).forEach((g, i) => { | |
| const file = Object.keys(g.files)[0] | |
| out += `${i + 1}. ${file}\n` | |
| out += ` ID: ${g.id}\n` | |
| out += ` ${g.public ? "π Public" : "π Private"}\n\n` | |
| }) | |
| return m.reply(out.trim()) | |
| } | |
| // ========================= | |
| // PREVIEW (FULL) | |
| // ========================= | |
| if (args[0] === "preview") { | |
| const id = args[1] | |
| if (!id) return m.reply("β Masukkan gist_id") | |
| const res = await fetch(`${GITHUB_API}/gists/${id}`, { headers }) | |
| const json = await res.json() | |
| if (json.message) throw json.message | |
| const file = Object.values(json.files)[0] | |
| return m.reply( | |
| `π *PREVIEW GIST (FULL)* | |
| Nama : ${file.filename} | |
| Type : ${file.language || "Unknown"} | |
| Mode : ${json.public ? "Public" : "Private"} | |
| Link : ${json.html_url} | |
| \`\`\` | |
| ${file.content} | |
| \`\`\`` | |
| ) | |
| } | |
| // ========================= | |
| // DELETE | |
| // ========================= | |
| if (args[0] === "delete") { | |
| const id = args[1] | |
| if (!id) return m.reply("β Masukkan gist_id") | |
| const res = await fetch(`${GITHUB_API}/gists/${id}`, { | |
| method: "DELETE", | |
| headers | |
| }) | |
| if (res.status === 204) | |
| return m.reply("β Gist berhasil dihapus") | |
| throw "Gagal menghapus gist" | |
| } | |
| // ========================= | |
| // EDIT (MULTILINE) | |
| // ========================= | |
| if (args[0] === "edit") { | |
| const id = args[1] | |
| if (!id || !bodyText) | |
| return m.reply( | |
| "β Format:\n.upgist edit <gist_id>\n<kode baru>" | |
| ) | |
| const get = await fetch(`${GITHUB_API}/gists/${id}`, { headers }) | |
| const json = await get.json() | |
| if (json.message) throw json.message | |
| const filename = Object.keys(json.files)[0] | |
| const res = await fetch(`${GITHUB_API}/gists/${id}`, { | |
| method: "PATCH", | |
| headers, | |
| body: JSON.stringify({ | |
| files: { | |
| [filename]: { content: bodyText } | |
| } | |
| }) | |
| }) | |
| const out = await res.json() | |
| if (out.message) throw out.message | |
| return m.reply( | |
| `βοΈ *GIST UPDATED* | |
| File : ${filename} | |
| Link : ${out.html_url}` | |
| ) | |
| } | |
| // ========================= | |
| // CREATE (MULTILINE) | |
| // ========================= | |
| const filename = args[0] | |
| const visibility = args[1] | |
| if (!filename || !visibility || !bodyText) | |
| return m.reply( | |
| "β Format:\n.upgist <nama_file> <public|private>\n<kode>" | |
| ) | |
| const isPublic = | |
| visibility === "public" | |
| ? true | |
| : visibility === "private" | |
| ? false | |
| : null | |
| if (isPublic === null) | |
| return m.reply("β visibility harus public / private") | |
| const body = { | |
| description: "Uploaded via YogiriMD", | |
| public: isPublic, | |
| files: { | |
| [filename]: { | |
| content: bodyText | |
| } | |
| } | |
| } | |
| const res = await fetch(`${GITHUB_API}/gists`, { | |
| method: "POST", | |
| headers, | |
| body: JSON.stringify(body) | |
| }) | |
| const json = await res.json() | |
| if (json.message) throw json.message | |
| return m.reply( | |
| `β *GIST BERHASIL DIBUAT* | |
| File : ${filename} | |
| Type : ${filename.split(".").pop()} | |
| Mode : ${isPublic ? "Public" : "Private"} | |
| Link : ${json.html_url}` | |
| ) | |
| } | |
| handler.help = ["upgist"] | |
| handler.tags = ["owner"] | |
| handler.command = /^upgist$/i | |
| handler.owner = true | |
| export default handler |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment