update: 开发浏览器对象&增加图片类&修改类型声明&增加动态模块取消参数
This commit is contained in:
parent
907a80c914
commit
faccb290c0
|
@ -465,7 +465,7 @@ class PluginsLoader {
|
||||||
* @param v
|
* @param v
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
filtEvent(e, v) {
|
filtEvent(e: EventType, v) {
|
||||||
if (!v.event) return false
|
if (!v.event) return false
|
||||||
const event = v.event.split('.')
|
const event = v.event.split('.')
|
||||||
const eventMap = this.eventMap[e.post_type] || []
|
const eventMap = this.eventMap[e.post_type] || []
|
||||||
|
@ -483,7 +483,7 @@ class PluginsLoader {
|
||||||
* @param v
|
* @param v
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
filtPermission(e, v) {
|
filtPermission(e: EventType, v) {
|
||||||
if (v.permission == 'all' || !v.permission) return true
|
if (v.permission == 'all' || !v.permission) return true
|
||||||
if (v.permission == 'master') {
|
if (v.permission == 'master') {
|
||||||
if (e.isMaster) {
|
if (e.isMaster) {
|
||||||
|
@ -531,7 +531,7 @@ class PluginsLoader {
|
||||||
* @param e.at 支持频道 tiny_id
|
* @param e.at 支持频道 tiny_id
|
||||||
* @param e.atBot 支持频道
|
* @param e.atBot 支持频道
|
||||||
*/
|
*/
|
||||||
dealMsg(e) {
|
dealMsg(e: EventType) {
|
||||||
if (e.message) {
|
if (e.message) {
|
||||||
for (let val of e.message) {
|
for (let val of e.message) {
|
||||||
switch (val.type) {
|
switch (val.type) {
|
||||||
|
@ -582,68 +582,85 @@ class PluginsLoader {
|
||||||
e.logText = ''
|
e.logText = ''
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 私聊
|
||||||
*/
|
*/
|
||||||
if (e.message_type === 'private' || e.notice_type === 'friend') {
|
if (e.message_type === 'private' || e.notice_type === 'friend') {
|
||||||
e.isPrivate = true
|
e.isPrivate = true
|
||||||
|
|
||||||
|
// 存在
|
||||||
if (e.sender) {
|
if (e.sender) {
|
||||||
|
// nickname
|
||||||
e.sender.card = e.sender.nickname
|
e.sender.card = e.sender.nickname
|
||||||
} else {
|
} else {
|
||||||
|
// 不存在
|
||||||
e.sender = {
|
e.sender = {
|
||||||
|
// nickname
|
||||||
card: e.friend?.nickname,
|
card: e.friend?.nickname,
|
||||||
|
// nickname
|
||||||
nickname: e.friend?.nickname
|
nickname: e.friend?.nickname
|
||||||
}
|
} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
e.logText = `[私聊][${e.sender.nickname}(${e.user_id})]`
|
e.logText = `[私聊][${e.sender.nickname}(${e.user_id})]`
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e?.user_id) {
|
|
||||||
e.user_avatar = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.user_id}`
|
|
||||||
e.user_name = e.sender.nickname
|
|
||||||
}
|
|
||||||
if (e?.group_id) {
|
|
||||||
e.group_avatar = `https://p.qlogo.cn/gh/${e.group_id}/${e.group_id}/640/`
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* 群聊
|
||||||
*/
|
*/
|
||||||
if (e.message_type === 'group' || e.notice_type === 'group') {
|
if (e.message_type === 'group' || e.notice_type === 'group') {
|
||||||
|
//
|
||||||
e.isGroup = true
|
e.isGroup = true
|
||||||
|
|
||||||
|
// 存在
|
||||||
if (e.sender) {
|
if (e.sender) {
|
||||||
e.sender.card = e.sender.card || e.sender.nickname
|
// nickname
|
||||||
|
e.sender.card = e.sender.card ?? e.sender.nickname
|
||||||
} else if (e.member) {
|
} else if (e.member) {
|
||||||
e.sender = {
|
e.sender = {
|
||||||
card: e.member.card || e.member.nickname
|
// nickname
|
||||||
}
|
card: e.member.card ?? e.member.nickname,
|
||||||
|
nickname: e.member.card ?? e.member.nickname
|
||||||
|
} as any
|
||||||
} else if (e.nickname) {
|
} else if (e.nickname) {
|
||||||
e.sender = {
|
e.sender = {
|
||||||
|
// nickname
|
||||||
card: e.nickname,
|
card: e.nickname,
|
||||||
|
// nickname
|
||||||
nickname: e.nickname
|
nickname: e.nickname
|
||||||
}
|
} as any
|
||||||
} else {
|
} else {
|
||||||
e.sender = {
|
e.sender = {
|
||||||
card: '',
|
card: e?.user_id ?? '',
|
||||||
nickname: ''
|
nickname: e?.user_id ?? ''
|
||||||
}
|
} as any
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!e.group_name) e.group_name = e.group?.name
|
if (!e.group_name) e.group_name = e.group?.name
|
||||||
|
|
||||||
e.logText = `[${e.group_name}(${e.sender.card})]`
|
e.logText = `[${e.group_name}(${e.sender.card})]`
|
||||||
|
|
||||||
|
//
|
||||||
} else if (e.detail_type === 'guild') {
|
} else if (e.detail_type === 'guild') {
|
||||||
|
//
|
||||||
e.isGuild = true
|
e.isGuild = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!e.user_id) {
|
||||||
|
e.user_id = e.sender?.user_id
|
||||||
|
}
|
||||||
|
if (e?.user_id) {
|
||||||
|
e.user_avatar = `https://q1.qlogo.cn/g?b=qq&s=0&nk=${e.user_id}`
|
||||||
|
}
|
||||||
|
if (e?.group_id) {
|
||||||
|
e.group_avatar = `https://p.qlogo.cn/gh/${e.group_id}/${e.group_id}/640/`
|
||||||
|
}
|
||||||
|
if (e.sender.nickname) {
|
||||||
|
e.user_name = e.sender.nickname
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (
|
if (e.user_id && cfg.masterQQ.includes(String(e.user_id))) {
|
||||||
e.user_id &&
|
|
||||||
cfg.masterQQ.includes(String(e.user_id) || String(e.user_id))
|
|
||||||
) {
|
|
||||||
e.isMaster = true
|
e.isMaster = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +668,7 @@ class PluginsLoader {
|
||||||
* 只关注主动at msg处理
|
* 只关注主动at msg处理
|
||||||
*/
|
*/
|
||||||
if (e.msg && e.isGroup) {
|
if (e.msg && e.isGroup) {
|
||||||
const groupCfg = cfg.getGroup(e.group_id)
|
const groupCfg = cfg.getGroup(String(e.group_id))
|
||||||
let alias = groupCfg.botAlias
|
let alias = groupCfg.botAlias
|
||||||
if (!Array.isArray(alias)) {
|
if (!Array.isArray(alias)) {
|
||||||
alias = [alias]
|
alias = [alias]
|
||||||
|
|
|
@ -1,10 +1,25 @@
|
||||||
import { type GroupMessage } from 'icqq'
|
import { type GroupMessage } from 'icqq'
|
||||||
import Runtime from './runtime'
|
import Runtime from './runtime'
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 消息体
|
||||||
|
* 应该是根据
|
||||||
|
* eleven 来进行赋值的
|
||||||
|
*
|
||||||
|
* tudo
|
||||||
|
* 错误的设计导致其混乱
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息事件体
|
* 消息事件体
|
||||||
*/
|
*/
|
||||||
export interface EventType extends GroupMessage {
|
export interface EventType extends GroupMessage {
|
||||||
|
/**
|
||||||
|
* 'group' | 'private'
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
|
message_type: any,
|
||||||
/**
|
/**
|
||||||
* 是否是机器人主人
|
* 是否是机器人主人
|
||||||
*/
|
*/
|
||||||
|
@ -45,6 +60,11 @@ export interface EventType extends GroupMessage {
|
||||||
* 用户消息
|
* 用户消息
|
||||||
*/
|
*/
|
||||||
msg: string
|
msg: string
|
||||||
|
/**
|
||||||
|
* 图片
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
|
img: string[]
|
||||||
/**
|
/**
|
||||||
* 消息发送
|
* 消息发送
|
||||||
* @param arg
|
* @param arg
|
||||||
|
@ -69,17 +89,47 @@ export interface EventType extends GroupMessage {
|
||||||
*/
|
*/
|
||||||
runtime: typeof Runtime.prototype
|
runtime: typeof Runtime.prototype
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
|
notice_type: any
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated 已废弃
|
* @deprecated 已废弃
|
||||||
*/
|
*/
|
||||||
group: {
|
group: {
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
is_owner: any;
|
is_owner: any;
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
recallMsg: (...arg: any[]) => any;
|
recallMsg: (...arg: any[]) => any;
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
getMemberMap: any;
|
getMemberMap: any;
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
quit: any;
|
quit: any;
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
mute_left: any
|
mute_left: any
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
pickMember: any
|
pickMember: any
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
sendMsg: any
|
sendMsg: any
|
||||||
|
/**
|
||||||
|
* @deprecated 已废弃
|
||||||
|
*/
|
||||||
|
name: any
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
* @deprecated 已废弃
|
* @deprecated 已废弃
|
||||||
|
|
|
@ -4,6 +4,7 @@ export * from './types.js'
|
||||||
export * from './common.js'
|
export * from './common.js'
|
||||||
export * from './component.js'
|
export * from './component.js'
|
||||||
export * from './module.js'
|
export * from './module.js'
|
||||||
|
export * from './picture.js'
|
||||||
/**
|
/**
|
||||||
* 旧版本兼容性方法
|
* 旧版本兼容性方法
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -19,9 +19,16 @@ export function require(path: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = () => `?update=${Date.now()}`
|
/**
|
||||||
|
* 获取时间请求
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
const now = () => `?t=${Date.now()}`
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param basePath import.meta.url
|
||||||
|
* @param T 默认开启动态,可自定设置系统量关闭
|
||||||
|
* @returns
|
||||||
* ***********
|
* ***********
|
||||||
* 创建动态模块
|
* 创建动态模块
|
||||||
* ***********
|
* ***********
|
||||||
|
@ -32,9 +39,14 @@ const now = () => `?update=${Date.now()}`
|
||||||
* 请确保你的模块是可预测
|
* 请确保你的模块是可预测
|
||||||
* ***********
|
* ***********
|
||||||
* 请确保当前模块是可被执行的
|
* 请确保当前模块是可被执行的
|
||||||
* @param basePath
|
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
export const createDynamic = (basePath: string) => {
|
export const createDynamic = (basePath: string, T = true) => {
|
||||||
return (path: string) => import(new URL(`${path}${now()}`, basePath).href)
|
/**
|
||||||
|
* 与import作用相同
|
||||||
|
* @param path 相对路径
|
||||||
|
* @param TT 默认开启动态,可自定设置系统量关闭
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
return (path: string, TT = true) =>
|
||||||
|
import(new URL(`${path}${TT && T ? now() : ''}`, basePath).href)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
import { Component } from './component'
|
||||||
|
import { Puppeteer } from './puppeteer'
|
||||||
|
export class Picture {
|
||||||
|
Pup: typeof Puppeteer.prototype = null
|
||||||
|
Com: typeof Component.prototype = null
|
||||||
|
constructor() {
|
||||||
|
this.Com = new Component()
|
||||||
|
this.Pup = new Puppeteer()
|
||||||
|
}
|
||||||
|
}
|
|
@ -32,13 +32,14 @@ export class Puppeteer {
|
||||||
#pic = 0
|
#pic = 0
|
||||||
// 重启次数控制
|
// 重启次数控制
|
||||||
#restart = 200
|
#restart = 200
|
||||||
// 应用缓存
|
|
||||||
#browser: Browser | null = null
|
|
||||||
// 状态
|
// 状态
|
||||||
#isBrowser = false
|
#isBrowser = false
|
||||||
// 配置
|
// 配置
|
||||||
#launch: PuppeteerLaunchOptions = PuppeteerLunchConfig.all()
|
#launch: PuppeteerLaunchOptions = PuppeteerLunchConfig.all()
|
||||||
|
|
||||||
|
// 应用缓存
|
||||||
|
browser: Browser | null = null
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置
|
* 设置
|
||||||
* @param val
|
* @param val
|
||||||
|
@ -62,7 +63,7 @@ export class Puppeteer {
|
||||||
*/
|
*/
|
||||||
async start() {
|
async start() {
|
||||||
try {
|
try {
|
||||||
this.#browser = await puppeteer.launch(this.#launch)
|
this.browser = await puppeteer.launch(this.#launch)
|
||||||
this.#isBrowser = true
|
this.#isBrowser = true
|
||||||
console.info('[puppeteer] open success')
|
console.info('[puppeteer] open success')
|
||||||
return true
|
return true
|
||||||
|
@ -97,7 +98,7 @@ export class Puppeteer {
|
||||||
this.#pic = 0
|
this.#pic = 0
|
||||||
console.info('[puppeteer] close')
|
console.info('[puppeteer] close')
|
||||||
this.#isBrowser = false
|
this.#isBrowser = false
|
||||||
this.#browser?.close().catch(err => {
|
this.browser?.close().catch(err => {
|
||||||
console.error('[puppeteer] close', err)
|
console.error('[puppeteer] close', err)
|
||||||
})
|
})
|
||||||
console.info('[puppeteer] reopen')
|
console.info('[puppeteer] reopen')
|
||||||
|
@ -119,7 +120,7 @@ export class Puppeteer {
|
||||||
async render(htmlPath: string, Options?: ScreenshotFileOptions) {
|
async render(htmlPath: string, Options?: ScreenshotFileOptions) {
|
||||||
if (!(await this.isStart())) return false
|
if (!(await this.isStart())) return false
|
||||||
try {
|
try {
|
||||||
const page = await this.#browser?.newPage().catch(err => {
|
const page = await this.browser?.newPage().catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
})
|
})
|
||||||
if (!page) return false
|
if (!page) return false
|
||||||
|
|
|
@ -5,47 +5,9 @@ declare module '*.module.css' {
|
||||||
const classes: CSSModuleClasses
|
const classes: CSSModuleClasses
|
||||||
export default classes
|
export default classes
|
||||||
}
|
}
|
||||||
declare module '*.module.scss' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
declare module '*.module.sass' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
declare module '*.module.less' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
declare module '*.module.styl' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
declare module '*.module.stylus' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
declare module '*.module.pcss' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
declare module '*.module.sss' {
|
|
||||||
const classes: CSSModuleClasses
|
|
||||||
export default classes
|
|
||||||
}
|
|
||||||
|
|
||||||
// CSS
|
// CSS
|
||||||
declare module '*.css' {}
|
declare module '*.css' {}
|
||||||
declare module '*.scss' {}
|
|
||||||
declare module '*.sass' {}
|
|
||||||
declare module '*.less' {}
|
|
||||||
declare module '*.styl' {}
|
|
||||||
declare module '*.stylus' {}
|
|
||||||
declare module '*.pcss' {}
|
|
||||||
declare module '*.sss' {}
|
|
||||||
|
|
||||||
// Built-in asset types
|
|
||||||
// see `src/node/constants.ts`
|
|
||||||
|
|
||||||
// images
|
// images
|
||||||
declare module '*.apng' {
|
declare module '*.apng' {
|
||||||
|
@ -164,79 +126,3 @@ declare module '*.otf' {
|
||||||
const src: string
|
const src: string
|
||||||
export default src
|
export default src
|
||||||
}
|
}
|
||||||
|
|
||||||
// other
|
|
||||||
declare module '*.webmanifest' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
declare module '*.pdf' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
declare module '*.txt' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
|
|
||||||
// wasm?init
|
|
||||||
declare module '*.wasm?init' {
|
|
||||||
const initWasm: (
|
|
||||||
options?: WebAssembly.Imports
|
|
||||||
) => Promise<WebAssembly.Instance>
|
|
||||||
export default initWasm
|
|
||||||
}
|
|
||||||
|
|
||||||
// web worker
|
|
||||||
declare module '*?worker' {
|
|
||||||
const workerConstructor: {
|
|
||||||
new (options?: { name?: string }): Worker
|
|
||||||
}
|
|
||||||
export default workerConstructor
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?worker&inline' {
|
|
||||||
const workerConstructor: {
|
|
||||||
new (options?: { name?: string }): Worker
|
|
||||||
}
|
|
||||||
export default workerConstructor
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?worker&url' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?sharedworker' {
|
|
||||||
const sharedWorkerConstructor: {
|
|
||||||
new (options?: { name?: string }): SharedWorker
|
|
||||||
}
|
|
||||||
export default sharedWorkerConstructor
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?sharedworker&inline' {
|
|
||||||
const sharedWorkerConstructor: {
|
|
||||||
new (options?: { name?: string }): SharedWorker
|
|
||||||
}
|
|
||||||
export default sharedWorkerConstructor
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?sharedworker&url' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?raw' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?url' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*?inline' {
|
|
||||||
const src: string
|
|
||||||
export default src
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue