File size: 4,941 Bytes
1c95eb2
 
 
7ad7620
1c95eb2
 
7ad7620
1c95eb2
1
2
3
4
5
6
7
8
{
  "id": "2ee02b97-499b-4c8f-84c8-f93c9098e25b",
  "title": "send.js",
  "content": "this.Seikoconfig = {\n  name: \"send\",\n  aliases: [\"sendnoti\"],\n  version: \"1.2.9\",\n  role: 3,\n  author: \"TruongMini\",\n  info: \"Gửi tin nhắn đến tất cả nhóm\",\n  Category: \"Admin\",\n  cd: 5,\n  images: [],\n};\nconst fs = require('fs');\nconst request = require('request');\nlet atmDir = [];\nconst getAtm = (atm, body) => new Promise(async (resolve) => {\n  let msg = {},\n    attachment = [];\n  msg.body = body;\n  for (let eachAtm of atm) {\n    await new Promise(async (resolve) => {\n      try {\n        let response = await request.get(eachAtm.url),\n          pathName = response.uri.pathname,\n          ext = pathName.substring(pathName.lastIndexOf(\".\") + 1),\n          path = __dirname + `/cache/${eachAtm.filename}.${ext}`\n        response\n          .pipe(fs.createWriteStream(path))\n          .on(\"close\", () => {\n            attachment.push(fs.createReadStream(path));\n            atmDir.push(path);\n            resolve();\n          })\n      } catch (e) {\n        console.log(e);\n      }\n    })\n  }\n  msg.attachment = attachment;\n  resolve(msg);\n})\n\nthis.onReply = async function ({\n  api,\n  event,\n  onReply,\n  Users,\n  Threads\n}) {\n  const {\n    threadID,\n    messageID,\n    senderID,\n    body\n  } = event;\n  let name = await Users.getNameUser(senderID);\n  switch (onReply.type) {\n    case \"sendnoti\": {\n      let text = `⩺ Phản hồi từ người dùng\\n\\n⩺ Nội dung: ${body}\\n\\n⩺ Từ: ${name}\\n⩺ Nhóm: ${(await Threads.getInfo(threadID)).threadName || \"Unknow\"}\\n⩺ Reply (phản hồi) tin nhắn để trả lời`;\n      if (event.attachments.length > 0) text = await getAtm(event.attachments, `⩺ Phản hồi từ người dùng\\n\\n⩺ Nội dung: ${body}\\n\\n⩺ Từ: ${name}\\n⩺ Nhóm ${(await Threads.getInfo(threadID)).threadName || \"Unknow\"}\\n⩺ Reply (phản hồi) tin nhắn để trả lời`);\n      api.sendMessage(text, onReply.threadID, (err, info) => {\n        atmDir.forEach(each => fs.unlinkSync(each))\n        atmDir = [];\n\n        global.Seiko.onReply.push({\n          name: this.Seikoconfig.name,\n          type: \"reply\",\n          messageID: info.messageID,\n          messID: messageID,\n          threadID\n        })\n      });\n      break;\n    }\n    case \"reply\": {\n      let text = `⩺ Phản hồi từ Admin\\n\\n⩺ Nội dung: ${body}\\n\\n⩺ Từ Admin: ${await Users.getNameUser(senderID)}\\n⩺ Reply (phản hồi) tin nhắn để trả lời`;\n      if (event.attachments.length > 0) text = await getAtm(event.attachments, `⩺ Phản hồi từ Admin\\n\\n⩺ Nội dung: ${body}\\n\\n⩺ Từ Admin: ${await Users.getNameUser(senderID)}\\n⩺ Reply (phản hồi) tin nhắn để trả lời`);\n      api.sendMessage(text, onReply.threadID, (err, info) => {\n        atmDir.forEach(each => fs.unlinkSync(each))\n        atmDir = [];\n        global.Seiko.onReply.push({\n          name: this.Seikoconfig.name,\n          type: \"sendnoti\",\n          messageID: info.messageID,\n          threadID\n        })\n      }, onReply.messID);\n      break;\n    }\n  }\n}\nthis.onRun = async function ({\n  api,\n  event,\n  args,\n  Users,\n  permssion\n}) {\n  if (permssion < 2) return;\n  const {\n    threadID,\n    messageID,\n    senderID,\n    messageReply\n  } = event;\n  if (!args[0]) return api.sendMessage(\"Please input message\", threadID);\n  let allThread = global.data.allThreadID || [];\n  let can = 0,\n    canNot = 0;\n  let text = `[ BOT ]\\n⩺ Thông báo từ Admin\\n\\n⩺ Nội dung: ${args.join(\" \")}\\n\\n⩺ Từ Admin: ${await Users.getNameUser(senderID)}\\n⩺ Reply (phản hồi) tin nhắn để gửi về admin`;\n  if (event.type == \"message_reply\") text = await getAtm(messageReply.attachments, `[  BOT ]\\n⩺ Thông báo từ Admin\\n\\n⩺ Nội dung: ${args.join(\" \")}\\n\\n⩺ Từ Admin: ${await Users.getNameUser(senderID)}\\n⩺ Reply (phản hồi) tin nhắn để gửi về admin`);\n  await new Promise(resolve => {\n    allThread.forEach((each) => {\n      try {\n        api.sendMessage(text, each, (err, info) => {\n          if (err) {\n            canNot++;\n          } else {\n            can++;\n            atmDir.forEach(each => fs.unlinkSync(each))\n            atmDir = [];\n            global.Seiko.onReply.push({\n              name: this.Seikoconfig.name,\n              type: \"sendnoti\",\n              messageID: info.messageID,\n              messID: messageID,\n              threadID\n            })\n            resolve();\n          }\n        })\n      } catch (e) {\n        console.log(e)\n      }\n    })\n  })\n  api.sendMessage(`✅ Đã gửi tin nhắn đến tất cả nhóm`, threadID);\n}",
  "language": "javascript",
  "createdAt": 1759292638821,
  "updatedAt": 1759292699556
}