From 94b0df3b2325d2d93b6607b11614e74fc3378b6f Mon Sep 17 00:00:00 2001
From: ningmengchongshui <916415899@qq.com>
Date: Mon, 17 Jun 2024 11:01:50 +0800
Subject: [PATCH] fix: this.reply
---
apps/status.ts | 6 +++---
apps/update.ts | 32 ++++++++++++++++----------------
data.ts | 16 ++++++++++++++++
image.tsx | 32 +++++++++++---------------------
routes.tsx | 23 +++++------------------
tes.ts | 8 ++++++++
6 files changed, 59 insertions(+), 58 deletions(-)
create mode 100644 data.ts
create mode 100644 tes.ts
diff --git a/apps/status.ts b/apps/status.ts
index c772d76..cc43560 100644
--- a/apps/status.ts
+++ b/apps/status.ts
@@ -33,7 +33,7 @@ export class status extends Plugin {
if (this.e.isMaster) return this.statusMaster()
if (!this.e.isGroup) {
- this.reply('请群聊查看')
+ this.e.reply('请群聊查看')
return
}
@@ -62,14 +62,14 @@ export class status extends Plugin {
msg += '\n-------累计-------'
msg += await this.getCount()
- await this.reply(msg)
+ await this.e.reply(msg)
}
async statusGroup() {
let msg = '-------状态-------'
msg += await this.getCount(this.e.group_id)
- await this.reply(msg)
+ await this.e.reply(msg)
}
async getCount(groupId:number | string = '') {
diff --git a/apps/update.ts b/apps/update.ts
index 6462614..40353e7 100644
--- a/apps/update.ts
+++ b/apps/update.ts
@@ -36,7 +36,7 @@ export class update extends Plugin {
async update() {
if (!this.e.isMaster) return false
- if (uping) return this.reply('已有命令更新中..请勿重复操作')
+ if (uping) return this.e.reply('已有命令更新中..请勿重复操作')
if (/详细|详情|面板|面版/.test(this.e.msg)) return false
@@ -56,7 +56,7 @@ export class update extends Plugin {
/** 是否需要重启 */
if (this.isUp) {
- // await this.reply('即将执行重启,以应用更新')
+ // await this.e.reply('即将执行重启,以应用更新')
setTimeout(() => this.restart(), 2000)
}
}
@@ -97,7 +97,7 @@ export class update extends Plugin {
logger.mark(`${this.e.logFnc} 开始${type}:${this.typeName}`)
- await this.reply(`开始${type} ${this.typeName}`)
+ await this.e.reply(`开始${type} ${this.typeName}`)
uping = true
const ret = await this.execSync(cm)
uping = false
@@ -111,11 +111,11 @@ export class update extends Plugin {
const time = await this.getTime(plugin)
if (/Already up|已经是最新/g.test(ret.stdout)) {
- await this.reply(`${this.typeName} 已是最新\n最后更新时间:${time}`)
+ await this.e.reply(`${this.typeName} 已是最新\n最后更新时间:${time}`)
} else {
- await this.reply(`${this.typeName} 更新成功\n更新时间:${time}`)
+ await this.e.reply(`${this.typeName} 更新成功\n更新时间:${time}`)
this.isUp = true
- await this.reply(await this.getLog(plugin))
+ await this.e.reply(await this.getLog(plugin))
}
logger.mark(`${this.e.logFnc} 最后更新时间:${time}`)
@@ -153,23 +153,23 @@ export class update extends Plugin {
if (errMsg.includes('Timed out')) {
const remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '')
- return this.reply(`${msg}\n连接超时:${remote}`)
+ return this.e.reply(`${msg}\n连接超时:${remote}`)
}
if (/Failed to connect|unable to access/g.test(errMsg)) {
const remote = errMsg.match(/'(.+?)'/g)[0].replace(/'/g, '')
- return this.reply(`${msg}\n连接失败:${remote}`)
+ return this.e.reply(`${msg}\n连接失败:${remote}`)
}
if (errMsg.includes('be overwritten by merge')) {
- return this.reply(`${msg}\n存在冲突:\n${errMsg}\n请解决冲突后再更新,或者执行#强制更新,放弃本地修改`)
+ return this.e.reply(`${msg}\n存在冲突:\n${errMsg}\n请解决冲突后再更新,或者执行#强制更新,放弃本地修改`)
}
if (stdout.includes('CONFLICT')) {
- return this.reply(`${msg}\n存在冲突:\n${errMsg}${stdout}\n请解决冲突后再更新,或者执行#强制更新,放弃本地修改`)
+ return this.e.reply(`${msg}\n存在冲突:\n${errMsg}${stdout}\n请解决冲突后再更新,或者执行#强制更新,放弃本地修改`)
}
- return this.reply([errMsg, stdout])
+ return this.e.reply([errMsg, stdout])
}
async updateAll() {
@@ -182,7 +182,7 @@ export class update extends Plugin {
const testReg = /^#静默全部(强制)?更新$/.test(this.e.msg)
if (testReg) {
- await this.reply(`开始执行静默全部更新,请稍等...`)
+ await this.e.reply(`开始执行静默全部更新,请稍等...`)
}
await this.runUpdate()
@@ -200,7 +200,7 @@ export class update extends Plugin {
}
if (this.isUp) {
- // await this.reply('即将执行重启,以应用更新')
+ // await this.e.reply('即将执行重启,以应用更新')
setTimeout(() => this.restart(), 2000)
}
@@ -219,7 +219,7 @@ export class update extends Plugin {
logAll = await execSync(cm, { encoding: 'utf-8' })
} catch (error) {
logger.error(error.toString())
- await this.reply(error.toString())
+ await this.e.reply(error.toString())
}
if (!logAll) return false
@@ -246,7 +246,7 @@ export class update extends Plugin {
end = end.match(/remote\..*\.url=.+/g).join('\n\n').replace(/remote\..*\.url=/g, '').replace(/\/\/([^@]+)@/, '//')
} catch (error) {
logger.error(error.toString())
- await this.reply(error.toString())
+ await this.e.reply(error.toString())
}
return makeForwardMsg(this.e, [log, end], `${plugin || 'Miao-Yunzai'} 更新日志,共${line}条`)
@@ -255,6 +255,6 @@ export class update extends Plugin {
async updateLog() {
const plugin = this.getPlugin()
if (plugin === false) return false
- return this.reply(await this.getLog(plugin))
+ return this.e.reply(await this.getLog(plugin))
}
}
diff --git a/data.ts b/data.ts
new file mode 100644
index 0000000..ba03909
--- /dev/null
+++ b/data.ts
@@ -0,0 +1,16 @@
+import { createRequire } from 'module'
+const require = createRequire(import.meta.url)
+const image: string = require('./resources/example.png')
+export const movies = [
+ {
+ id: 0,
+ image: image,
+ title: 'Prognosis Negative',
+ starRating: '2.66',
+ rating: 'PG-13',
+ year: '2021',
+ genre: 'Comedy',
+ runtime: '1h 46m',
+ cast: 'Simon Pegg, Zach Galifianakis '
+ }
+]
\ No newline at end of file
diff --git a/image.tsx b/image.tsx
index 111d129..fcd9915 100644
--- a/image.tsx
+++ b/image.tsx
@@ -1,25 +1,13 @@
import React from 'react'
-import { Component, Puppeteer } from 'yunzai/utils'
-import Hello, { PropsType } from './views/hello.tsx'
-// 初始化 组件渲染对象
-const Com = new Component()
-export class Image {
- Pup: typeof Puppeteer.prototype = null
- /**
- * 初始化运行Puppeteer
- */
+import { Picture } from 'yunzai/utils'
+import { createDynamic } from 'yunzai/utils'
+import { PropsType } from './views/hello.tsx'
+const require = createDynamic(import.meta.url)
+export class Image extends Picture {
constructor() {
- // init
- this.Pup = new Puppeteer()
+ super()
// start
this.Pup.start()
-
- this.Pup.setLaunch({
- defaultViewport: {
- width: 1280,
- height: 800
- }
- })
}
/**
* 为指定用户生成html 生成指定数据下的html文件
@@ -27,14 +15,16 @@ export class Image {
* @param Props 组件参数
* @returns
*/
- createHello(uid: number, Props: PropsType) {
+ async createHello(uid: number, Props: PropsType) {
+ // 此作用域可被重复执行,此处将变成动态组件 - 这是危险的!
+ const Hello = (await require('./views/hello.tsx')).default;
// 生成 html 地址 或 html字符串
- const Address = Com.create(, {
+ const Address = this.Com.create(, {
// html/hello/uid.html
join_dir: 'hello',
html_name: `${uid}.html`,
})
- return this.Pup.render(Address,{
+ return this.Pup.render(Address, {
tab: ''
})
}
diff --git a/routes.tsx b/routes.tsx
index e565307..b611412 100644
--- a/routes.tsx
+++ b/routes.tsx
@@ -1,22 +1,9 @@
import React from "react"
-import Hello from "./views/hello.tsx"
-import Music from './views/music.tsx'
-import { createRequire } from 'module'
-const require = createRequire(import.meta.url)
-const image: string = require('./resources/example.png')
-const movies = [
- {
- id: 0,
- image: image,
- title: 'Prognosis Negative',
- starRating: '2.66',
- rating: 'PG-13',
- year: '2021',
- genre: 'Comedy',
- runtime: '1h 46m',
- cast: 'Simon Pegg, Zach Galifianakis '
- }
-]
+import { movies } from "./data"
+import { createDynamic } from 'yunzai/utils'
+const require = createDynamic(import.meta.url)
+const Hello = (await require('./views/hello.tsx')).default;
+const Music = (await require('./views/music.tsx')).default;
const Config = [
{
url: "/hello",
diff --git a/tes.ts b/tes.ts
new file mode 100644
index 0000000..7ae6a38
--- /dev/null
+++ b/tes.ts
@@ -0,0 +1,8 @@
+
+// const require = async (basePath: string) => {
+// const now = () => `?update=${Date.now()}`
+// return (await import(`${basePath}${now()}`))
+// }
+
+// const Hello = await require('./views/hello.tsx')
+// const Music = await require(`./views/music.tsx`)
\ No newline at end of file