细节优化
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 msg 消息数组
 | 
				
			||||||
 * @param dec 转发描述
 | 
					 * @param dec 转发描述
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 = []
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,10 +1,11 @@
 | 
				
			||||||
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'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class sendLog extends plugin {
 | 
					export class sendLog extends plugin {
 | 
				
			||||||
  constructor () {
 | 
					  constructor() {
 | 
				
			||||||
    super({
 | 
					    super({
 | 
				
			||||||
      name: '发送日志',
 | 
					      name: '发送日志',
 | 
				
			||||||
      dsc: '发送最近100条运行日志',
 | 
					      dsc: '发送最近100条运行日志',
 | 
				
			||||||
| 
						 | 
					@ -25,7 +26,7 @@ export class sendLog extends plugin {
 | 
				
			||||||
    this.errFile = './logs/error.log'
 | 
					    this.errFile = './logs/error.log'
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async sendLog () {
 | 
					  async sendLog() {
 | 
				
			||||||
    let lineNum = this.e.msg.match(/\d+/g)
 | 
					    let lineNum = this.e.msg.match(/\d+/g)
 | 
				
			||||||
    if (lineNum) {
 | 
					    if (lineNum) {
 | 
				
			||||||
      this.lineNum = lineNum[0]
 | 
					      this.lineNum = lineNum[0]
 | 
				
			||||||
| 
						 | 
					@ -49,12 +50,12 @@ 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)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getLog (logFile) {
 | 
					  getLog(logFile) {
 | 
				
			||||||
    let log = fs.readFileSync(logFile, { encoding: 'utf-8' })
 | 
					    let log = fs.readFileSync(logFile, { encoding: 'utf-8' })
 | 
				
			||||||
    log = log.split('\n')
 | 
					    log = log.split('\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ const { exec, execSync } = require('child_process')
 | 
				
			||||||
let uping = false
 | 
					let uping = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class update extends plugin {
 | 
					export class update extends plugin {
 | 
				
			||||||
  constructor () {
 | 
					  constructor() {
 | 
				
			||||||
    super({
 | 
					    super({
 | 
				
			||||||
      name: '更新',
 | 
					      name: '更新',
 | 
				
			||||||
      dsc: '#更新 #强制更新',
 | 
					      dsc: '#更新 #强制更新',
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ export class update extends plugin {
 | 
				
			||||||
          fnc: 'update'
 | 
					          fnc: 'update'
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          reg: '^#全部更新$',
 | 
					          reg: '^#全部(强制)?更新$',
 | 
				
			||||||
          fnc: 'updateAll',
 | 
					          fnc: 'updateAll',
 | 
				
			||||||
          permission: 'master'
 | 
					          permission: 'master'
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
| 
						 | 
					@ -37,7 +37,7 @@ export class update extends plugin {
 | 
				
			||||||
    this.typeName = 'TRSS-Yunzai'
 | 
					    this.typeName = 'TRSS-Yunzai'
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async update () {
 | 
					  async update() {
 | 
				
			||||||
    if (!this.e.isMaster) return false
 | 
					    if (!this.e.isMaster) return false
 | 
				
			||||||
    if (uping) {
 | 
					    if (uping) {
 | 
				
			||||||
      await this.reply('已有命令更新中..请勿重复操作')
 | 
					      await this.reply('已有命令更新中..请勿重复操作')
 | 
				
			||||||
| 
						 | 
					@ -64,7 +64,7 @@ export class update extends plugin {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async checkGit () {
 | 
					  async checkGit() {
 | 
				
			||||||
    let ret = await execSync('git --version', { encoding: 'utf-8' })
 | 
					    let ret = await execSync('git --version', { encoding: 'utf-8' })
 | 
				
			||||||
    if (!ret || !ret.includes('git version')) {
 | 
					    if (!ret || !ret.includes('git version')) {
 | 
				
			||||||
      await this.reply('请先安装git')
 | 
					      await this.reply('请先安装git')
 | 
				
			||||||
| 
						 | 
					@ -74,7 +74,7 @@ export class update extends plugin {
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  getPlugin (plugin = '') {
 | 
					  getPlugin(plugin = '') {
 | 
				
			||||||
    if (!plugin) {
 | 
					    if (!plugin) {
 | 
				
			||||||
      plugin = this.e.msg.replace(/#|更新|强制/g, '')
 | 
					      plugin = this.e.msg.replace(/#|更新|强制/g, '')
 | 
				
			||||||
      if (!plugin) return ''
 | 
					      if (!plugin) return ''
 | 
				
			||||||
| 
						 | 
					@ -86,7 +86,7 @@ export class update extends plugin {
 | 
				
			||||||
    return plugin
 | 
					    return plugin
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async execSync (cmd) {
 | 
					  async execSync(cmd) {
 | 
				
			||||||
    return new Promise((resolve, reject) => {
 | 
					    return new Promise((resolve, reject) => {
 | 
				
			||||||
      exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
 | 
					      exec(cmd, { windowsHide: true }, (error, stdout, stderr) => {
 | 
				
			||||||
        resolve({ error, stdout, stderr })
 | 
					        resolve({ error, stdout, stderr })
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ export class update extends plugin {
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async runUpdate (plugin = '') {
 | 
					  async runUpdate(plugin = '') {
 | 
				
			||||||
    this.isNowUp = false
 | 
					    this.isNowUp = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let cm = 'git pull --no-rebase'
 | 
					    let cm = 'git pull --no-rebase'
 | 
				
			||||||
| 
						 | 
					@ -143,7 +143,7 @@ export class update extends plugin {
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getcommitId (plugin = '') {
 | 
					  async getcommitId(plugin = '') {
 | 
				
			||||||
    let cm = 'git rev-parse --short HEAD'
 | 
					    let cm = 'git rev-parse --short HEAD'
 | 
				
			||||||
    if (plugin) {
 | 
					    if (plugin) {
 | 
				
			||||||
      cm = `cd "plugins/${plugin}" && git rev-parse --short HEAD`
 | 
					      cm = `cd "plugins/${plugin}" && git rev-parse --short HEAD`
 | 
				
			||||||
| 
						 | 
					@ -155,7 +155,7 @@ export class update extends plugin {
 | 
				
			||||||
    return commitId
 | 
					    return commitId
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getTime (plugin = '') {
 | 
					  async getTime(plugin = '') {
 | 
				
			||||||
    let cm = 'git log -1 --pretty=format:"%cd" --date=format:"%F %T"'
 | 
					    let cm = 'git log -1 --pretty=format:"%cd" --date=format:"%F %T"'
 | 
				
			||||||
    if (plugin) {
 | 
					    if (plugin) {
 | 
				
			||||||
      cm = `cd "plugins/${plugin}" && git log -1 --pretty=format:"%cd" --date=format:"%F %T"`
 | 
					      cm = `cd "plugins/${plugin}" && git log -1 --pretty=format:"%cd" --date=format:"%F %T"`
 | 
				
			||||||
| 
						 | 
					@ -173,7 +173,7 @@ export class update extends plugin {
 | 
				
			||||||
    return time
 | 
					    return time
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async gitErr (err, stdout) {
 | 
					  async gitErr(err, stdout) {
 | 
				
			||||||
    let msg = '更新失败!'
 | 
					    let msg = '更新失败!'
 | 
				
			||||||
    let errMsg = err.toString()
 | 
					    let errMsg = err.toString()
 | 
				
			||||||
    stdout = stdout.toString()
 | 
					    stdout = stdout.toString()
 | 
				
			||||||
| 
						 | 
					@ -203,7 +203,7 @@ export class update extends plugin {
 | 
				
			||||||
    await this.reply([errMsg, stdout])
 | 
					    await this.reply([errMsg, stdout])
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async updateAll () {
 | 
					  async updateAll() {
 | 
				
			||||||
    let dirs = fs.readdirSync('./plugins/')
 | 
					    let dirs = fs.readdirSync('./plugins/')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await this.runUpdate()
 | 
					    await this.runUpdate()
 | 
				
			||||||
| 
						 | 
					@ -221,11 +221,11 @@ export class update extends plugin {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  restart () {
 | 
					  restart() {
 | 
				
			||||||
    new Restart(this.e).restart()
 | 
					    new Restart(this.e).restart()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getLog (plugin = '') {
 | 
					  async getLog(plugin = '') {
 | 
				
			||||||
    let cm = 'git log -20 --pretty=format:"%h||[%cd] %s" --date=format:"%F %T"'
 | 
					    let cm = 'git log -20 --pretty=format:"%h||[%cd] %s" --date=format:"%F %T"'
 | 
				
			||||||
    if (plugin) {
 | 
					    if (plugin) {
 | 
				
			||||||
      cm = `cd "plugins/${plugin}" && ${cm}`
 | 
					      cm = `cd "plugins/${plugin}" && ${cm}`
 | 
				
			||||||
| 
						 | 
					@ -257,33 +257,12 @@ 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) {
 | 
					  async updateLog() {
 | 
				
			||||||
    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()
 | 
					    let log = await this.getLog()
 | 
				
			||||||
    await this.reply(log)
 | 
					    await this.reply(log)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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'
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ import moment from 'moment'
 | 
				
			||||||
let textArr = {}
 | 
					let textArr = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export class add extends plugin {
 | 
					export class add extends plugin {
 | 
				
			||||||
  constructor () {
 | 
					  constructor() {
 | 
				
			||||||
    super({
 | 
					    super({
 | 
				
			||||||
      name: '添加表情',
 | 
					      name: '添加表情',
 | 
				
			||||||
      dsc: '添加表情,文字等',
 | 
					      dsc: '添加表情,文字等',
 | 
				
			||||||
| 
						 | 
					@ -44,7 +44,7 @@ export class add extends plugin {
 | 
				
			||||||
    this.isGlobal = false
 | 
					    this.isGlobal = false
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async init () {
 | 
					  async init() {
 | 
				
			||||||
    if (!fs.existsSync(this.path)) {
 | 
					    if (!fs.existsSync(this.path)) {
 | 
				
			||||||
      fs.mkdirSync(this.path)
 | 
					      fs.mkdirSync(this.path)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					@ -53,7 +53,7 @@ export class add extends plugin {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async accept () {
 | 
					  async accept() {
 | 
				
			||||||
    /** 处理消息 */
 | 
					    /** 处理消息 */
 | 
				
			||||||
    if (this.e.atBot && this.e.msg && this.e?.msg.includes('添加') && !this.e?.msg.includes('#')) {
 | 
					    if (this.e.atBot && this.e.msg && this.e?.msg.includes('添加') && !this.e?.msg.includes('#')) {
 | 
				
			||||||
      this.e.msg = '#' + this.e.msg
 | 
					      this.e.msg = '#' + this.e.msg
 | 
				
			||||||
| 
						 | 
					@ -61,12 +61,12 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 群号key */
 | 
					  /** 群号key */
 | 
				
			||||||
  get grpKey () {
 | 
					  get grpKey() {
 | 
				
			||||||
    return `Yz:group_id:${this.e.user_id}`
 | 
					    return `Yz:group_id:${this.e.user_id}`
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** #添加 */
 | 
					  /** #添加 */
 | 
				
			||||||
  async add () {
 | 
					  async add() {
 | 
				
			||||||
    this.isGlobal = this.e?.msg.includes("全局");
 | 
					    this.isGlobal = this.e?.msg.includes("全局");
 | 
				
			||||||
    await this.getGroupId()
 | 
					    await this.getGroupId()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,14 +94,13 @@ 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;
 | 
				
			||||||
      return this.e.bot.uin;
 | 
					      return this.e.bot.uin;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (this.e.isGroup) {
 | 
					    if (this.e.isGroup) {
 | 
				
			||||||
      this.group_id = this.e.group_id
 | 
					      this.group_id = this.e.group_id
 | 
				
			||||||
      redis.setEx(this.grpKey, 3600 * 24 * 30, String(this.group_id))
 | 
					      redis.setEx(this.grpKey, 3600 * 24 * 30, String(this.group_id))
 | 
				
			||||||
| 
						 | 
					@ -118,7 +117,7 @@ export class add extends plugin {
 | 
				
			||||||
    return false
 | 
					    return false
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  checkAuth () {
 | 
					  checkAuth() {
 | 
				
			||||||
    if (this.e.isMaster) return true
 | 
					    if (this.e.isMaster) return true
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
					    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
				
			||||||
| 
						 | 
					@ -141,7 +140,7 @@ export class add extends plugin {
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  checkKeyWord () {
 | 
					  checkKeyWord() {
 | 
				
			||||||
    if (this.e.img && this.e.img.length > 1) {
 | 
					    if (this.e.img && this.e.img.length > 1) {
 | 
				
			||||||
      this.e.reply('添加错误:只能发送一个表情当关键词')
 | 
					      this.e.reply('添加错误:只能发送一个表情当关键词')
 | 
				
			||||||
      return false
 | 
					      return false
 | 
				
			||||||
| 
						 | 
					@ -164,7 +163,7 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 单独添加 */
 | 
					  /** 单独添加 */
 | 
				
			||||||
  async singleAdd () {
 | 
					  async singleAdd() {
 | 
				
			||||||
    if (this.e.message.length != 2) return false
 | 
					    if (this.e.message.length != 2) return false
 | 
				
			||||||
    let msg = lodash.keyBy(this.e.message, 'type')
 | 
					    let msg = lodash.keyBy(this.e.message, 'type')
 | 
				
			||||||
    if (!this.e.msg || !msg.image) return false
 | 
					    if (!this.e.msg || !msg.image) return false
 | 
				
			||||||
| 
						 | 
					@ -187,7 +186,7 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 获取添加关键词 */
 | 
					  /** 获取添加关键词 */
 | 
				
			||||||
  getKeyWord () {
 | 
					  getKeyWord() {
 | 
				
			||||||
    this.e.isGlobal = this.e.msg.includes("全局");
 | 
					    this.e.isGlobal = this.e.msg.includes("全局");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.keyWord = this.e.raw_message.trim()
 | 
					    this.keyWord = this.e.raw_message.trim()
 | 
				
			||||||
| 
						 | 
					@ -203,7 +202,7 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 过滤别名 */
 | 
					  /** 过滤别名 */
 | 
				
			||||||
  trimAlias (msg) {
 | 
					  trimAlias(msg) {
 | 
				
			||||||
    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
					    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
				
			||||||
    let alias = groupCfg.botAlias
 | 
					    let alias = groupCfg.botAlias
 | 
				
			||||||
    if (!Array.isArray(alias)) {
 | 
					    if (!Array.isArray(alias)) {
 | 
				
			||||||
| 
						 | 
					@ -219,7 +218,7 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 添加内容 */
 | 
					  /** 添加内容 */
 | 
				
			||||||
  async addContext () {
 | 
					  async addContext() {
 | 
				
			||||||
    this.isGlobal = this.e.isGlobal || this.getContext()?.addContext?.isGlobal;
 | 
					    this.isGlobal = this.e.isGlobal || this.getContext()?.addContext?.isGlobal;
 | 
				
			||||||
    await this.getGroupId()
 | 
					    await this.getGroupId()
 | 
				
			||||||
    /** 关键词 */
 | 
					    /** 关键词 */
 | 
				
			||||||
| 
						 | 
					@ -262,7 +261,7 @@ export class add extends plugin {
 | 
				
			||||||
    this.e.reply(retMsg)
 | 
					    this.e.reply(retMsg)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  saveJson () {
 | 
					  saveJson() {
 | 
				
			||||||
    let obj = {}
 | 
					    let obj = {}
 | 
				
			||||||
    for (let [k, v] of textArr[this.group_id]) {
 | 
					    for (let [k, v] of textArr[this.group_id]) {
 | 
				
			||||||
      obj[k] = v
 | 
					      obj[k] = v
 | 
				
			||||||
| 
						 | 
					@ -283,7 +282,7 @@ export class add extends plugin {
 | 
				
			||||||
    );
 | 
					    );
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async saveImg (url, keyWord) {
 | 
					  async saveImg(url, keyWord) {
 | 
				
			||||||
    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
					    let groupCfg = cfg.getGroup(this.e.self_id, this.group_id)
 | 
				
			||||||
    let savePath = `${this.facePath}${this.group_id}/`
 | 
					    let savePath = `${this.facePath}${this.group_id}/`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -321,7 +320,7 @@ export class add extends plugin {
 | 
				
			||||||
    return savePath
 | 
					    return savePath
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async getText () {
 | 
					  async getText() {
 | 
				
			||||||
    if (!this.e.raw_message) return false
 | 
					    if (!this.e.raw_message) return false
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
    this.isGlobal = false
 | 
					    this.isGlobal = false
 | 
				
			||||||
| 
						 | 
					@ -353,7 +352,7 @@ export class add extends plugin {
 | 
				
			||||||
    if (lodash.isEmpty(msg) && lodash.isEmpty(globalMsg)) return false
 | 
					    if (lodash.isEmpty(msg) && lodash.isEmpty(globalMsg)) return false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    msg = [...msg, ...globalMsg]
 | 
					    msg = [...msg, ...globalMsg]
 | 
				
			||||||
    
 | 
					
 | 
				
			||||||
    if (num >= 0 && num < msg.length) {
 | 
					    if (num >= 0 && num < msg.length) {
 | 
				
			||||||
      msg = msg[num]
 | 
					      msg = msg[num]
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
| 
						 | 
					@ -389,7 +388,7 @@ export class add extends plugin {
 | 
				
			||||||
    return true
 | 
					    return true
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  expiredMsg (keyWord, num) {
 | 
					  expiredMsg(keyWord, num) {
 | 
				
			||||||
    logger.mark(`[发送表情]${this.e.logText} ${keyWord} 表情已过期失效`)
 | 
					    logger.mark(`[发送表情]${this.e.logText} ${keyWord} 表情已过期失效`)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let arr = textArr[this.group_id].get(keyWord)
 | 
					    let arr = textArr[this.group_id].get(keyWord)
 | 
				
			||||||
| 
						 | 
					@ -405,7 +404,7 @@ export class add extends plugin {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /** 初始化已添加内容 */
 | 
					  /** 初始化已添加内容 */
 | 
				
			||||||
  initTextArr () {
 | 
					  initTextArr() {
 | 
				
			||||||
    if (textArr[this.group_id]) return
 | 
					    if (textArr[this.group_id]) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    textArr[this.group_id] = new Map()
 | 
					    textArr[this.group_id] = new Map()
 | 
				
			||||||
| 
						 | 
					@ -453,7 +452,7 @@ export class add extends plugin {
 | 
				
			||||||
      fs.mkdirSync(facePath)
 | 
					      fs.mkdirSync(facePath)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  
 | 
					
 | 
				
			||||||
  /** 初始化全局已添加内容 */
 | 
					  /** 初始化全局已添加内容 */
 | 
				
			||||||
  initGlobalTextArr() {
 | 
					  initGlobalTextArr() {
 | 
				
			||||||
    if (textArr[this.e.bot.uin]) return;
 | 
					    if (textArr[this.e.bot.uin]) return;
 | 
				
			||||||
| 
						 | 
					@ -511,7 +510,7 @@ export class add extends plugin {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async del () {
 | 
					  async del() {
 | 
				
			||||||
    this.isGlobal = this.e?.msg.includes("全局");
 | 
					    this.isGlobal = this.e?.msg.includes("全局");
 | 
				
			||||||
    await this.getGroupId()
 | 
					    await this.getGroupId()
 | 
				
			||||||
    if (!this.group_id) return false
 | 
					    if (!this.group_id) return false
 | 
				
			||||||
| 
						 | 
					@ -607,7 +606,7 @@ export class add extends plugin {
 | 
				
			||||||
    this.saveJson()
 | 
					    this.saveJson()
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  async list () {
 | 
					  async list() {
 | 
				
			||||||
    this.isGlobal = this.e?.msg.includes("全局");
 | 
					    this.isGlobal = this.e?.msg.includes("全局");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let page = 1
 | 
					    let page = 1
 | 
				
			||||||
| 
						 | 
					@ -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,41 +683,14 @@ 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
 | 
				
			||||||
    return offset + pageSize >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize)
 | 
					    return offset + pageSize >= array.length ? array.slice(offset, array.length) : array.slice(offset, offset + pageSize)
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
		Loading…
	
		Reference in New Issue