put notes/9a17c6ec-0756-422e-9dae-5164f6310135.json
Browse files
notes/9a17c6ec-0756-422e-9dae-5164f6310135.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "9a17c6ec-0756-422e-9dae-5164f6310135",
|
3 |
+
"title": "theme.js",
|
4 |
+
"content": "\"use strict\";\n\nconst axios = require(\"axios\");\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst os = require(\"os\");\nconst { once } = require(\"events\");\n\nmodule.exports.zuckbotconfig = {\n name: \"theme\",\n version: \"1.4.2\",\n role: 0,\n author: \"Twan\",\n info: \"Tạo theme AI (preview) + gửi ảnh sáng/tối, áp dụng qua reply\",\n Category: \"Admin\",\n usages: \"[prompt]\",\n cd: 5,\n shadowPrefix: true\n};\n\n// helpers\nconst tmp = p => path.join(os.tmpdir(), p);\nconst sleep = ms => new Promise(r => setTimeout(r, ms));\nconst themeAsync = (api, threadID, opts) =>\n new Promise((res, rej) => api.theme(threadID, opts, (e, d) => (e ? rej(e) : res(d))));\nconst sendAsync = (api, threadID, msg, replyTo) =>\n new Promise(r => api.sendMessage(msg, threadID, (_, info) => r(info), replyTo));\n\n// --- FIX(1): thêm header fbcdn\nconst HTTP_HEADERS = {\n \"User-Agent\": \"Mozilla/5.0\",\n \"Referer\": \"https://www.facebook.com/\"\n};\n\nasync function download(url) {\n if (!url) return null;\n const file = tmp(`theme_${Date.now()}_${Math.random().toString(36).slice(2)}.jpg`);\n try {\n const res = await axios.get(url, { responseType: \"stream\", timeout: 20000, headers: HTTP_HEADERS });\n const w = fs.createWriteStream(file);\n res.data.pipe(w);\n await once(w, \"finish\");\n return file;\n } catch {\n try { fs.unlinkSync(file); } catch {}\n return null;\n }\n}\n\nfunction card(name, id) {\n return `[# THEME AI PREVIEW]\\n\\nName: ${name || \"Không tên\"}\\nID: ${id}\\n\\n→ Reply \"s\" để áp dụng chủ đề này\\n→ Reply prompt để tạo lại chủ đề`;\n}\n\nfunction pickPreviewUrls(gen) {\n const light = gen.lightUrl || gen.iconLight || gen.iconUrl || null;\n const dark = gen.darkUrl || gen.iconDark || gen.iconUrl || null;\n return { light, dark };\n}\n\nasync function attachPreview(gen) {\n const files = [];\n const { light, dark } = pickPreviewUrls(gen);\n const fLight = await download(light);\n const fDark = await download(dark);\n if (fLight) files.push(fs.createReadStream(fLight));\n if (fDark) files.push(fs.createReadStream(fDark));\n return { files, paths: [fLight, fDark].filter(Boolean) };\n}\n\nfunction getReplyStore() {\n global.zuckbot = global.zuckbot || {};\n global.zuckbot.onReply = global.zuckbot.onReply || [];\n return global.zuckbot.onReply;\n}\nfunction pushHandleReply(ctx) {\n const store = getReplyStore();\n store.push(ctx);\n}\nfunction replaceHandleReplyByMsgID(oldMsgID, nextCtx) {\n const store = getReplyStore();\n const next = store.filter(h => h.messageID !== oldMsgID);\n next.push(nextCtx);\n global.zuckbot.onReply = next;\n}\n\nasync function safeUnlinkMany(paths) {\n for (const p of paths) {\n try { fs.unlinkSync(p); } catch {}\n }\n}\n\nmodule.exports.onRun = async function ({ api, event, args }) {\n const threadID = event.threadID;\n const prompt = args.length ? args.join(\" \") : \"anime\";\n\n try {\n const gen = await themeAsync(api, threadID, { aiPrompt: prompt, dryRun: true });\n const { files, paths } = await attachPreview(gen);\n\n const info = await sendAsync(\n api,\n threadID,\n { body: card(gen.themeName, gen.themeId), attachment: files.length ? files : undefined },\n event.messageID\n );\n\n await sleep(100);\n await safeUnlinkMany(paths);\n\n if (info?.messageID) {\n pushHandleReply({\n name: module.exports.zuckbotconfig.name,\n messageID: info.messageID,\n author: event.senderID,\n threadID,\n themeId: gen.themeId,\n type: \"_handleReply\"\n });\n }\n } catch (e) {\n return api.sendMessage(`❌ Lỗi tạo theme: ${e?.message || e}`, threadID, undefined, event.messageID);\n }\n};\n\nmodule.exports.onReply = async function ({ api, event, onReply }) {\n if (!onReply || event.threadID !== onReply.threadID) return;\n if (event.senderID !== onReply.author) return;\n\n const text = (event.body || \"\").trim();\n if (!text) return;\n\n if (text.toLowerCase() === \"s\") {\n try {\n await themeAsync(api, onReply.threadID, { themeId: onReply.themeId });\n return api.sendMessage(`✅ Đã áp dụng chủ đề ID: ${onReply.themeId}`, onReply.threadID);\n } catch (e) {\n return api.sendMessage(`❌ Lỗi áp dụng: ${e?.message || e}`, onReply.threadID);\n }\n }\n\n try {\n const gen = await themeAsync(api, onReply.threadID, { aiPrompt: text, dryRun: true });\n const { files, paths } = await attachPreview(gen);\n\n const info = await sendAsync(api, onReply.threadID, {\n body: card(gen.themeName, gen.themeId),\n attachment: files.length ? files : undefined\n });\n\n await sleep(100);\n await safeUnlinkMany(paths);\n\n if (info?.messageID) {\n replaceHandleReplyByMsgID(\n onReply.messageID,\n {\n name: module.exports.zuckbotconfig.name,\n messageID: info.messageID,\n author: event.senderID,\n threadID: onReply.threadID,\n themeId: gen.themeId,\n type: \"_handleReply\"\n }\n );\n }\n } catch (e) {\n return api.sendMessage(`❌ Lỗi tạo lại theme: ${e?.message || e}`, onReply.threadID);\n }\n};",
|
5 |
+
"language": "javascript",
|
6 |
+
"createdAt": 1756996019674,
|
7 |
+
"updatedAt": 1756996019674
|
8 |
+
}
|