feat: 增加必要类型提示
This commit is contained in:
parent
9e9ad5b55d
commit
bca3842ae6
|
@ -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]
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,9 +1,3 @@
|
||||||
/**
|
|
||||||
* ************
|
|
||||||
* 关于bot处理,属于core
|
|
||||||
* ************
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送私聊消息,仅给好友发送
|
* 发送私聊消息,仅给好友发送
|
||||||
* @param userId qq号
|
* @param userId qq号
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,65 +3,62 @@ 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)
|
const dir = join(process.cwd(), 'pm2.config.cjs')
|
||||||
|
if (!existsSync(dir)) {
|
||||||
|
// 不存在配置,错误
|
||||||
|
reject(false)
|
||||||
}
|
}
|
||||||
if (process.argv[1].includes('test')) {
|
const cfg = require(dir)
|
||||||
resolve(true)
|
pm2.connect(err => {
|
||||||
}
|
if (err) {
|
||||||
// 不是生产运行
|
reject(err)
|
||||||
if (process.env.NODE_ENV != 'production') {
|
return
|
||||||
const dir = join(process.cwd(), 'pm2.config.cjs')
|
|
||||||
if (!existsSync(dir)) {
|
|
||||||
reject(false)
|
|
||||||
}
|
}
|
||||||
const cfg = require('../../pm2.config.cjs')
|
pm2.list((err, processList) => {
|
||||||
pm2.connect(err => {
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
pm2.disconnect()
|
||||||
reject(err)
|
reject(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//
|
const app = processList.find(p => p.name === cfg.apps[0].name)
|
||||||
pm2.list((err, processList) => {
|
if (app && app.pm2_env.status === 'online') {
|
||||||
if (err) {
|
console.log('检测到后台正在运行')
|
||||||
pm2.disconnect()
|
// 关闭
|
||||||
reject(err)
|
pm2.stop(cfg.apps[0].name, err => {
|
||||||
return
|
if (err) {
|
||||||
}
|
reject(err)
|
||||||
const app = processList.find(p => p.name === cfg.apps[0].name)
|
} else {
|
||||||
if (app && app.pm2_env.status === 'online') {
|
console.log('已停止后台进程,防止重复运行')
|
||||||
console.log('检测到后台正在运行')
|
}
|
||||||
// 关闭
|
|
||||||
pm2.stop(cfg.apps[0].name, err => {
|
|
||||||
if (err) {
|
|
||||||
reject(err)
|
|
||||||
} else {
|
|
||||||
console.log('已停止后台进程,防止重复运行')
|
|
||||||
}
|
|
||||||
pm2.disconnect()
|
|
||||||
resolve(true)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
// 断开连接
|
|
||||||
pm2.disconnect()
|
pm2.disconnect()
|
||||||
resolve(true)
|
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)
|
|
||||||
})
|
|
||||||
|
|
Loading…
Reference in New Issue