import fs from 'node:fs';

if (!global.segment) {
  global.segment = (await import("oicq")).segment;
}

let ret = [];

logger.info(logger.yellow("- æ­£åœ¨è½½å…¥ AP-PLUGIN"));

const files = fs
  .readdirSync('./plugins/ap-plugin/apps')
  .filter((file) => file.endsWith('.js'));

files.forEach((file) => {
  ret.push(import(`./apps/${file}`))
})

ret = await Promise.allSettled(ret);

let apps = {};
for (let i in files) {
  let name = files[i].replace('.js', '');

  if (ret[i].status !== 'fulfilled') {
    logger.error(`è½½å…¥æ�’ä»¶é”™è¯¯ï¼š${logger.red(name)}`);
    logger.error(ret[i].reason);
    continue;
  }
  apps[name] = ret[i].value[Object.keys(ret[i].value)[0]];
}

logger.info(logger.green("- AP-PLUGIN è½½å…¥æˆ�åŠŸ"));
logger.info(logger.magenta(`- æ¬¢è¿�åŠ å…¥æ–°ç»„ç»‡ã€�è²“å¨˜æ¨‚åœ’ğŸ�¥ğŸ�³ï¸�â€�âš§ï¸�ã€‘ï¼ˆç¾¤å�· 707331865ï¼‰`));

export { apps };