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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -3,65 +3,62 @@ import { createRequire } from 'module'
import { existsSync } from 'fs'
import pm2 from 'pm2'
const require = createRequire(import.meta.url)
/**
*
*
* @returns
*/
export function checkRun() {
function inquiryProcess() {
return new Promise((resolve, reject) => {
if (process.argv[1].includes('pm2')) {
resolve(true)
// 开始询问是否有正在运行的同实例进程
const dir = join(process.cwd(), 'pm2.config.cjs')
if (!existsSync(dir)) {
// 不存在配置,错误
reject(false)
}
if (process.argv[1].includes('test')) {
resolve(true)
}
// 不是生产运行
if (process.env.NODE_ENV != 'production') {
const dir = join(process.cwd(), 'pm2.config.cjs')
if (!existsSync(dir)) {
reject(false)
const cfg = require(dir)
pm2.connect(err => {
if (err) {
reject(err)
return
}
const cfg = require('../../pm2.config.cjs')
pm2.connect(err => {
pm2.list((err, processList) => {
if (err) {
pm2.disconnect()
reject(err)
return
}
//
pm2.list((err, processList) => {
if (err) {
pm2.disconnect()
reject(err)
return
}
const app = processList.find(p => p.name === cfg.apps[0].name)
if (app && app.pm2_env.status === 'online') {
console.log('检测到后台正在运行')
// 关闭
pm2.stop(cfg.apps[0].name, err => {
if (err) {
reject(err)
} else {
console.log('已停止后台进程,防止重复运行')
}
pm2.disconnect()
resolve(true)
})
} else {
// 断开连接
const app = processList.find(p => p.name === cfg.apps[0].name)
if (app && app.pm2_env.status === 'online') {
console.log('检测到后台正在运行')
// 关闭
pm2.stop(cfg.apps[0].name, err => {
if (err) {
reject(err)
} else {
console.log('已停止后台进程,防止重复运行')
}
pm2.disconnect()
resolve(true)
}
})
})
} else {
// 断开连接
pm2.disconnect()
resolve(true)
}
})
} else {
resolve(true)
}
})
})
}
/**
*
*/
if (process.env.NODE_ENV != 'production') {
await inquiryProcess().catch(err => {
// 打印错误
console.error(err)
// 关闭进程
process.exit(2)
})
}
await checkRun().catch(err => {
// 打印错误
console.error(err)
// 关闭进程
process.exit(2)
})