优化 获取回复消息

This commit is contained in:
🌌 2023-07-19 17:15:47 +08:00
parent 8bd23798ad
commit e94b60da7d
2 changed files with 45 additions and 36 deletions

View File

@ -350,40 +350,38 @@ class PluginsLoader {
* @param e.isMaster 是否管理员 * @param e.isMaster 是否管理员
* @param e.logText 日志用户字符串 * @param e.logText 日志用户字符串
* @param e.logFnc 日志方法字符串 * @param e.logFnc 日志方法字符串
* 频道
* @param e.isGuild 是否频道
* @param e.at 支持频道 tiny_id
* @param e.atBot 支持频道
*/ */
dealMsg(e) { dealMsg(e) {
if (e.message) { if (e.message) for (const i of e.message) {
for (let val of e.message) { switch (i.type) {
switch (val.type) {
case "text": case "text":
e.msg = (e.msg || "") + (val.text || "").replace(/^\s*[##井]+\s*/, "#").replace(/^\s*[\\**※]+\s*/, "*").trim() if (!e.msg) e.msg = ""
if (i.text) e.msg += i.text.replace(/^\s*[##井]+\s*/, "#").replace(/^\s*[\\**※]+\s*/, "*").trim()
break break
case "image": case "image":
if (!e.img) { if (Array.isArray(e.img))
e.img = [] e.img.push(i.url)
} else
e.img.push(val.url) e.img = [i.url]
break break
case "at": case "at":
if (val.qq == e.self_id || val.qq == e.self_tiny_id) { if (i.qq == e.self_id)
e.atBot = true e.atBot = true
} else { else
/** 多个at 以最后的为准 */ e.at = i.qq
e.at = val.qq break
} case "reply":
e.reply_id = i.id
if (e.group?.getMsg)
e.getReply = () => e.group.getMsg(e.reply_id)
else if (e.friend?.getMsg)
e.getReply = () => e.friend.getMsg(e.reply_id)
break break
case "file": case "file":
e.file = { name: val.name, fid: val.fid } e.file = val
break break
} }
} }
}
e.logText = "" e.logText = ""

View File

@ -89,8 +89,17 @@ Bot.adapter.push(new class gocqhttpAdapter {
}) })
} }
getMsg(data, message_id) { async getMsg(data, message_id) {
return data.sendApi("get_msg", { message_id }) const msg = (await data.sendApi("get_msg", { message_id })).data
if (msg?.message) {
const message = []
for (const i of msg.message)
message.push({ ...i.data, type: i.type })
msg.message = message
}
return msg
} }
recallMsg(data, message_id) { recallMsg(data, message_id) {
@ -432,7 +441,9 @@ Bot.adapter.push(new class gocqhttpAdapter {
return { return {
...i, ...i,
sendMsg: msg => this.sendFriendMsg(i, msg), sendMsg: msg => this.sendFriendMsg(i, msg),
getMsg: message_id => this.getMsg(i, message_id),
recallMsg: message_id => this.recallMsg(i, message_id), recallMsg: message_id => this.recallMsg(i, message_id),
getForwardMsg: message_id => this.getForwardMsg(i, message_id),
makeForwardMsg: Bot.makeForwardMsg, makeForwardMsg: Bot.makeForwardMsg,
sendForwardMsg: msg => this.sendFriendForwardMsg(i, msg), sendForwardMsg: msg => this.sendFriendForwardMsg(i, msg),
sendFile: (file, name) => this.sendFriendFile(i, file, name), sendFile: (file, name) => this.sendFriendFile(i, file, name),
@ -484,7 +495,9 @@ Bot.adapter.push(new class gocqhttpAdapter {
return { return {
...i, ...i,
sendMsg: msg => this.sendGuildMsg(i, msg), sendMsg: msg => this.sendGuildMsg(i, msg),
getMsg: message_id => this.getMsg(i, message_id),
recallMsg: message_id => this.recallMsg(i, message_id), recallMsg: message_id => this.recallMsg(i, message_id),
getForwardMsg: message_id => this.getForwardMsg(i, message_id),
makeForwardMsg: Bot.makeForwardMsg, makeForwardMsg: Bot.makeForwardMsg,
sendForwardMsg: msg => this.sendGuildForwardMsg(i, msg), sendForwardMsg: msg => this.sendGuildForwardMsg(i, msg),
getInfo: () => this.getGuildInfo(i), getInfo: () => this.getGuildInfo(i),
@ -506,7 +519,9 @@ Bot.adapter.push(new class gocqhttpAdapter {
return { return {
...i, ...i,
sendMsg: msg => this.sendGroupMsg(i, msg), sendMsg: msg => this.sendGroupMsg(i, msg),
getMsg: message_id => this.getMsg(i, message_id),
recallMsg: message_id => this.recallMsg(i, message_id), recallMsg: message_id => this.recallMsg(i, message_id),
getForwardMsg: message_id => this.getForwardMsg(i, message_id),
makeForwardMsg: Bot.makeForwardMsg, makeForwardMsg: Bot.makeForwardMsg,
sendForwardMsg: msg => this.sendGroupForwardMsg(i, msg), sendForwardMsg: msg => this.sendGroupForwardMsg(i, msg),
sendFile: (file, name) => this.sendGroupFile(i, file, undefined, name), sendFile: (file, name) => this.sendGroupFile(i, file, undefined, name),
@ -532,10 +547,6 @@ Bot.adapter.push(new class gocqhttpAdapter {
sendApi: data.sendApi, sendApi: data.sendApi,
stat: { start_time: data.time }, stat: { start_time: data.time },
getMsg: message_id => this.getMsg(data, message_id),
recallMsg: message_id => this.recallMsg(data, message_id),
getForwardMsg: message_id => this.getForwardMsg(data, message_id),
pickUser: user_id => this.pickFriend(data, user_id), pickUser: user_id => this.pickFriend(data, user_id),
pickFriend: user_id => this.pickFriend(data, user_id), pickFriend: user_id => this.pickFriend(data, user_id),