修复传参错误 (#16)

This commit is contained in:
2y8e9h22 2023-03-11 09:35:53 +08:00 committed by GitHub
parent 74f5d7a861
commit f3d6950b51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 29 additions and 58 deletions

View File

@ -2,8 +2,9 @@
host: 127.0.0.1
# redis端口
port: 6379
# redis用户名可以为空
username:
# redis密码没有密码可以为空
password:
# redis数据库
db: 0

View File

@ -5,8 +5,8 @@ import cfg from './config/config.js'
export default class Yunzai extends Client {
// eslint-disable-next-line no-useless-constructor
constructor (uin, conf) {
super(uin, conf)
constructor (conf) {
super(conf)
}
/** 登录机器人 */

View File

@ -42,7 +42,7 @@ class Cfg {
bot = { ...defbot, ...bot }
bot.platform = this.getConfig('qq').platform
/** 设置data目录防止pm2运行时目录不对 */
bot.data_dir = process.cwd() + '/data'
bot.data_dir = process.cwd() + '/data/icqq/' + this.qq || ''
if (!bot.ffmpeg_path) delete bot.ffmpeg_path
if (!bot.ffprobe_path) delete bot.ffprobe_path
@ -54,6 +54,10 @@ class Cfg {
return this.getConfig('other')
}
get redis () {
return this.getConfig('redis')
}
/** 主人qq */
get masterQQ () {
let masterQQ = this.getConfig('other').masterQQ || []
@ -144,7 +148,7 @@ class Cfg {
change_qq () {
if (process.argv.includes('login') || !this.qq) return
logger.info('修改qq或密码,请手动重启')
logger.info('修改机器人QQ或密码,请手动重启')
}
async change_bot () {

View File

@ -2,36 +2,9 @@ import createQQ from './qq.js'
import setLog from './log.js'
import redisInit from './redis.js'
import { checkRun } from './check.js'
import fs from 'fs'
import fs from 'node:fs'
import yaml from 'yaml'
let path = './config/config/qq.yaml'
// 异步函数来读取 yaml 文件
/*
async function getQQ () {
function getQQPromise () {
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
try {
const file = await fs.promises.readFile(path, 'utf8')
const config = yaml.parse(file)
resolve(config)
} catch (err) {
console.error(err)
reject(err)
}
})
}
return getQQPromise().then((config) => {
return config
}).catch((err) => {
console.log(err)
})
}
*/
// 添加一些多余的标题内容
let title = 'Miao-Yunzai'
let qq = await fs.promises.readFile('./config/config/qq.yaml', 'UTF-8').then(yaml.parse).catch(() => null)
@ -57,7 +30,6 @@ if (qq) {
/** 设置标题 */
process.title = title
// process.title = `Miao-Yunzai ${(await getQQ()).qq === null ? '首次启动' : (await getQQ()).qq} ${(await getQQ()).platform === 1 ? '安卓手机' : (await getQQ()).platform === 2 ? 'aPad' : (await getQQ()).platform === 3 ? '安卓手表' : (await getQQ()).platform === 4 ? 'MacOS' : (await getQQ()).platform === 5 ? 'iPad' : 'Null'}`
/** 设置时区 */
process.env.TZ = 'Asia/Shanghai'
@ -85,7 +57,7 @@ await checkInit()
async function checkInit () {
/** 检查node_modules */
if (!fs.existsSync('./node_modules') || !fs.existsSync('./node_modules/icqq')) {
console.log('请先运行命令pnpm install 安装依赖')
console.log('请先运行命令pnpm install -P 安装依赖')
process.exit()
}

View File

@ -1,31 +1,26 @@
import YAML from 'yaml'
import fs from 'fs'
import cfg from './config.js'
import common from '../common/common.js'
import { createClient } from 'redis'
import { createRequire } from 'module'
const require = createRequire(import.meta.url)
const { exec } = require('child_process')
import { exec } from 'node:child_process'
/**
* 初始化全局redis客户端
*/
export default async function redisInit () {
logger.mark('正在连接 Redis...')
const file = './config/config/redis.yaml'
const cfg = YAML.parse(fs.readFileSync(file, 'utf8'))
let redisUrl = ''
if (cfg.password) {
redisUrl = `redis://:${cfg.password}@${cfg.host}:${cfg.port}`
} else {
redisUrl = `redis://${cfg.host}:${cfg.port}`
}
const rc = cfg.redis
let redisUn = rc.username || ''
let redisPw = rc.password ? `:${rc.password}` : ''
if (rc.username || rc.password) redisPw += '@'
let redisUrl = `redis://${redisUn}${redisPw}${rc.host}:${rc.port}/${rc.db}`
// 初始化reids
let client = createClient({ url: redisUrl })
try {
logger.mark(`正在连接 Redis...`)
logger.mark(redisUrl)
await client.connect()
} catch (error) {
let err = error.toString()
@ -73,7 +68,6 @@ export default async function redisInit () {
process.exit()
})
client.select(cfg.db)
/** 全局变量 redis */
global.redis = client
@ -101,7 +95,7 @@ async function aarch64 () {
/** 尝试自动启动redis */
async function startRedis (cmd, client, redisUrl) {
logger.mark('正在尝试启动 Redis...')
logger.mark('正在启动 Redis...')
await execSync(cmd)
await common.sleep(500)
try {

View File

@ -105,7 +105,7 @@ class PluginsLoader {
packageErr.forEach(v => {
let pack = v.error.stack.match(/'(.+?)'/g)[0].replace(/'/g, '')
logger.mark(`${v.File.name} 缺少依赖:${logger.red(pack)}`)
logger.mark(`新增插件后请执行安装命令:${logger.red('pnpm install')} 安装依赖`)
logger.mark(`新增插件后请执行安装命令:${logger.red('pnpm install -P')} 安装依赖`)
logger.mark(`如安装后仍未解决可联系插件作者将 ${logger.red(pack)} 依赖添加至插件的package.json dependencies中或手工安装依赖`)
})
// logger.error('或者使用其他包管理工具安装依赖')

View File

@ -3,13 +3,14 @@
"version": "3.0.1",
"author": "Yoimiya-Kokomi, Le-niao",
"description": "QQ group Bot",
"main": "app.js",
"type": "module",
"scripts": {
"app": "node app.js",
"dev": "node app.js dev",
"app": "node .",
"dev": "node . dev",
"login": "node . login",
"web": "node ./lib/tools/web.js",
"test": "node ./lib/tools/test.js",
"login": "node app.js login",
"start": "pm2 start ./config/pm2/pm2.json",
"stop": "pm2 stop ./config/pm2/pm2.json",
"restart": "pm2 restart ./config/pm2/pm2.json",
@ -31,7 +32,6 @@
"node-schedule": "^2.1.1",
"node-xlsx": "^0.21.0",
"oicq": "^2.3.1",
"patch-package": "^6.5.1",
"pm2": "^5.2.2",
"puppeteer": "^19.7.3",
"redis": "^4.6.5",