feat: 增加必要类型提示

This commit is contained in:
ningmengchongshui 2024-06-17 22:49:05 +08:00
parent 9e9ad5b55d
commit bca3842ae6
7 changed files with 59 additions and 100 deletions

View File

@ -110,7 +110,7 @@ class ConfigController {
* @param groupId * @param groupId
* @returns * @returns
*/ */
getGroup(groupId = '') { getGroup(groupId: number | string = '') {
const config = this.getConfig('group') const config = this.getConfig('group')
const defCfg = this.getdefSet('group') const defCfg = this.getdefSet('group')
if (config[groupId]) { if (config[groupId]) {
@ -162,7 +162,7 @@ class ConfigController {
* @param type -defSet-config * @param type -defSet-config
* @param name * @param name
*/ */
getYaml(type, name) { getYaml(type: string, name: string) {
const file = `config/${type}/${name}.yaml` const file = `config/${type}/${name}.yaml`
const key = `${type}.${name}` const key = `${type}.${name}`
if (this.config[key]) return this.config[key] if (this.config[key]) return this.config[key]

View File

@ -39,54 +39,26 @@ export class Client extends IcqqClient {
*/ */
static async run() { static async run() {
const bot = new Client(cfg.bot) const bot = new Client(cfg.bot)
/**
*
*/
await ListenerLoader.load(bot) await ListenerLoader.load(bot)
/**
*
*/
if (cfg.bot.skip_login) { if (cfg.bot.skip_login) {
return await this.skip_login(bot) return await this.skip_login(bot)
} }
/**
*
*/
await bot.login(cfg.qq, cfg.pwd) await bot.login(cfg.qq, cfg.pwd)
bot[bot.uin] = bot bot[bot.uin] = bot
/**
* bot
*/
global.Bot = bot global.Bot = bot
return bot return bot
} }
/** /**
* ICQQ * ICQQ
* @param bot * @param bot
* @returns * @returns
*/ */
static async skip_login(bot) { static async skip_login(bot) {
//
bot.uin = 88888 bot.uin = 88888
//
bot[bot.uin] = bot bot[bot.uin] = bot
/**
* bot
*/
global.Bot = bot global.Bot = bot
/**
*
*/
return bot return bot
} }
/** /**
* *
* @param bot * @param bot
@ -95,8 +67,6 @@ export class Client extends IcqqClient {
static async PluginsLoader() { static async PluginsLoader() {
await PluginsLoader.load() await PluginsLoader.load()
} }
//
} }
/** /**

View File

@ -1,9 +1,3 @@
/**
* ************
* bot处理core
* ************
*/
/** /**
* *
* @param userId qq号 * @param userId qq号

View File

@ -1,5 +1,5 @@
import { MessageCallBackType } from './types.js' import { MessageCallBackType } from './types.js'
import { plugin } from './index.js' import { Plugin } from './index.js'
import { EventMap } from 'icqq' import { EventMap } from 'icqq'
/** /**
@ -60,7 +60,7 @@ export class Messages {
*/ */
get ok() { get ok() {
const App = this const App = this
class Children extends plugin { class Children extends Plugin {
constructor() { constructor() {
super({ super({
...App.#init, ...App.#init,
@ -91,14 +91,14 @@ export class Events {
* *
*/ */
#data: { #data: {
[key: string]: typeof plugin [key: string]: typeof Plugin
} = {} } = {}
/** /**
* *
* @param val * @param val
*/ */
use(val: typeof plugin) { use(val: typeof Plugin) {
this.#count++ this.#count++
this.#data[this.#count] = val this.#data[this.#count] = val
} }

View File

@ -1,5 +1,5 @@
import lodash from 'lodash' import lodash from 'lodash'
import fs from 'node:fs' import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
import { import {
gsCfg, gsCfg,
mysApi as MysApi, mysApi as MysApi,
@ -265,16 +265,16 @@ export default class Runtime {
let currDir = `${process.cwd()}/temp` let currDir = `${process.cwd()}/temp`
for (let p of check.split('/')) { for (let p of check.split('/')) {
currDir = `${currDir}/${p}` currDir = `${currDir}/${p}`
if (!fs.existsSync(currDir)) { if (!existsSync(currDir)) {
fs.mkdirSync(currDir) mkdirSync(currDir)
} }
} }
return currDir return currDir
} }
mkdir(`html/${plugin_name}/${path}`) mkdir(`html/${plugin_name}/${path}`)
// 自动计算pluResPath // 自动计算pluResPath
let pluResPath = `../../../${lodash.repeat('../', paths.length)}plugins/${plugin_name}/resources/` const pluResPath = `../../../${lodash.repeat('../', paths.length)}plugins/${plugin_name}/resources/`
let miaoResPath = `../../../${lodash.repeat('../', paths.length)}plugins/miao-plugin/resources/` const miaoResPath = `../../../${lodash.repeat('../', paths.length)}plugins/miao-plugin/resources/`
const layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/' const layoutPath = process.cwd() + '/plugins/miao-plugin/resources/common/layout/'
// 渲染data // 渲染data
data = { data = {
@ -309,12 +309,12 @@ export default class Runtime {
if (process.argv.includes('dev')) { if (process.argv.includes('dev')) {
// debug下保存当前页面的渲染数据方便模板编写与调试 // debug下保存当前页面的渲染数据方便模板编写与调试
// 由于只用于调试开发者只关注自己当时开发的文件即可暂不考虑app及plugin的命名冲突 // 由于只用于调试开发者只关注自己当时开发的文件即可暂不考虑app及plugin的命名冲突
let saveDir = mkdir(`ViewData/${plugin_name}`) const saveDir = mkdir(`ViewData/${plugin_name}`)
let file = `${saveDir}/${data._htmlPath.split('/').join('_')}.json` const file = `${saveDir}/${data._htmlPath.split('/').join('_')}.json`
fs.writeFileSync(file, JSON.stringify(data)) writeFileSync(file, JSON.stringify(data))
} }
// 截图 // 截图
let base64 = await puppeteer.screenshot(`${plugin_name}/${path}`, data) const base64 = await puppeteer.screenshot(`${plugin_name}/${path}`, data)
if (cfg.retType === 'base64') { if (cfg.retType === 'base64') {
return base64 return base64
} }

View File

@ -44,8 +44,6 @@ async function redisInit() {
}) })
/** 全局变量 redis */ /** 全局变量 redis */
global.redis = client as any global.redis = client as any
//
logger.info('Redis 连接成功') logger.info('Redis 连接成功')
return client return client
} }

View File

@ -3,31 +3,25 @@ import { createRequire } from 'module'
import { existsSync } from 'fs' import { existsSync } from 'fs'
import pm2 from 'pm2' import pm2 from 'pm2'
const require = createRequire(import.meta.url) const require = createRequire(import.meta.url)
/** /**
* *
* @returns * @returns
*/ */
export function checkRun() { function inquiryProcess() {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (process.argv[1].includes('pm2')) { // 开始询问是否有正在运行的同实例进程
resolve(true)
}
if (process.argv[1].includes('test')) {
resolve(true)
}
// 不是生产运行
if (process.env.NODE_ENV != 'production') {
const dir = join(process.cwd(), 'pm2.config.cjs') const dir = join(process.cwd(), 'pm2.config.cjs')
if (!existsSync(dir)) { if (!existsSync(dir)) {
// 不存在配置,错误
reject(false) reject(false)
} }
const cfg = require('../../pm2.config.cjs') const cfg = require(dir)
pm2.connect(err => { pm2.connect(err => {
if (err) { if (err) {
reject(err) reject(err)
return return
} }
//
pm2.list((err, processList) => { pm2.list((err, processList) => {
if (err) { if (err) {
pm2.disconnect() pm2.disconnect()
@ -54,14 +48,17 @@ export function checkRun() {
} }
}) })
}) })
} else {
resolve(true)
}
}) })
} }
await checkRun().catch(err => {
/**
*
*/
if (process.env.NODE_ENV != 'production') {
await inquiryProcess().catch(err => {
// 打印错误 // 打印错误
console.error(err) console.error(err)
// 关闭进程 // 关闭进程
process.exit(2) process.exit(2)
}) })
}