Skip to content

Instantly share code, notes, and snippets.

@manzxy
Last active December 20, 2025 09:42
Show Gist options
  • Select an option

  • Save manzxy/77463e28e9e14cd71bdad9404dd1681f to your computer and use it in GitHub Desktop.

Select an option

Save manzxy/77463e28e9e14cd71bdad9404dd1681f to your computer and use it in GitHub Desktop.
Uploaded via YogiriMD
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