Skip to content

🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.

1.3 KB
Raw Blame
/** 终端扫码登录微信 iLink:二维码打印到终端并保存为 PNG。用法:npm run weixin:login [botId] */
import path from "node:path";
import { loadConfig } from "../config.js";
import { Store } from "../store/db.js";
import { WeixinLogin } from "../channels/weixin/login.js";
import { t as tr } from "../i18n/index.js";

async function main(): Promise<void> {
  const config = loadConfig();
  const store = new Store(path.join(config.dataDir, "anymodel.db"));
  const botId = process.argv[2] || store.listBots()[0]?.id || "default";
  if (!store.getBot(botId)) store.createBot({ id: botId, name: tr("app.default_bot_name"), weixinEnabled: true });
  const login = new WeixinLogin({
    apiBaseUrl: config.weixin.apiBaseUrl,
    pngPath: path.join(config.dataDir, "weixin", `${botId}-login-qr.png`),
    printTerminal: true,
  });
  login.subscribe((s) => s.message && console.log(`[${s.state}] ${s.message}`));
  const res = await login.run();
  if (!res) process.exit(1);
  store.saveWeixinAccount({ botId, botToken: res.botToken, ilinkBotId: res.ilinkBotId, baseUrl: res.baseUrl, ownerUserId: res.userId });
  store.updateBot(botId, { weixinEnabled: true });
  store.close();
  console.log(tr("cli.weixinConnected"));
}

main().catch((e) => {
  console.error((e as Error).message);
  process.exit(1);
});