put notes/2d5e391d-272d-44dd-8db3-42020054db0f.json
Browse files
notes/2d5e391d-272d-44dd-8db3-42020054db0f.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "2d5e391d-272d-44dd-8db3-42020054db0f",
|
3 |
+
"title": "adc.js",
|
4 |
+
"content": "module.exports.config = {\n name: \"adc\",\n version: \"3.0.1\",\n hasPermssion: 3,\n credits: \"nvh\",\n description: \"Áp dụng code từ link/raw hoặc upload code local lên Gist\",\n commandCategory: \"Admin\",\n usages: \"adc <tên-file> (reply link/raw hoặc không để up code local lên Gist)\",\n cooldowns: 0,\n};\n\nconst fs = require(\"fs\");\nconst path = require(\"path\");\nconst axios = require(\"axios\");\nconst request = require(\"request\");\nconst cheerio = require(\"cheerio\");\n\n// ⚠️ Token GitHub mới (chỉ cần quyền gist)\nconst GITHUB_TOKEN = \"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\";\nconst GIST_API = \"https://api.github.com/gists\";\n\nasync function createGist(fileName, content) {\n const body = {\n description: `Upload ${fileName}.js`,\n public: false,\n files: { [`${fileName}.js`]: { content } }\n };\n const res = await axios.post(GIST_API, body, {\n headers: {\n Authorization: `Bearer ${GITHUB_TOKEN}`, // ✅ Fix 404\n \"User-Agent\": \"Mozilla/5.0\"\n }\n });\n return res.data.files[`${fileName}.js`].raw_url;\n}\n\nasync function downloadFile(url, dest) {\n const writer = fs.createWriteStream(dest);\n const res = await axios.get(url, { responseType: \"stream\" });\n await new Promise((resolve, reject) => {\n res.data.pipe(writer);\n writer.on(\"finish\", resolve);\n writer.on(\"error\", reject);\n });\n}\n\nmodule.exports.run = async function ({ api, event, args }) {\n const { threadID, messageID, messageReply, type } = event;\n const fileName = args[0];\n let text;\n if (type === \"message_reply\") text = messageReply.body;\n\n if (!text && !fileName)\n return api.sendMessage(\n \"⚠️ Vui lòng reply link raw hoặc ghi tên file để up code local lên Gist!\",\n threadID,\n messageID\n );\n\n // CASE 1: UP CODE LOCAL LÊN GIST\n if (!text && fileName) {\n return fs.readFile(\n `${__dirname}/${fileName}.js`,\n \"utf-8\",\n async (err, data) => {\n if (err)\n return api.sendMessage(\n `❎ Không tìm thấy file ${fileName}.js!`,\n threadID,\n messageID\n );\n\n try {\n const rawLink = await createGist(fileName, data);\n return api.sendMessage(\n `✅ Upload thành công!\\n📄 Raw: ${rawLink}`,\n threadID,\n messageID\n );\n } catch (e) {\n return api.sendMessage(\n `❎ Lỗi khi upload lên Gist: ${e.response?.status || \"\"} ${\n e.response?.data?.message || e.message\n }`,\n threadID,\n messageID\n );\n }\n }\n );\n }\n\n // CASE 2: REPLY LINK RAW ĐỂ ÁP DỤNG\n const urlR =\n /https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)/g;\n const urls = text ? text.match(urlR) : null;\n if (!urls || !urls[0])\n return api.sendMessage(\"❎ Không tìm thấy link hợp lệ!\", threadID, messageID);\n\n const url = urls[0];\n const filePath = path.join(__dirname, `${fileName}.js`);\n\n try {\n // buildtool / tinyurl\n if (url.includes(\"buildtool\") || url.includes(\"tinyurl\")) {\n request(url, (err, response, body) => {\n if (err) return api.sendMessage(\"❎ Lỗi tải link!\", threadID, messageID);\n const $ = cheerio.load(body);\n const code = $(\".language-js\").first().text() || $(\"pre\").first().text();\n fs.writeFileSync(filePath, code, \"utf8\");\n reloadModule(api, threadID, messageID, fileName);\n });\n return;\n }\n\n // Google Drive\n if (url.includes(\"drive.google\")) {\n const id = url.match(/[-\\w]{25,}/);\n await downloadFile(\n `https://drive.google.com/u/0/uc?id=${id}&export=download`,\n filePath\n );\n return reloadModule(api, threadID, messageID, fileName);\n }\n\n // Note API\n if (url.includes(\"/note\")) {\n const raw = url.includes(\"raw=true\") ? url : url + \"?raw=true\";\n const res = await axios.get(raw);\n fs.writeFileSync(filePath, res.data, \"utf8\");\n return reloadModule(api, threadID, messageID, fileName);\n }\n\n // Gist / Github / Pastebin / Dpaste (link raw)\n const res = await axios.get(url);\n fs.writeFileSync(filePath, res.data, \"utf8\");\n return reloadModule(api, threadID, messageID, fileName);\n } catch (e) {\n return api.sendMessage(\n `❎ Lỗi khi áp dụng code: ${e.message}`,\n threadID,\n messageID\n );\n }\n};\n\nfunction reloadModule(api, threadID, messageID, fileName) {\n try {\n const dir = path.join(__dirname, `${fileName}.js`);\n delete require.cache[require.resolve(dir)];\n global.client.commands.delete(fileName);\n const newCommand = require(dir);\n global.client.commands.set(newCommand.config.name, newCommand);\n\n api.sendMessage(\n `☑️ Đã áp dụng & load lại module \"${fileName}.js\" thành công!`,\n threadID,\n messageID\n );\n } catch (e) {\n api.sendMessage(\n `⚠️ Code đã ghi nhưng lỗi khi load lại module: ${e.message}`,\n threadID,\n messageID\n );\n }\n}",
|
5 |
+
"language": "javascript",
|
6 |
+
"createdAt": 1755533336837,
|
7 |
+
"updatedAt": 1755533336837
|
8 |
+
}
|