细节优化
This commit is contained in:
		
							parent
							
								
									57f3741d78
								
							
						
					
					
						commit
						72d196a7d3
					
				| 
						 | 
				
			
			@ -53,7 +53,7 @@ function mkdirs (dirname) {
 | 
			
		|||
 | 
			
		||||
/**
 | 
			
		||||
 * 制作转发消息
 | 
			
		||||
 * @param e icqq消息e
 | 
			
		||||
 * @param e 消息事件
 | 
			
		||||
 * @param msg 消息数组
 | 
			
		||||
 * @param dec 转发描述
 | 
			
		||||
 */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,31 +41,29 @@ Bot.adapter.push(new class GSUIDCoreAdapter {
 | 
			
		|||
    const msgs = []
 | 
			
		||||
    for (let i of msg) {
 | 
			
		||||
      if (typeof i != "object")
 | 
			
		||||
        i = { type: "text", data: { text: i }}
 | 
			
		||||
      else if (!i.data)
 | 
			
		||||
        i = { type: i.type, data: { ...i, type: undefined }}
 | 
			
		||||
        i = { type: "text", text: i }
 | 
			
		||||
 | 
			
		||||
      switch (i.type) {
 | 
			
		||||
        case "text":
 | 
			
		||||
          i.data = i.data.text
 | 
			
		||||
          i.data = i.text
 | 
			
		||||
          break
 | 
			
		||||
        case "image":
 | 
			
		||||
          i.data = i.data.file
 | 
			
		||||
          i.data = i.file
 | 
			
		||||
          break
 | 
			
		||||
        case "record":
 | 
			
		||||
          i = { type: "file", data: i.data.file }
 | 
			
		||||
          i = { type: "file", data: i.file }
 | 
			
		||||
          break
 | 
			
		||||
        case "video":
 | 
			
		||||
          i = { type: "file", data: i.data.file }
 | 
			
		||||
          i = { type: "file", data: i.file }
 | 
			
		||||
          break
 | 
			
		||||
        case "file":
 | 
			
		||||
          i.data = i.data.file
 | 
			
		||||
          i.data = i.file
 | 
			
		||||
          break
 | 
			
		||||
        case "at":
 | 
			
		||||
          i.data = i.data.qq
 | 
			
		||||
          i.data = i.qq
 | 
			
		||||
          break
 | 
			
		||||
        case "reply":
 | 
			
		||||
          i.data = i.data.id
 | 
			
		||||
          i.data = i.id
 | 
			
		||||
          break
 | 
			
		||||
        case "node": {
 | 
			
		||||
          const array = []
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
import plugin from '../../lib/plugins/plugin.js'
 | 
			
		||||
import common from '../../lib/common/common.js'
 | 
			
		||||
import fs from 'node:fs'
 | 
			
		||||
import lodash from 'lodash'
 | 
			
		||||
import moment from 'moment'
 | 
			
		||||
| 
						 | 
				
			
			@ -49,7 +50,7 @@ export class sendLog extends plugin {
 | 
			
		|||
      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)
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			@ -78,22 +79,4 @@ export class sendLog extends plugin {
 | 
			
		|||
 | 
			
		||||
    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
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,7 +27,7 @@ export class update extends plugin {
 | 
			
		|||
          fnc: 'update'
 | 
			
		||||
        },
 | 
			
		||||
        {
 | 
			
		||||
          reg: '^#全部更新$',
 | 
			
		||||
          reg: '^#全部(强制)?更新$',
 | 
			
		||||
          fnc: 'updateAll',
 | 
			
		||||
          permission: 'master'
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -257,32 +257,11 @@ export class update extends plugin {
 | 
			
		|||
 | 
			
		||||
    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
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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() {
 | 
			
		||||
    let log = await this.getLog()
 | 
			
		||||
    await this.reply(log)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
 | 
			
		||||
import cfg from '../../lib/config/config.js'
 | 
			
		||||
import plugin from '../../lib/plugins/plugin.js'
 | 
			
		||||
import common from '../../lib/common/common.js'
 | 
			
		||||
import fs from 'node:fs'
 | 
			
		||||
import lodash from 'lodash'
 | 
			
		||||
import { pipeline } from 'stream'
 | 
			
		||||
| 
						 | 
				
			
			@ -95,7 +95,6 @@ export class add extends plugin {
 | 
			
		|||
 | 
			
		||||
  /** 获取群号 */
 | 
			
		||||
  async getGroupId() {
 | 
			
		||||
    
 | 
			
		||||
    /** 添加全局表情,存入到机器人qq文件中 */
 | 
			
		||||
    if (this.isGlobal) {
 | 
			
		||||
      this.group_id = this.e.bot.uin;
 | 
			
		||||
| 
						 | 
				
			
			@ -675,9 +674,8 @@ export class add extends plugin {
 | 
			
		|||
      num++
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let end = ''
 | 
			
		||||
    if (type == 'list' && count > 100) {
 | 
			
		||||
      end = `更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`
 | 
			
		||||
      msg.push(`更多内容请翻页查看\n如:#表情列表${Number(page) + 1}`)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let title = `表情列表,第${page}页,共${count}条`
 | 
			
		||||
| 
						 | 
				
			
			@ -685,38 +683,11 @@ export class add extends plugin {
 | 
			
		|||
      title = `表情${search},${count}条`
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    let forwardMsg = await this.makeForwardMsg(title, msg, end)
 | 
			
		||||
    let forwardMsg = await common.makeForwardMsg(this.e, msg, title)
 | 
			
		||||
 | 
			
		||||
    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) {
 | 
			
		||||
    let offset = (pageNo - 1) * pageSize
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue