put notes/9d5bfc45-b56e-43c0-8a61-70de54f88ba2.json
Browse files
notes/9d5bfc45-b56e-43c0-8a61-70de54f88ba2.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "9d5bfc45-b56e-43c0-8a61-70de54f88ba2",
|
3 |
+
"title": "1anh.js",
|
4 |
+
"content": "const axios = require(\"axios\");\nconst path = require(\"path\");\n\nmodule.exports.config = {\n name: \"imgRandom\",\n version: \"1.0.0\",\n hasPermssion: 0,\n credits: \"GPT\",\n description: \"Random ảnh từ link JSON (noprefix)\",\n commandCategory: \"fun\",\n usages: \"gai / boy / meme\",\n cooldowns: 3,\n usePrefix: false\n};\n\nasync function checkLink(url) {\n try {\n const res = await axios.head(url, { timeout: 5000 });\n return { ok: true, size: parseInt(res.headers[\"content-length\"] || \"0\") };\n } catch {\n return { ok: false, size: 0 };\n }\n}\n\nmodule.exports.handleEvent = async ({ api, event }) => {\n const { body, threadID } = event;\n if (!body) return;\n\n // Các keyword và file JSON\n const keywords = {\n \"gai\": \"gai.json\",\n \"boy\": \"boy.json\",\n \"xloli\": \"xloli.json\"\n };\n\n const key = body.toLowerCase();\n if (!keywords[key]) return;\n\n try {\n const filePath = path.join(__dirname, `./../../gojo/datajson/${keywords[key]}`);\n const imgList = require(filePath);\n const imgs = Object.values(imgList);\n\n // Random ảnh\n let randomUrl, check, tries = 0;\n do {\n randomUrl = imgs[Math.floor(Math.random() * imgs.length)];\n check = await checkLink(randomUrl);\n tries++;\n } while (!check.ok && tries < 10);\n\n if (!check.ok) {\n return api.sendMessage(`❌ Không tìm được ảnh nào hoạt động trong ${key}!`, threadID);\n }\n\n // Gửi ảnh trực tiếp (ảnh hầu hết < 5MB nên nhanh)\n const response = await axios.get(randomUrl, { responseType: \"stream\" });\n api.sendMessage({\n body: `📷 Ảnh ${key} của bạn đây:`,\n attachment: response.data\n }, threadID);\n\n } catch (e) {\n api.sendMessage(\"❌ Có lỗi xảy ra khi tải ảnh!\", threadID);\n console.error(e);\n }\n};\n\nmodule.exports.run = async () => {};\n",
|
5 |
+
"language": "javascript",
|
6 |
+
"createdAt": 1756484994542,
|
7 |
+
"updatedAt": 1756484994542
|
8 |
+
}
|