Skip to content

Commit

Permalink
Update update.js
Browse files Browse the repository at this point in the history
  • Loading branch information
hanhan258 committed Aug 13, 2023
1 parent 76dbe5d commit aa1fed0
Showing 1 changed file with 7 additions and 54 deletions.
61 changes: 7 additions & 54 deletions apps/update.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import plugin from '../../../lib/plugins/plugin.js'
import { getforwardMsg } from '../utils/common.js'
import { Restart } from '../../other/restart.js'
import { createRequire } from 'module'
import _ from 'lodash'
Expand Down Expand Up @@ -140,8 +141,12 @@ export class Update extends plugin {
let end = ''
end =
'更多详细信息,请前往Github查看\nhttps://github.com/hanhan258/hanhan-plugin'
log = await this.makeForwardMsg(`hanhan-plugin更新日志,共${line}条`, log, end)

let forwardMsg = [
`hanhan-plugin更新日志,共${line}条`, log, end
]
log = await getforwardMsg(this.e, forwardMsg, {
shouldSendMsg: false
})
return log
}

Expand Down Expand Up @@ -178,58 +183,6 @@ export class Update extends plugin {
return time
}

/**
* 制作转发消息
* @param {string} title 标题 - 首条消息
* @param {string} msg 日志信息
* @param {string} end 最后一条信息
* @returns
*/
async makeForwardMsg (title, msg, end) {
let nickname = (this.e.bot ?? Bot).nickname
if (this.e.isGroup) {
let info = await (this.e.bot ?? Bot).getGroupMemberInfo(this.e.group_id, (this.e.bot ?? Bot).uin)
nickname = info.card || info.nickname
}
let userInfo = {
user_id: (this.e.bot ?? Bot).uin,
nickname
}

let forwardMsg = [
{
...userInfo,
message: title
},
{
...userInfo,
message: msg
}
]

if (end) {
forwardMsg.push({
...userInfo,
message: end
})
}

/** 制作转发内容 */
if (this.e.isGroup) {
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
}

/**
* 处理更新失败的相关函数
* @param {string} err
Expand Down

0 comments on commit aa1fed0

Please sign in to comment.