this.config = {
  name: "hi",
  aliases: ["hi"],
  version: "1.2.9",
  role: 1,
  author: "DongDev",
  info: "Hi chào thành viên",
  Category: "Quản trị viên",
  guides: "[]",
  cd: 5,
  hasPrefix: true,
  images: [],
};
const fs = require("fs");
const path = require("path");
const moment = require("moment-timezone");
const KEY = [
  "hello", "hi", "hai", "chào", "hí", "híí", "lô", "hii", "helo", "hê nhô"
];

let filePath;
this.onLoad = () => {
  filePath = path.join(__dirname, "../../system/data/hi.json");
  if (!fs.existsSync(filePath)) {
    fs.writeFileSync(filePath, "{}");
  }
};
this.onEvent = async function ({ event, api, Users }) {
  let { threadID, messageID } = event;
  const jsonData = fs.readFileSync(filePath, "utf-8");
  const savedData = JSON.parse(jsonData);
  if (event.senderID === api.getCurrentUserID()) return;
  if (typeof savedData[threadID]?.hi === "undefined" || savedData[threadID].hi) {
    if (event.body && KEY.includes(event.body.toLowerCase())) {
      let hours = moment.tz('Asia/Ho_Chi_Minh').format('HHmm');
      let data2 = ["tốt lành", "vui vẻ"];
      let text = data2[Math.floor(Math.random() * data2.length)];
      let session = (hours > 0 && hours <= 400 ? "sáng tinh mơ" :
        hours > 400 && hours <= 700 ? "sáng sớm" :
        hours > 700 && hours <= 1000 ? "sáng" :
        hours > 1000 && hours <= 1200 ? "trưa" :
        hours > 1200 && hours <= 1700 ? "chiều" :
        hours > 1700 && hours <= 1800 ? "chiều tà" :
        hours > 1800 && hours <= 2100 ? "tối" :
        hours > 2100 && hours <= 2400 ? "tối muộn" :
        "lỗi");
      let name = await Users.getNameUser(event.senderID);
      let mentions = [{ tag: name, id: event.senderID }];
      let msg = {
        body: `Xin chào ${name}, chúc bạn một buổi ${session} ${text} ❤️`,
        mentions,
      };
      api.sendMessage(msg, threadID, messageID);
    }
  }
};
this.onRun = async ({ event, api }) => {
  let { threadID, messageID } = event;
  const jsonData = fs.readFileSync(filePath, "utf-8");
  const savedData = JSON.parse(jsonData);
  if (typeof savedData[threadID]?.hi === "undefined" || savedData[threadID].hi) {
    savedData[threadID] = { hi: false };
    fs.writeFileSync(filePath, JSON.stringify(savedData, null, 2));
    api.sendMessage(`☑️ Tắt hi thành công!`, threadID, messageID);
  } else {
    savedData[threadID] = { hi: true };
    fs.writeFileSync(filePath, JSON.stringify(savedData, null, 2));
    api.sendMessage(`☑️ Bật hi thành công!`, threadID, messageID);
  }
};