细节优化

This commit is contained in:
🌌 2023-07-25 00:24:52 +08:00
parent 57f3741d78
commit 72d196a7d3
5 changed files with 56 additions and 125 deletions

View File

@ -53,7 +53,7 @@ function mkdirs (dirname) {
/** /**
* 制作转发消息 * 制作转发消息
* @param e icqq消息e * @param e 消息事件
* @param msg 消息数组 * @param msg 消息数组
* @param dec 转发描述 * @param dec 转发描述
*/ */

View File

@ -41,31 +41,29 @@ Bot.adapter.push(new class GSUIDCoreAdapter {
const msgs = [] const msgs = []
for (let i of msg) { for (let i of msg) {
if (typeof i != "object") if (typeof i != "object")
i = { type: "text", data: { text: i }} i = { type: "text", text: i }
else if (!i.data)
i = { type: i.type, data: { ...i, type: undefined }}
switch (i.type) { switch (i.type) {
case "text": case "text":
i.data = i.data.text i.data = i.text
break break
case "image": case "image":
i.data = i.data.file i.data = i.file
break break
case "record": case "record":
i = { type: "file", data: i.data.file } i = { type: "file", data: i.file }
break break
case "video": case "video":
i = { type: "file", data: i.data.file } i = { type: "file", data: i.file }
break break
case "file": case "file":
i.data = i.data.file i.data = i.file
break break
case "at": case "at":
i.data = i.data.qq i.data = i.qq
break break
case "reply": case "reply":
i.data = i.data.id i.data = i.id
break break
case "node": { case "node": {
const array = [] const array = []

View File

@ -1,4 +1,5 @@
import plugin from '../../lib/plugins/plugin.js' import plugin from '../../lib/plugins/plugin.js'
import common from '../../lib/common/common.js'
import fs from 'node:fs' import fs from 'node:fs'
import lodash from 'lodash' import lodash from 'lodash'
import moment from 'moment' import moment from 'moment'
@ -49,7 +50,7 @@ export class sendLog extends plugin {
return return
} }
let forwardMsg = await this.makeForwardMsg(`最近${log.length}${type}日志`, log) let forwardMsg = await common.makeForwardMsg(this.e, log, `最近${log.length}${type}日志`)
await this.reply(forwardMsg) await this.reply(forwardMsg)
} }
@ -78,22 +79,4 @@ export class sendLog extends plugin {
return tmp return tmp
} }
async makeForwardMsg (title, msg) {
let forwardMsg = [{ message: title }, { message: msg }]
/** 制作转发内容 */
if (this.e.group)
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
else
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
/** 处理描述 */
forwardMsg.data = forwardMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
return forwardMsg
}
} }

View File

@ -27,7 +27,7 @@ export class update extends plugin {
fnc: 'update' fnc: 'update'
}, },
{ {
reg: '^#全部更新$', reg: '^#全部(强制)?更新$',
fnc: 'updateAll', fnc: 'updateAll',
permission: 'master' permission: 'master'
} }
@ -257,32 +257,11 @@ export class update extends plugin {
let end = '' let end = ''
log = await this.makeForwardMsg(`${plugin || 'TRSS-Yunzai'}更新日志,共${line}`, log, end) log = await common.makeForwardMsg(this.e, [log, end], `${plugin || 'TRSS-Yunzai'}更新日志,共${line}`)
return log return log
} }
async makeForwardMsg (title, msg, end) {
let forwardMsg = [{ message: title }, { message: msg }]
if (end)
forwardMsg.push({ message: end })
/** 制作转发内容 */
if (this.e.group)
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
else
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
/** 处理描述 */
forwardMsg.data = forwardMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
return forwardMsg
}
async updateLog() { async updateLog() {
let log = await this.getLog() let log = await this.getLog()
await this.reply(log) await this.reply(log)

View File

@ -1,6 +1,6 @@
import cfg from '../../lib/config/config.js' import cfg from '../../lib/config/config.js'
import plugin from '../../lib/plugins/plugin.js' import plugin from '../../lib/plugins/plugin.js'
import common from '../../lib/common/common.js'
import fs from 'node:fs' import fs from 'node:fs'
import lodash from 'lodash' import lodash from 'lodash'
import { pipeline } from 'stream' import { pipeline } from 'stream'
@ -95,7 +95,6 @@ export class add extends plugin {
/** 获取群号 */ /** 获取群号 */
async getGroupId() { async getGroupId() {
/** 添加全局表情存入到机器人qq文件中 */ /** 添加全局表情存入到机器人qq文件中 */
if (this.isGlobal) { if (this.isGlobal) {
this.group_id = this.e.bot.uin; this.group_id = this.e.bot.uin;
@ -675,9 +674,8 @@ export class add extends plugin {
num++ num++
} }
let end = ''
if (type == 'list' && count > 100) { if (type == 'list' && count > 100) {
end = `更多内容请翻页查看\n如:#表情列表${Number(page) + 1}` msg.push(`更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`)
} }
let title = `表情列表,第${page}页,共${count}` let title = `表情列表,第${page}页,共${count}`
@ -685,38 +683,11 @@ export class add extends plugin {
title = `表情${search}${count}` title = `表情${search}${count}`
} }
let forwardMsg = await this.makeForwardMsg(title, msg, end) let forwardMsg = await common.makeForwardMsg(this.e, msg, title)
this.e.reply(forwardMsg) this.e.reply(forwardMsg)
} }
async makeForwardMsg (title, msg, end = '') {
let forwardMsg = [{ message: title }]
let msgArr = lodash.chunk(msg, 40)
msgArr.forEach(v => {
v[v.length - 1] = lodash.trim(v[v.length - 1], '\n')
forwardMsg.push({ message: v })
})
if (end)
forwardMsg.push({ message: end })
/** 制作转发内容 */
if (this.e.group)
forwardMsg = await this.e.group.makeForwardMsg(forwardMsg)
else
forwardMsg = await this.e.friend.makeForwardMsg(forwardMsg)
/** 处理描述 */
forwardMsg.data = forwardMsg.data
.replace(/\n/g, '')
.replace(/<title color="#777777" size="26">(.+?)<\/title>/g, '___')
.replace(/___+/, `<title color="#777777" size="26">${title}</title>`)
return forwardMsg
}
/** 分页 */ /** 分页 */
pagination(pageNo, pageSize, array) { pagination(pageNo, pageSize, array) {
let offset = (pageNo - 1) * pageSize let offset = (pageNo - 1) * pageSize