2 Star 1 Fork 0

向日葵/向日葵脚本二代本体仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
qq.js 3.20 KB
一键复制 编辑 原始数据 按行查看 历史
向日葵 提交于 2024-10-06 09:26 . pilot again
import fs from 'fs/promises'; // 使用异步的fs
import inquirer from 'inquirer';
import cfg from './config.js';
import common from '../common/common.js';
import chalk from 'chalk';
import yaml from 'yaml';
export default async function createQQ() {
/** 跳过登录ICQQ */
if (cfg.bot.skip_login) return;
if (cfg.qq && !process.argv.includes('login')) {
return;
}
console.log(`欢迎使用${chalk.green('向日葵脚本喵崽登录界面')}\n请按提示输入完成QQ配置`);
const promptList = [
{
type: 'Input',
message: '请输入机器人QQ号(建议用小号):',
name: 'QQ',
validate(value) {
if (/^[1-9][0-9]{4,14}$/.test(value)) return true;
return '请输入正确的QQ号';
}
},
{
type: 'list',
message: '请选择登录端口:',
name: 'platform',
choices: ['aPad', 'iPad', 'Tim'],
filter: (val) => {
switch (val) {
case 'Tim': return 6;
case 'iPad': return 5;
case 'aPad': return 2;
default: return 2;
}
}
}
];
const xrk = await inquirer.prompt(promptList);
const accountFilePath = `/xrk/accounts/${xrk.QQ}.yaml`;
let ret = {};
if (await fs.stat(accountFilePath).then(() => true).catch(() => false)) {
try {
const fileContents = await fs.readFile(accountFilePath, 'utf8');
const data = yaml.parse(fileContents);
ret = {
QQ: data.account,
pwd: data.password,
masterqq: data.ownerqq,
signAPI: data.signapi
};
} catch (error) {
console.log(`读取 ${xrk.QQ} 文件失败,将手动输入密码和主人QQ`);
}
} else {
console.log(`未找到该QQ号文件,将手动输入密码和主人QQ。`);
const promptList2 = [
{
type: 'input',
message: '请输入登录密码(为空则扫码登录):',
name: 'pwd',
}
];
if (!process.argv.includes('login')) {
promptList2.push({
type: 'Input',
message: '请输入主人QQ号:',
name: 'masterQQ',
});
}
promptList2.push({
type: 'input',
message: '请输入签名API地址(可留空):',
name: 'signAPI'
});
ret = await inquirer.prompt(promptList2);
}
const file = './config/config/';
const fileDef = './config/default_config/';
let qq = await fs.readFile(`${fileDef}qq.yaml`, 'utf8');
qq = qq.replace(/qq:/g, 'qq: ' + ret.QQ);
qq = qq.replace(/pwd:/g, `pwd: '${ret.pwd}'`);
qq = qq.replace(/platform: [1-6]/g, 'platform: ' + Number(xrk.platform));
await fs.writeFile(`${file}qq.yaml`, qq, 'utf8');
let bot = await fs.readFile(`${fileDef}bot.yaml`, 'utf8');
if (ret.masterQQ) {
let other = await fs.readFile(`${fileDef}other.yaml`, 'utf8');
other = other.replace(/masterQQ:/g, `masterQQ:\n - ${ret.masterQQ}`);
await fs.writeFile(`${file}other.yaml`, other, 'utf8');
}
if (ret.signAPI) {
bot = bot.replace(/sign_api_addr:/g, `sign_api_addr: ${ret.signAPI}`);
}
await fs.writeFile(`${file}bot.yaml`, bot, 'utf8');
console.log(`\nQQ配置完成,正在登录\n后续修改账号可以运行命令:${chalk.green('node app login')}\n`);
await common.sleep(2000);
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xrk114514/sunbody.git
git@gitee.com:xrk114514/sunbody.git
xrk114514
sunbody
向日葵脚本二代本体仓库
master

搜索帮助