feat: 优化导出

This commit is contained in:
ningmengchongshui 2024-06-12 09:35:17 +08:00
parent c8a60391c3
commit 60ac6e3479
8 changed files with 41 additions and 57 deletions

View File

@ -9,7 +9,7 @@ import { CONFIG_DEFAULT_PATH, CONFIG_INIT_PATH } from './system.js'
*
* ********
*/
class Cfg {
class ConfigController {
/**
*
@ -238,8 +238,8 @@ class Cfg {
*
*/
async change_bot() {
const log = await import('./log.js')
log.default()
const { setLogger } = await import('./log.js')
setLogger && setLogger()
}
}
@ -249,4 +249,4 @@ class Cfg {
*
* ***
*/
export default new Cfg()
export default new ConfigController()

View File

@ -1,28 +1,10 @@
import config from './config.js'
import RedisInit from './redis.js'
import QQ from './qq.js'
/**
*
*/
export { checkRun } from './check.js'
/**
*
*/
export { checkInit, UpdateTitle as checkUpdateTitle } from './init.js'
/**
*
*/
export const ConfigController = config
/**
* qq配置
*/
export const createQQ = QQ
/**
* redis全局对象
*/
export const redisInit = RedisInit
/**
*
*
*/
export * from './system.js'

View File

@ -86,7 +86,7 @@ function createLog() {
/**
*
*/
export default function setLog() {
export function setLogger() {
/**
*
@ -96,7 +96,7 @@ export default function setLog() {
/**
*
*/
if (!fs.existsSync(file)){
if (!fs.existsSync(file)) {
fs.mkdirSync(file, {
'recursive': true
})

View File

@ -1,16 +1,16 @@
import fs, { promises } from "node:fs"
import yaml from "yaml"
import { BOT_NAME, CONFIG_INIT_PATH } from "./system.js"
import createQQ from "./qq.js"
import setLog from "./log.js"
import redisInit from "./redis.js"
import { createQQ } from "./qq.js"
import { setLogger } from "./log.js"
import { redisInit } from "./redis.js"
import { checkRun } from "./check.js"
import { join } from "node:path"
/**
*
*/
export async function UpdateTitle() {
async function UpdateTitle() {
/**
*
*/
@ -25,31 +25,31 @@ export async function UpdateTitle() {
if (qq) {
title += `@${qq.qq || ""}`
switch (qq.platform) {
case 1:{
case 1: {
title += " 安卓手机"
break
}
case 2:{
case 2: {
title += " aPad"
break
}
case 3:{
case 3: {
title += " 安卓手表"
break
}
case 4:{
case 4: {
title += " MacOS"
break
}
case 5:{
case 5: {
title += " iPad"
break
}
case 6:{
case 6: {
title += " Tim"
break
}
default:{
default: {
break
}
}
@ -78,7 +78,7 @@ export async function checkInit() {
/**
* node_modules/icqq
*/
if(!fs.existsSync(join(process.cwd(), "./node_modules/icqq"))){
if (!fs.existsSync(join(process.cwd(), "./node_modules/icqq"))) {
console.log("未安装icqq。。。。")
console.log("请先运行命令pnpm install -P 安装依赖")
process.exit()
@ -92,7 +92,7 @@ export async function checkInit() {
/**
*
*/
setLog()
setLogger()
/**
*
@ -100,12 +100,12 @@ export async function checkInit() {
logger.mark(`${BOT_NAME} 启动中...`)
/**
*
*
*/
await redisInit()
/**
*
*
*/
await checkRun()

View File

@ -10,7 +10,7 @@ import { sleep } from '../utils/common.js'
* Git Bash npm命令会无法选择列表
* @returns
*/
export default async function createQQ() {
export async function createQQ() {
/** 跳过登录ICQQ */
if (cfg.bot.skip_login) return
@ -63,12 +63,6 @@ export default async function createQQ() {
}
}
}
// ,{
// type: 'Input',
// message: '代理服务器地址,无需代理服务器请直接按下Enter',
// name: 'proxyAddress',
// default: 'http://0.0.0.0:0'
// }
]
/**
@ -103,8 +97,6 @@ export default async function createQQ() {
const fileDef = `./${CONFIG_DEFAULT_PATH}`
let qq = fs.readFileSync(`${fileDef}qq.yaml`, 'utf8')
qq = qq.replace(/qq:/g, 'qq: ' + ret.QQ)
@ -113,7 +105,6 @@ export default async function createQQ() {
fs.writeFileSync(`${file}qq.yaml`, qq, 'utf8')
let bot = fs.readFileSync(`${fileDef}bot.yaml`, 'utf8')
// bot = bot.replace(/proxyAddress:/g, `proxyAddress: ${ret.proxyAddress}`)
/**
*
@ -133,7 +124,7 @@ export default async function createQQ() {
fs.writeFileSync(`${file}bot.yaml`, bot, 'utf8')
console.log(`\nQQ配置完成正在登录\n后续修改账号可以运行命令 ${chalk.green('node app login')}\n`)
console.log(`\nQQ配置完成正在登录\n后续修改账号可以运行命令 ${chalk.green('npm run login')}\n`)
/**
*

View File

@ -6,7 +6,7 @@ import { createClient } from "redis"
* redis客户端
* @returns
*/
export default async function redisInit() {
export async function redisInit() {
const rc = cfg.redis
const redisUn = rc.username || ""
let redisPw = rc.password ? `:${rc.password}` : ""

View File

@ -3,7 +3,7 @@
*
* **********
*/
import '../config/init.js'
import '../config/main.js'
/**
* **********
*
@ -71,4 +71,12 @@ export class Client extends IcqqClient {
}
}
/**
* Redis
*/
export const Redis = global.redis
/**
*
*/
export const Bot = global.Bot as typeof Client.prototype

5
src/global.d.ts vendored
View File

@ -53,19 +53,22 @@ type ChalkInstanceType = {
declare global {
/**
* import { Redis } from 'yunzai/core'
* @deprecated 使
*/
var redis: RedisClientType
/**
*
* import { Bot } from 'yunzai/core'
* @deprecated 使
*/
var Bot: typeof Client.prototype
/**
* import { segment } from 'yunzai/core'
* @deprecated 使
*/
var segment: typeof se
/**
* import { plugin } from 'yunzai/core'
* @deprecated 使
*/
var plugin: typeof p