put notes/45952b5d-8228-48f0-99de-99deb79e8da6.json
Browse files
notes/45952b5d-8228-48f0-99de-99deb79e8da6.json
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"id": "45952b5d-8228-48f0-99de-99deb79e8da6",
|
3 |
+
"title": "check.js",
|
4 |
+
"content": "const fs = require(\"fs-extra\");\nconst path = __dirname + '/kiemtra/';\nconst configPath = __dirname + '/tt-config.json';\nconst moment = require('moment-timezone');\nconst axios = require(\"axios\");\nconst downloader = require('image-downloader');\n\nasync function streamURL(url, mime = 'jpg') {\n const dest = `${__dirname}/cache/${Date.now()}.${mime}`;\n await downloader.image({ url, dest });\n setTimeout(() => fs.unlinkSync(dest), 60 * 1000);\n return fs.createReadStream(dest);\n}\n\nmodule.exports.config = {\n name: \"check\",\n version: \"2.1.9\",\n hasPermssion: 0,\n credits: \"PTT & Modified by Grok\",\n description: \"Check tương tác + lọc, reset, auto lọc tuần\",\n commandCategory: \"Tiện ích\" ,\n usages: \"[all/week/day/reset/loc <số>/auto-loc <số>]\",\n cooldowns: 0,\n dependencies: {\n \"fs-extra\": \"\",\n \"moment-timezone\": \"\",\n \"axios\": \"\",\n \"image-downloader\": \"\"\n }\n};\n\nmodule.exports.onLoad = () => {\n if (!fs.existsSync(path)) fs.mkdirSync(path, { recursive: true });\n if (!fs.existsSync(configPath)) fs.writeFileSync(configPath, JSON.stringify({}, null, 4));\n global.checkttConfig = JSON.parse(fs.readFileSync(configPath));\n\n setInterval(() => {\n const today = moment.tz(\"Asia/Ho_Chi_Minh\").day();\n const files = fs.readdirSync(path);\n files.forEach(file => {\n try {\n let data = JSON.parse(fs.readFileSync(path + file));\n if (data.time !== today) {\n data.day = data.day.map(u => ({ ...u, count: 0 }));\n data.time = today;\n fs.writeFileSync(path + file, JSON.stringify(data, null, 4));\n }\n\n const threadID = file.replace('.json', '');\n const threshold = global.checkttConfig[threadID];\n if (today === 1 && threshold !== undefined) {\n const toRemove = data.total.filter(u => u.count <= threshold && u.id != global.data.botID);\n let removed = toRemove.length;\n data.total = data.total.filter(u => u.count > threshold || u.id == global.data.botID);\n fs.writeFileSync(path + file, JSON.stringify(data, null, 4));\n if (removed > 0) {\n global.api.sendMessage(`🔔 Auto lọc: Đã loại bỏ ${removed} thành viên có số tin nhắn dưới ${threshold}`, threadID);\n }\n }\n } catch (err) {\n console.error(`Lỗi khi xử lý file ${file}:`, err);\n }\n });\n }, 60000);\n};\n\nmodule.exports.handleEvent = async function({ api, event }) {\n try {\n if (!event.isGroup || global.client.sending_top) return;\n const { threadID, senderID, participantIDs } = event;\n const today = moment.tz(\"Asia/Ho_Chi_Minh\").day();\n const filePath = path + threadID + '.json';\n let data = fs.existsSync(filePath) ? JSON.parse(fs.readFileSync(filePath)) : { total: [], week: [], day: [], time: today };\n const userList = participantIDs || [];\n userList.forEach(user => {\n ['total', 'week', 'day'].forEach(type => {\n if (!data[type].some(e => e.id == user)) data[type].push({ id: user, count: 0 });\n });\n });\n if (data.time !== today) {\n global.client.sending_top = true;\n setTimeout(() => global.client.sending_top = false, 300000);\n }\n ['total', 'week', 'day'].forEach(type => {\n const index = data[type].findIndex(e => e.id == senderID);\n if (index > -1) data[type][index].count++;\n });\n const activeIDs = userList.map(String);\n ['total', 'week', 'day'].forEach(type => {\n data[type] = data[type].filter(e => activeIDs.includes(String(e.id)));\n });\n fs.writeFileSync(filePath, JSON.stringify(data, null, 4));\n } catch (err) {\n console.error(`Lỗi khi xử lý sự kiện tương tác:`, err);\n }\n};\n\nmodule.exports.run = async function({ api, event, args, Users, Threads }) {\n const { threadID, senderID } = event;\n const filePath = path + threadID + '.json';\n if (!fs.existsSync(filePath)) return api.sendMessage(\"⚠️ Chưa có dữ liệu\", threadID);\n let data = JSON.parse(fs.readFileSync(filePath));\n const query = args[0] ? args[0].toLowerCase() : '';\n let targetID = senderID; // Mặc định là bản thân\n if (event.type === 'message_reply') {\n targetID = event.messageReply.senderID;\n } else if (event.mentions && Object.keys(event.mentions).length > 0) {\n targetID = Object.keys(event.mentions)[0];\n }\n\n if (query === 'reset') {\n const threadInfo = await Threads.getData(threadID).then(data => data.threadInfo);\n if (!threadInfo.adminIDs.some(item => item.id == senderID))\n return api.sendMessage('❎️ Bạn không đủ quyền để reset dữ liệu!', threadID);\n fs.unlinkSync(filePath);\n return api.sendMessage('✅ Đã reset dữ liệu tương tác của nhóm!', threadID);\n }\n\n if (query === 'lọc' || query === 'loc') {\n if (!args[1] || isNaN(args[1]))\n return api.sendMessage('⚠️ Vui lòng nhập số tin nhắn.\\nVí dụ: check lọc 10', threadID);\n const threshold = parseInt(args[1]);\n if (threshold < 0 || threshold > 10000)\n return api.sendMessage('⚠️ Ngưỡng phải là số dương và hợp lý!', threadID);\n const threadInfo = await Threads.getData(threadID).then(data => data.threadInfo);\n if (!threadInfo.adminIDs.some(item => item.id == senderID))\n return api.sendMessage('❎️ Bạn không đủ quyền để lọc thành viên!', threadID);\n if (!threadInfo.adminIDs.some(item => item.id == api.getCurrentUserID()))\n return api.sendMessage('⚠️ Bot cần quyền quản trị viên!', threadID);\n const toRemove = data.total.filter(u => u.count <= threshold && u.id != api.getCurrentUserID());\n let removed = 0;\n for (const user of toRemove) {\n try {\n await api.removeUserFromGroup(user.id, threadID);\n removed++;\n } catch {}\n }\n return api.sendMessage(`✅ Đã lọc ${removed} thành viên có số tin nhắn dưới ${threshold}`, threadID);\n }\n\n if (query === 'autoloc' || query === 'auto-loc') {\n const threadInfo = await Threads.getData(threadID).then(data => data.threadInfo);\n if (!threadInfo.adminIDs.some(item => item.id == senderID))\n return api.sendMessage('❎ Bạn không đủ quyền để thiết lập auto lọc!', threadID);\n if (!args[1])\n return api.sendMessage('⚠️ Vui lòng nhập số tin nhắn hoặc \"off\" để tắt.\\nVí dụ: check autoloc 5 hoặc check autoloc off', threadID);\n if (args[1].toLowerCase() === 'off') {\n delete global.checkttConfig[threadID];\n fs.writeFileSync(configPath, JSON.stringify(global.checkttConfig, null, 4));\n return api.sendMessage('✅ Đã tắt auto lọc.', threadID);\n }\n if (isNaN(args[1]))\n return api.sendMessage('⚠️ Vui lòng nhập số tin nhắn hợp lệ.', threadID);\n const threshold = parseInt(args[1]);\n if (threshold < 0 || threshold > 10000)\n return api.sendMessage('⚠️ Ngưỡng phải là số dương và hợp lý!', threadID);\n global.checkttConfig[threadID] = threshold;\n fs.writeFileSync(configPath, JSON.stringify(global.checkttConfig, null, 4));\n return api.sendMessage(`✅ Đã bật auto lọc với ngưỡng ${threshold} tin nhắn.`, threadID);\n }\n\n if (['all', 'week', 'day'].includes(query)) {\n let list = [];\n if (query === 'all') list = data.total;\n if (query === 'week') list = data.week;\n if (query === 'day') list = data.day;\n\n const sorted = list.slice().sort((a, b) => b.count - a.count);\n const totalMessages = sorted.reduce((a, b) => a + b.count, 0);\n\n try {\n const threadInfo = await api.getThreadInfo(threadID);\n const msg = `[ Bảng Xếp Hạng Tin Nhắn - ${query.toUpperCase()} ]\\n\\n` +\n sorted.map((u, i) => `${i + 1}. ${global.data.userName.get(u.id) || \"Người dùng\"} - ${u.count.toLocaleString()} Tin.`).join('\\n') +\n `\\n\\n💬 Tổng Tin Nhắn: ${totalMessages.toLocaleString()}\\n` +\n `📌 Chỉ QTV được reply số để xóa thành viên (VD: 1 2 3).`;\n \n if (threadInfo.imageSrc) {\n const boxImage = await streamURL(threadInfo.imageSrc);\n return api.sendMessage({ \n body: `${msg}`, \n attachment: boxImage \n }, threadID, (err, info) => {\n if (err) return api.sendMessage(\"❌ Không thể gửi bảng xếp hạng kèm avatar nhóm\", threadID);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n tag: 'locmen',\n thread: threadID,\n author: senderID,\n storage: sorted\n });\n });\n } else {\n return api.sendMessage(msg, threadID, (err, info) => {\n if (err) return api.sendMessage(\"❌ Không thể gửi bảng xếp hạng\", threadID);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n tag: 'locmen',\n thread: threadID,\n author: senderID,\n storage: sorted\n });\n });\n }\n } catch (err) {\n console.error(`Lỗi khi lấy avatar nhóm hoặc gửi bảng xếp hạng:`, err);\n return api.sendMessage(\"❌ Không thể lấy avatar nhóm hoặc gửi bảng xếp hạng\", threadID);\n }\n }\n\n const threadInfo = await Threads.getData(threadID).then(data => data.threadInfo);\n const nameThread = threadInfo.threadName;\n const nameUID = global.data.userName.get(targetID) || \"Người dùng\";\n const UID = targetID;\n let permission;\n if (global.config.ADMINBOT.includes(UID.toString())) {\n permission = 'Admin Bot';\n } else if (global.config.NDH && global.config.NDH.includes(UID.toString())) {\n permission = 'Người Thuê Bot';\n } else if (threadInfo.adminIDs.some(i => i.id == UID)) {\n permission = 'Quản Trị Viên';\n } else {\n permission = 'Thành Viên';\n }\n\n const totalDay = data.day.reduce((a, b) => a + b.count, 0);\n const totalWeek = data.week.reduce((a, b) => a + b.count, 0);\n const totalAll = data.total.reduce((a, b) => a + b.count, 0);\n\n const userTotalDay = data.day.find(u => u.id == targetID)?.count || 0;\n const userTotalWeek = data.week.find(u => u.id == targetID)?.count || 0;\n const userTotal = data.total.find(u => u.id == targetID)?.count || 0;\n\n const sortedDay = data.day.slice().sort((a, b) => b.count - a.count);\n const sortedWeek = data.week.slice().sort((a, b) => b.count - a.count);\n const sortedTotal = data.total.slice().sort((a, b) => b.count - a.count);\n\n const userRankDay = sortedDay.findIndex(u => u.id == targetID);\n const userRankWeek = sortedWeek.findIndex(u => u.id == targetID);\n const userRank = sortedTotal.findIndex(u => u.id == targetID);\n\n let body = `[ ${nameThread} ]\\n\\n👤 Tên: ${nameUID}\\n🎖️ Chức Vụ: ${permission}\\n📝 Profile: https://www.facebook.com/profile.php?id=${UID}\\n───────────────\\n💬 Tin Nhắn Trong Ngày: ${userTotalDay.toString().replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\")}\\n📊 Tỉ Lệ Tương Tác Ngày ${totalDay > 0 ? ((userTotalDay / totalDay) * 100).toFixed(2) : 0}%\\n🥇 Hạng Trong Ngày: ${userRankDay + 1}\\n───────────────\\n💬 Tin Nhắn Trong Tuần: ${userTotalWeek.toString().replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\")}\\n📊 Tỉ Lệ Tương Tác Tuần ${totalWeek > 0 ? ((userTotalWeek / totalWeek) * 100).toFixed(2) : 0}%\\n🥈 Hạng Trong Tuần: ${userRankWeek + 1}\\n───────────────\\n💬 Tổng Tin Nhắn: ${userTotal.toString().replace(/\\B(?=(\\d{3})+(?!\\d))/g, \",\")}\\n📊 Tỉ Lệ Tương Tác Tổng ${totalAll > 0 ? ((userTotal / totalAll) * 100).toFixed(2) : 0}%\\n🏆 Hạng Tổng: ${userRank + 1}\\n\\n📌 Dùng:\\n- ${global.config.PREFIX}check day/week/all để xem BXH\\n- Thả ❤️ để xem tổng BXH\\n- ${global.config.PREFIX}check lọc/reset/autoloc [số] để quản lý nhóm.`;\n api.sendMessage({ body }, threadID, (err, info) => {\n if (err) return api.sendMessage(\"❌ Không thể gửi thông tin tương tác\", threadID);\n global.client.handleReaction.push({\n name: this.config.name,\n messageID: info.messageID,\n author: senderID\n });\n });\n};\n\nmodule.exports.handleReply = async function({ api, event, handleReply, Threads }) {\n try {\n const { senderID, threadID, messageID, body } = event;\n const dataThread = (await Threads.getData(threadID)).threadInfo;\n\n // Kiểm tra quyền QTV\n if (!dataThread.adminIDs.some(item => item.id == senderID))\n return api.sendMessage('❎ Chỉ quản trị viên mới được phép kick thành viên!', threadID, messageID);\n\n // Kiểm tra bot có quyền QTV\n if (!dataThread.adminIDs.some(item => item.id == api.getCurrentUserID()))\n return api.sendMessage('❎ Bot cần quyền quản trị viên để kick!', threadID, messageID);\n\n // Kiểm tra xem reply có chỉ chứa số hay không\n const isValidInput = body.trim().match(/^\\d+(\\s+\\d+)*$/);\n if (!isValidInput)\n return api.sendMessage('⚠️ Vui lòng chỉ reply số (VD: 1, 2 3) để kick thành viên!', threadID, messageID);\n\n const indexes = body.split(\" \").map(i => parseInt(i)).filter(i => !isNaN(i));\n if (indexes.length === 0)\n return api.sendMessage(`⚠️ Dữ liệu không hợp lệ`, threadID, messageID);\n\n let success = 0, fail = 0, msg = '', botBlocked = false;\n for (let index of indexes) {\n const user = handleReply.storage[index - 1];\n if (user) {\n if (user.id == api.getCurrentUserID()) {\n botBlocked = true;\n continue;\n }\n try {\n await api.removeUserFromGroup(user.id, threadID);\n success++;\n msg += `${index}. ${global.data.userName.get(user.id) || \"Người dùng\"}\\n`;\n } catch {\n fail++;\n }\n }\n }\n let resultMsg = `✅ Đã xóa ${success} thành viên thành công\\n❎ Thất bại ${fail}\\n\\n${msg}`;\n api.sendMessage(resultMsg, threadID, () => {\n if (botBlocked) {\n api.sendMessage(`Kick em làm gì vậy!`, threadID);\n }\n });\n } catch (err) {\n console.error(`Lỗi khi xử lý reply:`, err);\n return api.sendMessage(\"❌ Lỗi khi xóa thành viên\", threadID);\n }\n};\n\nmodule.exports.handleReaction = async function({ api, event, handleReaction }) {\n if (event.userID !== handleReaction.author || event.reaction !== '❤') return;\n\n api.unsendMessage(handleReaction.messageID);\n const filePath = path + event.threadID + '.json';\n if (!fs.existsSync(filePath)) return api.sendMessage(\"⚠️ Chưa có dữ liệu\", event.threadID);\n\n const data = JSON.parse(fs.readFileSync(filePath));\n const sorted = data.total.sort((a, b) => b.count - a.count);\n const totalMessages = sorted.reduce((a, b) => a + b.count, 0);\n const rank = sorted.findIndex(u => u.id == event.userID) + 1;\n\n try {\n const threadInfo = await api.getThreadInfo(event.threadID);\n const msg = `[ Tất Cả Tin Nhắn ]\\n\\n` +\n sorted.map((u, i) => `${i + 1}. ${global.data.userName.get(u.id) || \"Người dùng\"} - ${u.count.toLocaleString()} Tin.`).join('\\n') +\n `\\n\\n💬 Tổng Tin Nhắn: ${totalMessages.toLocaleString()}\\n` +\n `📊 Bạn hiện đang đứng ở hạng: ${rank}\\n\\n` +\n `📌 Chỉ QTV được reply số để xóa thành viên (VD: 1 2 3).\\n` +\n `${global.config.PREFIX}check lọc [số] để lọc thành viên.\\n` +\n `${global.config.PREFIX}check autoloc [số] để tự lọc.\\n` +\n `${global.config.PREFIX}check reset để reset dữ liệu.\\n` +\n `${global.config.PREFIX}kickndfb để xóa người dùng fb.`;\n\n if (threadInfo.imageSrc) {\n const boxImage = await streamURL(threadInfo.imageSrc);\n return api.sendMessage({ \n body: `${msg}`, \n attachment: boxImage \n }, event.threadID, (err, info) => {\n if (err) return api.sendMessage(\"❌ Không thể gửi bảng xếp hạng kèm avatar nhóm\", event.threadID);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n tag: 'locmen',\n thread: event.threadID,\n author: event.userID,\n storage: sorted\n });\n });\n } else {\n return api.sendMessage(msg, event.threadID, (err, info) => {\n if (err) return api.sendMessage(\"❌ Không thể gửi bảng xếp hạng\", event.threadID);\n global.client.handleReply.push({\n name: this.config.name,\n messageID: info.messageID,\n tag: 'locmen',\n thread: event.threadID,\n author: event.userID,\n storage: sorted\n });\n });\n }\n } catch (err) {\n console.error(`Lỗi khi lấy avatar nhóm hoặc gửi bảng xếp hạng:`, err);\n return api.sendMessage(\"❌ Không thể lấy avatar nhóm hoặc gửi bảng xếp hạng\", event.threadID);\n }\n};\n\nfunction sendRankMessage(api, threadID, msg, senderID, sorted, configName) {\n api.sendMessage(msg, threadID, (err, info) => {\n if (err) return api.sendMessage(\"❌ Không thể gửi bảng xếp hạng\", threadID);\n global.client.handleReply.push({\n name: configName,\n messageID: info.messageID,\n tag: 'locmen',\n thread: threadID,\n author: senderID,\n storage: sorted\n });\n });\n}",
|
5 |
+
"language": "javascript",
|
6 |
+
"createdAt": 1757036486672,
|
7 |
+
"updatedAt": 1757036486672
|
8 |
+
}
|