feat: 优化导出
This commit is contained in:
		
							parent
							
								
									c8a60391c3
								
							
						
					
					
						commit
						60ac6e3479
					
				|  | @ -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() { |   async change_bot() { | ||||||
|     const log = await import('./log.js') |     const { setLogger } = await import('./log.js') | ||||||
|     log.default() |     setLogger && setLogger() | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | @ -249,4 +249,4 @@ class Cfg { | ||||||
|  *  |  *  | ||||||
|  * *** |  * *** | ||||||
|  */ |  */ | ||||||
| export default new Cfg() | export default new ConfigController() | ||||||
|  | @ -1,28 +1,10 @@ | ||||||
| 
 | 
 | ||||||
| import config from './config.js' | 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 | export const ConfigController = config | ||||||
| /** | /** | ||||||
|  * 创建qq配置 |  * 系统性配置 | ||||||
|  */ |  | ||||||
| export const createQQ = QQ |  | ||||||
| /** |  | ||||||
|  * 初始化redis全局对象 |  | ||||||
|  */ |  | ||||||
| export const redisInit = RedisInit |  | ||||||
| /** |  | ||||||
|  *  |  | ||||||
|  */ |  */ | ||||||
| export * from './system.js' | export * from './system.js' | ||||||
|  | @ -86,7 +86,7 @@ function createLog() { | ||||||
| /** | /** | ||||||
| * 设置日志样式 | * 设置日志样式 | ||||||
| */ | */ | ||||||
| export default function setLog() { | export function setLogger() { | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    *  |    *  | ||||||
|  |  | ||||||
|  | @ -1,16 +1,16 @@ | ||||||
| import fs, { promises } from "node:fs" | import fs, { promises } from "node:fs" | ||||||
| import yaml from "yaml" | import yaml from "yaml" | ||||||
| import { BOT_NAME, CONFIG_INIT_PATH } from "./system.js" | import { BOT_NAME, CONFIG_INIT_PATH } from "./system.js" | ||||||
| import createQQ from "./qq.js" | import { createQQ } from "./qq.js" | ||||||
| import setLog from "./log.js" | import { setLogger } from "./log.js" | ||||||
| import redisInit from "./redis.js" | import { redisInit } from "./redis.js" | ||||||
| import { checkRun } from "./check.js" | import { checkRun } from "./check.js" | ||||||
| import { join } from "node:path" | import { join } from "node:path" | ||||||
| 
 | 
 | ||||||
| /** | /** | ||||||
|  *  |  *  | ||||||
|  */ |  */ | ||||||
| export async function UpdateTitle() { | async function UpdateTitle() { | ||||||
|   /** |   /** | ||||||
|    * 添加一些多余的标题内容 |    * 添加一些多余的标题内容 | ||||||
|    */ |    */ | ||||||
|  | @ -92,7 +92,7 @@ export async function checkInit() { | ||||||
|   /** |   /** | ||||||
|    * 日志设置 |    * 日志设置 | ||||||
|    */ |    */ | ||||||
|   setLog() |   setLogger() | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    *  |    *  | ||||||
|  | @ -100,12 +100,12 @@ export async function checkInit() { | ||||||
|   logger.mark(`${BOT_NAME} 启动中...`) |   logger.mark(`${BOT_NAME} 启动中...`) | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    *  |    *  初始化客户端 | ||||||
|    */ |    */ | ||||||
|   await redisInit() |   await redisInit() | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    *  |    * 检查程序 | ||||||
|    */ |    */ | ||||||
|   await checkRun() |   await checkRun() | ||||||
| 
 | 
 | ||||||
|  | @ -10,7 +10,7 @@ import { sleep } from '../utils/common.js' | ||||||
|  * Git Bash 运行npm命令会无法选择列表 |  * Git Bash 运行npm命令会无法选择列表 | ||||||
|  * @returns  |  * @returns  | ||||||
|  */ |  */ | ||||||
| export default async function createQQ() { | export  async function createQQ() { | ||||||
|   /** 跳过登录ICQQ */ |   /** 跳过登录ICQQ */ | ||||||
|   if (cfg.bot.skip_login) return |   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}` |   const fileDef = `./${CONFIG_DEFAULT_PATH}` | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|   let qq = fs.readFileSync(`${fileDef}qq.yaml`, 'utf8') |   let qq = fs.readFileSync(`${fileDef}qq.yaml`, 'utf8') | ||||||
| 
 | 
 | ||||||
|   qq = qq.replace(/qq:/g, 'qq: ' + ret.QQ) |   qq = qq.replace(/qq:/g, 'qq: ' + ret.QQ) | ||||||
|  | @ -113,7 +105,6 @@ export default async function createQQ() { | ||||||
|   fs.writeFileSync(`${file}qq.yaml`, qq, 'utf8') |   fs.writeFileSync(`${file}qq.yaml`, qq, 'utf8') | ||||||
| 
 | 
 | ||||||
|   let bot = fs.readFileSync(`${fileDef}bot.yaml`, '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') |   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`) | ||||||
| 
 | 
 | ||||||
|   /** |   /** | ||||||
|    *  |    *  | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import { createClient } from "redis" | ||||||
|  * 初始化全局redis客户端 |  * 初始化全局redis客户端 | ||||||
|  * @returns  |  * @returns  | ||||||
|  */ |  */ | ||||||
| export default async function redisInit() { | export  async function redisInit() { | ||||||
|   const rc = cfg.redis |   const rc = cfg.redis | ||||||
|   const redisUn = rc.username || "" |   const redisUn = rc.username || "" | ||||||
|   let redisPw = rc.password ? `:${rc.password}` : "" |   let redisPw = rc.password ? `:${rc.password}` : "" | ||||||
|  |  | ||||||
|  | @ -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 | export const Bot = global.Bot as typeof Client.prototype | ||||||
|  |  | ||||||
|  | @ -53,19 +53,22 @@ type ChalkInstanceType = { | ||||||
| 
 | 
 | ||||||
| declare global { | declare global { | ||||||
|   /** |   /** | ||||||
|  |    * import { Redis } from 'yunzai/core' | ||||||
|    * @deprecated 不推荐使用,未来将废弃 |    * @deprecated 不推荐使用,未来将废弃 | ||||||
|    */ |    */ | ||||||
|   var redis: RedisClientType |   var redis: RedisClientType | ||||||
|   /** |   /** | ||||||
|    * |    * import { Bot } from 'yunzai/core' | ||||||
|    * @deprecated 不推荐使用,未来将废弃 |    * @deprecated 不推荐使用,未来将废弃 | ||||||
|    */ |    */ | ||||||
|   var Bot: typeof Client.prototype |   var Bot: typeof Client.prototype | ||||||
|   /** |   /** | ||||||
|  |    * import { segment } from 'yunzai/core' | ||||||
|    * @deprecated 不推荐使用,未来将废弃 |    * @deprecated 不推荐使用,未来将废弃 | ||||||
|    */ |    */ | ||||||
|   var segment: typeof se |   var segment: typeof se | ||||||
|   /** |   /** | ||||||
|  |    * import { plugin } from 'yunzai/core' | ||||||
|    * @deprecated 不推荐使用,未来将废弃 |    * @deprecated 不推荐使用,未来将废弃 | ||||||
|    */ |    */ | ||||||
|   var plugin: typeof p |   var plugin: typeof p | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue