File size: 17,115 Bytes
09b7a35
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
{
  "id": "bf8eb0aa-1d59-4abb-82aa-155bf0207e4d",
  "title": "hh",
  "content": "const fs = require('fs');\nconst path = require('path');\nconst { createCanvas, loadImage, registerFont } = require('canvas');\n\nmodule.exports.config = {\n  name: \"menu\",\n  usePrefix: true,\n  version: \"6.0.0\",\n  hasPermssion: 0,\n  credits: \"Neon Team\",\n  description: \"Hiển thị danh sách lệnh hoặc thông tin chi tiết về lệnh\",\n  commandCategory: \"Tiện ích\",\n  usages: \"menu [tên lệnh | danh mục | all]\",\n  cooldowns: 5\n};\n\nconst createCyberImage = (textContent, type = 'menu') => {\n  const lines = Array.isArray(textContent) ? textContent : textContent.split('\\n').filter(line => line.trim());\n  const lineHeight = 32;\n  const padding = 40;\n  const headerHeight = 80;\n  \n  const canvas = createCanvas(1000, headerHeight + (lines.length * lineHeight) + (padding * 2));\n  const ctx = canvas.getContext('2d');\n\n  const gradient = ctx.createLinearGradient(0, 0, 0, canvas.height);\n  gradient.addColorStop(0, '#0a0a0a');\n  gradient.addColorStop(0.3, '#1a1a2e');\n  gradient.addColorStop(0.7, '#16213e');\n  gradient.addColorStop(1, '#0f0f23');\n  ctx.fillStyle = gradient;\n  ctx.fillRect(0, 0, canvas.width, canvas.height);\n\n  ctx.strokeStyle = '#00ffff';\n  ctx.lineWidth = 3;\n  ctx.setLineDash([10, 5]);\n  ctx.strokeRect(15, 15, canvas.width - 30, canvas.height - 30);\n  ctx.setLineDash([]);\n\n  ctx.fillStyle = '#00ffff';\n  ctx.shadowColor = '#00ffff';\n  ctx.shadowBlur = 20;\n  ctx.font = 'bold 28px Arial';\n  ctx.textAlign = 'center';\n  \n  let title = 'CYBER CORE SYSTEM';\n  if (type === 'command') title = 'COMMAND INFO';\n  else if (type === 'category') title = 'CATEGORY LIST';\n  \n  ctx.fillText(title, canvas.width / 2, 50);\n  ctx.shadowBlur = 0;\n\n  ctx.strokeStyle = '#00ffff';\n  ctx.lineWidth = 2;\n  ctx.beginPath();\n  ctx.moveTo(padding, headerHeight - 10);\n  ctx.lineTo(canvas.width - padding, headerHeight - 10);\n  ctx.stroke();\n\n  ctx.font = '20px monospace';\n  ctx.textAlign = 'left';\n  \n  lines.forEach((line, index) => {\n    const y = headerHeight + padding + (index * lineHeight);\n    \n    if (line.includes(':')) {\n      const parts = line.split(':');\n      ctx.fillStyle = '#00ffff';\n      ctx.fillText(parts[0] + ':', 50, y);\n      ctx.fillStyle = '#ffffff';\n      ctx.fillText(parts.slice(1).join(':'), 50 + ctx.measureText(parts[0] + ': ').width, y);\n    } else if (line.match(/^\\d+\\./)) {\n      ctx.fillStyle = '#ff6b6b';\n      const numPart = line.match(/^\\d+\\./)[0];\n      ctx.fillText(numPart, 50, y);\n      ctx.fillStyle = '#ffffff';\n      ctx.fillText(line.substring(numPart.length), 50 + ctx.measureText(numPart + ' ').width, y);\n    } else {\n      ctx.fillStyle = line.includes('─') || line.includes('=') ? '#00ffff' : '#ffffff';\n      ctx.fillText(line, 50, y);\n    }\n\n    if (index % 2 === 0) {\n      ctx.fillStyle = 'rgba(0, 255, 255, 0.1)';\n      ctx.fillRect(30, y - 20, canvas.width - 60, lineHeight - 2);\n    }\n  });\n\n  const cornerSize = 20;\n  ctx.strokeStyle = '#ff6b6b';\n  ctx.lineWidth = 3;\n  \n  [[30, 30], [canvas.width - 30, 30], [30, canvas.height - 30], [canvas.width - 30, canvas.height - 30]].forEach(([x, y]) => {\n    ctx.beginPath();\n    if (x < canvas.width / 2) {\n      ctx.moveTo(x, y + cornerSize);\n      ctx.lineTo(x, y);\n      ctx.lineTo(x + cornerSize, y);\n    } else {\n      ctx.moveTo(x - cornerSize, y);\n      ctx.lineTo(x, y);\n      ctx.lineTo(x, y + cornerSize);\n    }\n    if (y > canvas.height / 2) {\n      ctx.moveTo(x < canvas.width / 2 ? x : x - cornerSize, y);\n      ctx.lineTo(x, y);\n      ctx.lineTo(x, y - cornerSize);\n    }\n    ctx.stroke();\n  });\n\n  return canvas.toBuffer('image/png');\n};\n\nconst cleanupFiles = () => {\n  const tempDir = __dirname;\n  const tempFiles = fs.readdirSync(tempDir).filter(file => \n    file.endsWith('.png') && (\n      file.includes('menu_') || \n      file.includes('allCommands_') || \n      file.includes('categoryCommands_') || \n      file === 'menu.png'\n    )\n  );\n  \n  tempFiles.forEach(file => {\n    try {\n      fs.unlinkSync(path.join(tempDir, file));\n    } catch (err) {}\n  });\n};\n\nmodule.exports.run = async function({ api, event, args, Users }) {\n  const commandsPath = path.resolve(__dirname, '..', 'commands');\n  const senderID = event.senderID;\n  const userPermission = (await Users.getData(senderID)).data.permission || 0;\n\n  try {\n    const files = await fs.promises.readdir(commandsPath);\n    let commandFiles = files.filter(file => file.endsWith('.js'));\n\n    if (commandFiles.length === 0) {\n      return api.sendMessage(\"║ SYSTEM ERROR ║ Không có lệnh nào trong database\", event.threadID, event.messageID);\n    }\n\n    commandFiles = await Promise.all(commandFiles.map(async file => {\n      try {\n        const command = require(path.join(commandsPath, file));\n        const stats = await fs.promises.stat(path.join(commandsPath, file));\n        return {\n          name: file.replace('.js', ''),\n          config: command.config,\n          lastUpdated: stats.mtime\n        };\n      } catch {\n        return {\n          name: file.replace('.js', ''),\n          config: {\n            description: 'System Error - Unable to load',\n            credits: 'Unknown',\n            version: 'Error',\n            usages: 'Unavailable',\n            cooldowns: 0,\n            hasPermssion: 0,\n            commandCategory: 'Error'\n          },\n          lastUpdated: null\n        };\n      }\n    }));\n\n    commandFiles = commandFiles.filter(cmd => userPermission >= cmd.config.hasPermssion);\n\n    if (args.length === 0) {\n      let categorizedCommands = {};\n      commandFiles.forEach((cmd, idx) => {\n        const category = cmd.config.commandCategory || 'Unknown';\n        if (!categorizedCommands[category]) categorizedCommands[category] = [];\n        categorizedCommands[category].push({ ...cmd, index: idx + 1 });\n      });\n\n      let menuLines = [\n        \"═══════════════════════════════════════\",\n        \"         COMMAND CATEGORIES\",\n        \"═══════════════════════════════════════\",\n        \"\"\n      ];\n\n      Object.keys(categorizedCommands).forEach((category, idx) => {\n        menuLines.push(`${idx + 1}. ${category.toUpperCase()}: ${categorizedCommands[category].length} commands`);\n      });\n\n      menuLines.push(\"\");\n      menuLines.push(\"─────────────────────────────────────\");\n      menuLines.push(\"Reply with number or category name\");\n      menuLines.push(\"Type 'all' to view all commands\");\n      menuLines.push(\"─────────────────────────────────────\");\n\n      const buffer = createCyberImage(menuLines, 'menu');\n      const fileName = `menu_${Date.now()}.png`;\n      const filePath = path.resolve(__dirname, fileName);\n      fs.writeFileSync(filePath, buffer);\n\n      setTimeout(() => cleanupFiles(), 30000);\n\n      return api.sendMessage({ \n        body: \"║ CYBER CORE SYSTEM ║ Command Menu Loaded\", \n        attachment: fs.createReadStream(filePath) \n      }, event.threadID, (err, info) => {\n        if (err) return console.error(err);\n        global.client.handleReply.push({\n          name: this.config.name,\n          messageID: info.messageID,\n          author: senderID,\n          categorizedCommands: categorizedCommands\n        });\n      });\n\n    } else {\n      const input = args.join(\" \").toLowerCase();\n\n      if (input === 'all') {\n        let allLines = [\n          \"═══════════════════════════════════════\",\n          \"           ALL COMMANDS\",\n          \"═══════════════════════════════════════\",\n          \"\"\n        ];\n        \n        commandFiles.forEach((cmd, idx) => {\n          allLines.push(`${idx + 1}. ${cmd.name.toUpperCase()}: ${cmd.config.description || 'No description available'}`);\n        });\n\n        allLines.push(\"\");\n        allLines.push(\"─────────────────────────────────────\");\n        allLines.push(`Total Commands: ${commandFiles.length}`);\n        allLines.push(\"─────────────────────────────────────\");\n\n        const buffer = createCyberImage(allLines, 'category');\n        const fileName = `allCommands_${Date.now()}.png`;\n        const filePath = path.resolve(__dirname, fileName);\n        fs.writeFileSync(filePath, buffer);\n\n        setTimeout(() => cleanupFiles(), 30000);\n\n        return api.sendMessage({ \n          body: \"║ CYBER CORE ║ All Commands Database\", \n          attachment: fs.createReadStream(filePath) \n        }, event.threadID, (err, info) => {\n          if (err) return console.error(err);\n          global.client.handleReply.push({\n            name: this.config.name,\n            messageID: info.messageID,\n            author: senderID,\n            commandsList: commandFiles\n          });\n        });\n      }\n\n      const command = commandFiles.find(cmd => cmd.name.toLowerCase() === input);\n\n      if (command) {\n        let detailLines = [\n          \"═══════════════════════════════════════\",\n          `        ${command.name.toUpperCase()} INFO`,\n          \"═══════════════════════════════════════\",\n          \"\",\n          `Command Name: ${command.name}`,\n          `Description: ${command.config.description || 'No description'}`,\n          `Author: ${command.config.credits || 'Unknown'}`,\n          `Version: ${command.config.version || 'Unknown'}`,\n          `Usage: ${command.config.usages || 'No usage info'}`,\n          `Cooldown: ${command.config.cooldowns || '0'} seconds`,\n          `Permission: Level ${command.config.hasPermssion || 0}`,\n          `Last Updated: ${command.lastUpdated ? command.lastUpdated.toLocaleString() : 'Unknown'}`,\n          \"\",\n          \"─────────────────────────────────────\"\n        ];\n\n        const buffer = createCyberImage(detailLines, 'command');\n        const fileName = `${command.name}_${Date.now()}.png`;\n        const filePath = path.resolve(__dirname, fileName);\n        fs.writeFileSync(filePath, buffer);\n\n        setTimeout(() => cleanupFiles(), 30000);\n\n        return api.sendMessage({ \n          body: `║ CYBER CORE ║ Command: ${command.name}`, \n          attachment: fs.createReadStream(filePath) \n        }, event.threadID, event.messageID);\n      }\n\n      const categoryCommands = commandFiles.filter(cmd => \n        cmd.config.commandCategory && cmd.config.commandCategory.toLowerCase() === input\n      );\n\n      if (categoryCommands.length === 0) {\n        return api.sendMessage(\"║ SYSTEM ERROR ║ Command or category not found in database\", event.threadID, event.messageID);\n      }\n\n      let categoryLines = [\n        \"═══════════════════════════════════════\",\n        `      ${input.toUpperCase()} CATEGORY`,\n        \"═══════════════════════════════════════\",\n        \"\"\n      ];\n\n      categoryCommands.forEach((cmd, idx) => {\n        categoryLines.push(`${idx + 1}. ${cmd.name.toUpperCase()}: ${cmd.config.description || 'No description'}`);\n      });\n\n      categoryLines.push(\"\");\n      categoryLines.push(\"─────────────────────────────────────\");\n      categoryLines.push(`Total in category: ${categoryCommands.length}`);\n      categoryLines.push(\"─────────────────────────────────────\");\n\n      const buffer = createCyberImage(categoryLines, 'category');\n      const fileName = `categoryCommands_${input}_${Date.now()}.png`;\n      const filePath = path.resolve(__dirname, fileName);\n      fs.writeFileSync(filePath, buffer);\n\n      setTimeout(() => cleanupFiles(), 30000);\n\n      return api.sendMessage({ \n        body: `║ CYBER CORE ║ Category: ${input.toUpperCase()}`, \n        attachment: fs.createReadStream(filePath) \n      }, event.threadID, event.messageID);\n    }\n  } catch (err) {\n    console.error(err);\n    return api.sendMessage(\"║ CRITICAL ERROR ║ System malfunction detected\", event.threadID, event.messageID);\n  }\n};\n\nmodule.exports.handleReply = async function({ api, event, handleReply }) {\n  const { threadID, messageID, senderID, body } = event;\n\n  if (handleReply.author !== senderID) return;\n\n  const input = body.trim();\n  const index = parseInt(input);\n\n  let categoryName = input.toLowerCase();\n  let categoryCommands = null;\n\n  if (!isNaN(index)) {\n    if (handleReply.commandsList && index > 0 && index <= handleReply.commandsList.length) {\n      const command = handleReply.commandsList[index - 1];\n\n      let detailLines = [\n        \"═══════════════════════════════════════\",\n        `        ${command.name.toUpperCase()} INFO`,\n        \"═══════════════════════════════════════\",\n        \"\",\n        `Command Name: ${command.name}`,\n        `Description: ${command.config.description || 'No description'}`,\n        `Author: ${command.config.credits || 'Unknown'}`,\n        `Version: ${command.config.version || 'Unknown'}`,\n        `Usage: ${command.config.usages || 'No usage info'}`,\n        `Cooldown: ${command.config.cooldowns || '0'} seconds`,\n        `Permission: Level ${command.config.hasPermssion || 0}`,\n        `Last Updated: ${command.lastUpdated ? command.lastUpdated.toLocaleString() : 'Unknown'}`,\n        \"\",\n        \"─────────────────────────────────────\"\n      ];\n\n      const buffer = createCyberImage(detailLines, 'command');\n      const fileName = `${command.name}_${Date.now()}.png`;\n      const filePath = path.resolve(__dirname, fileName);\n      fs.writeFileSync(filePath, buffer);\n\n      setTimeout(() => cleanupFiles(), 30000);\n\n      return api.sendMessage({\n        body: `║ CYBER CORE ║ Command: ${command.name}`,\n        attachment: fs.createReadStream(filePath)\n      }, threadID, messageID);\n    } else if (index > 0 && index <= Object.keys(handleReply.categorizedCommands).length) {\n      categoryName = Object.keys(handleReply.categorizedCommands)[index - 1].toLowerCase();\n    }\n  }\n\n  for (const [key, value] of Object.entries(handleReply.categorizedCommands)) {\n    if (key.toLowerCase() === categoryName) {\n      categoryCommands = value;\n      break;\n    }\n  }\n\n  if (categoryCommands) {\n    let categoryLines = [\n      \"═══════════════════════════════════════\",\n      `      ${categoryName.toUpperCase()} CATEGORY`,\n      \"═══════════════════════════════════════\",\n      \"\"\n    ];\n\n    categoryCommands.forEach((cmd, idx) => {\n      categoryLines.push(`${idx + 1}. ${cmd.name.toUpperCase()}: ${cmd.config.description || 'No description'}`);\n    });\n\n    categoryLines.push(\"\");\n    categoryLines.push(\"─────────────────────────────────────\");\n    categoryLines.push(`Total in category: ${categoryCommands.length}`);\n    categoryLines.push(\"─────────────────────────────────────\");\n\n    const buffer = createCyberImage(categoryLines, 'category');\n    const fileName = `categoryCommands_${categoryName}_${Date.now()}.png`;\n    const filePath = path.resolve(__dirname, fileName);\n    fs.writeFileSync(filePath, buffer);\n\n    setTimeout(() => cleanupFiles(), 30000);\n\n    return api.sendMessage({\n      body: `║ CYBER CORE ║ Category: ${categoryName.toUpperCase()}`,\n      attachment: fs.createReadStream(filePath)\n    }, threadID, messageID);\n  }\n};",
  "language": "javascript",
  "createdAt": 1755709161352,
  "updatedAt": 1755709161352
}