fix: 转发消息。 (#215)

This commit is contained in:
小飞 2023-07-27 04:19:02 +08:00 committed by GitHub
parent f34240511b
commit ad35f9007d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 52 deletions

View File

@ -67,6 +67,7 @@ function mkdirs(dirname) {
* @param msgsscr 转发信息是否为Bot * @param msgsscr 转发信息是否为Bot
*/ */
async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) { async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) {
if (!Array.isArray(msg)) msg = [msg]
let name = msgsscr ? this.e.sender.card || this.e.user_id : Bot.nickname let name = msgsscr ? this.e.sender.card || this.e.user_id : Bot.nickname
let id = msgsscr ? this.e.user_id : Bot.uin let id = msgsscr ? this.e.user_id : Bot.uin
@ -82,11 +83,14 @@ async function makeForwardMsg(e, msg = [], dec = '', msgsscr = false) {
} }
let forwardMsg = [] let forwardMsg = []
for (const message of msg) for (const message of msg){
if(!message) continue
forwardMsg.push({ forwardMsg.push({
...userInfo, ...userInfo,
message message: message
}) })
}
/** 制作转发内容 */ /** 制作转发内容 */
if (e?.group?.makeForwardMsg) { if (e?.group?.makeForwardMsg) {

View File

@ -159,51 +159,13 @@ export class abbrSet extends plugin {
let msg = [] let msg = []
for (let i in list) { for (let i in list) {
let num = Number(i) + 1 let num = Number(i) + 1
msg.push(`${num}.${list[i]}\n`) msg.push(`${num}.${list[i]}`)
} }
let title = `${role.name}别名,${list.length}` let title = `${role.name}别名,${list.length}`
msg = await common.makeForwardMsg(this.e, msg, title) msg = await common.makeForwardMsg(this.e, [title, msg.join("\n")], title)
await this.e.reply(msg) await this.e.reply(msg)
} }
async makeForwardMsg(qq, title, msg) {
let nickname = this.e.bot.nickname
if (this.e.isGroup) {
let info = await this.e.bot.getGroupMemberInfo(this.e.group_id, qq)
nickname = info.card ?? info.nickname
}
let userInfo = {
user_id: this.e.bot.uin,
nickname
}
let forwardMsg = [
{
...userInfo,
message: title
},
{
...userInfo,
message: msg
}
]
/** 制作转发内容 */
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
}
} }

View File

@ -258,13 +258,13 @@ export default class MysNews extends base {
return await this.replyMsg(img, `${param.data.post.subject}`) return await this.replyMsg(img, `${param.data.post.subject}`)
} }
async replyMsg (img, titile) { async replyMsg (img, title) {
if (!img || img.length <= 0) return false if (!img || img.length <= 0) return false
if (img.length == 1) { if (img.length == 1) {
return img[0] return img[0]
} else { } else {
let msg = [titile, ...img] let msg = [title, ...img]
return await common.makeForwardMsg(this.e, msg, titile) return await common.makeForwardMsg(this.e, msg, title)
} }
} }

View File

@ -180,13 +180,13 @@ export default class MysSrNews extends base {
return emp return emp
} }
async replyMsg (img, titile) { async replyMsg (img, title) {
if (!img || img.length <= 0) return false if (!img || img.length <= 0) return false
if (img.length == 1) { if (img.length == 1) {
return img[0] return img[0]
} else { } else {
let msg = [titile, ...img] let msg = [title, ...img]
return await common.makeForwardMsg(this.e, msg, titile) return await common.makeForwardMsg(this.e, msg, title)
} }
} }

View File

@ -49,8 +49,9 @@ export class sendLog extends plugin {
this.reply(`暂无相关日志:${type}`) this.reply(`暂无相关日志:${type}`)
return return
} }
let title = `最近${log.length}${type}日志`
let forwardMsg = await common.makeForwardMsg(this.e, log, `最近${log.length}${type}日志`) let forwardMsg = await common.makeForwardMsg(this.e, [title, log.join("")], title)
await this.reply(forwardMsg) await this.reply(forwardMsg)
} }

View File

@ -255,9 +255,9 @@ export class update extends plugin {
if (log.length <= 0) return '' if (log.length <= 0) return ''
let end = '' let title = `${plugin || 'Miao-Yunzai'}更新日志,共${line}`
log = await common.makeForwardMsg(this.e, [log, end], `${plugin || 'Miao-Yunzai'}更新日志,共${line}`) log = await common.makeForwardMsg(this.e, [title, log], title)
return log return log
} }

View File

@ -734,7 +734,7 @@ export class add extends plugin {
title = `表情${search}${count}` title = `表情${search}${count}`
} }
let forwardMsg = await common.makeForwardMsg(this.e, msg, title) let forwardMsg = await common.makeForwardMsg(this.e, [title, msg], title)
this.e.reply(forwardMsg) this.e.reply(forwardMsg)
} }