适配 TRSS-Yunzai 原图、上传图片、戳一戳 功能 (#610)

This commit is contained in:
时雨◎星空 2023-07-20 08:31:09 +08:00 committed by GitHub
parent 5e70298547
commit 08edd41ce7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 89 additions and 58 deletions

View File

@ -85,9 +85,17 @@ let Avatar = {
isRelease,
data
}, { e, scale, retMsgId: true })
if (msgRes && msgRes.message_id) {
if (msgRes) {
// 如果消息发送成功就将message_id和图片路径存起来3小时过期
await redis.set(`miao:original-picture:${msgRes.message_id}`, JSON.stringify({ type: 'character', img: bg.img }), { EX: 3600 * 3 })
const message_id = [e.message_id]
if (Array.isArray(msgRes.message_id)) {
message_id.push(...msgRes.message_id)
} else {
message_id.push(msgRes.message_id)
}
for (const i of message_id) {
await redis.set(`miao:original-picture:${i}`, JSON.stringify({ type: 'character', img: bg.img }), { EX: 3600 * 3 })
}
}
return true
},

View File

@ -42,13 +42,17 @@ export async function uploadCharacterImg (e) {
imageMessages.push(val)
}
}
if (imageMessages.length === 0 && e.source) {
if (imageMessages.length === 0) {
let source
if (e.isGroup) {
// 支持at图片添加以及支持后发送
source = (await e.group.getChatHistory(e.source?.seq, 1)).pop()
} else {
source = (await e.friend.getChatHistory((e.source?.time + 1), 1)).pop()
if (e.getReply) {
source = await e.getReply()
} else if (e.source) {
if (e.group?.getChatHistory) {
// 支持at图片添加以及支持后发送
source = (await e.group.getChatHistory(e.source?.seq, 1)).pop()
} else if (e.friend?.getChatHistory) {
source = (await e.friend.getChatHistory((e.source?.time + 1), 1)).pop()
}
}
if (source) {
for (let val of source.message) {
@ -63,7 +67,7 @@ export async function uploadCharacterImg (e) {
resid = val.id
}
if (!resid) break
let message = await Bot.getForwardMsg(resid)
let message = await e.bot.getForwardMsg(resid)
for (const item of message) {
for (const i of item.message) {
if (i.type === 'image') {
@ -109,8 +113,12 @@ async function saveImages (e, name, imageMessages) {
e.reply([segment.at(e.user_id, senderName), '添加失败:图片太大了。'])
return true
}
let fileName = val.file.substring(0, val.file.lastIndexOf('.'))
let fileType = val.file.substring(val.file.lastIndexOf('.') + 1)
let fileName = ""
let fileType = "png"
if (val.file) {
fileName = val.file.substring(0, val.file.lastIndexOf('.'))
fileType = val.file.substring(val.file.lastIndexOf('.') + 1)
}
if (response.headers.get('content-type') === 'image/gif') {
fileType = 'gif'
}
@ -132,7 +140,7 @@ async function saveImages (e, name, imageMessages) {
fs.rename(imgPath, newImgPath, () => {
})
imgCount++
Bot.logger.mark(`添加成功: ${path}/${fileName}`)
Bot.logger.mark(`添加成功: ${newImgPath}`)
}
e.reply([segment.at(e.user_id, senderName), `\n成功添加${imgCount}${name}${isProfile ? '面板图' : '图片'}`])
return true
@ -211,11 +219,6 @@ export async function profileImgList (e) {
e.reply('已禁止获取面板图列表')
return true
}
let nickname = Bot.nickname
if (e.isGroup) {
let info = await Bot.getGroupMemberInfo(e.group_id, Bot.uin)
nickname = info.card || info.nickname
}
let name = char.name
let pathSuffix = `profile/normal-character/${name}`
let path = resPath + pathSuffix
@ -229,19 +232,23 @@ export async function profileImgList (e) {
})
msglist.push({
message: [`当前查看的是${name}面板图,共${imgs.length}张,可输入【#删除${name}面板图(序列号)】进行删除`],
nickname: nickname,
user_id: Bot.uin
})
for (let i = 0; i < imgs.length; i++) {
// 合并转发最多99 但是我感觉不会有这么多先不做处理
console.log(`${path}${imgs[i]}`)
msglist.push({
message: [`${i + 1}.`, segment.image(`file://${path}/${imgs[i]}`)],
nickname: nickname,
user_id: Bot.uin
})
}
let msgRsg = await e.reply(await Bot.makeForwardMsg(msglist))
let msg
if (e.group?.makeForwardMsg) {
msg = await e.group.makeForwardMsg(msglist)
} else if (e.friend?.makeForwardMsg) {
msg = await e.friend.makeForwardMsg(msglist)
} else {
msg = await Bot.makeForwardMsg(msglist)
}
let msgRsg = await e.reply(msg)
if (!msgRsg) e.reply('风控了,可私聊查看', true)
} catch (err) {
logger.error(err)

View File

@ -201,12 +201,20 @@ let ProfileDetail = {
}
// 渲染图像
let msgRes = await Common.render('character/profile-detail', renderData, { e, scale: 1.6, retMsgId: true })
if (msgRes && msgRes.message_id) {
if (msgRes) {
// 如果消息发送成功就将message_id和图片路径存起来3小时过期
await redis.set(`miao:original-picture:${msgRes.message_id}`, JSON.stringify({
type: 'profile',
img: renderData?.data?.costumeSplash
}), { EX: 3600 * 3 })
const message_id = [e.message_id]
if (Array.isArray(msgRes.message_id)) {
message_id.push(...msgRes.message_id)
} else {
message_id.push(msgRes.message_id)
}
for (const i of message_id) {
await redis.set(`miao:original-picture:${i}`, JSON.stringify({
type: 'profile',
img: renderData?.data?.costumeSplash
}), { EX: 3600 * 3 })
}
}
return true
},

View File

@ -3,25 +3,29 @@ import { MysApi } from '#miao.models'
/** 获取角色卡片的原图 */
export async function getOriginalPicture (e) {
if (!e.hasReply && !e.source) {
return true
}
// 引用的消息不是自己的消息
if (e.source.user_id !== e.self_id) {
return true
}
// 引用的消息不是纯图片
if (!/^\[图片]$/.test(e.source.message)) {
return true
let source
if (e.reply_id) {
source = { message_id: e.reply_id }
} else {
if (!e.hasReply && !e.source) {
return false
}
// 引用的消息不是自己的消息
if (e.source.user_id !== e.self_id) {
return false
}
// 引用的消息不是纯图片
if (!/^\[图片]$/.test(e.source.message)) {
return false
}
// 获取原消息
if (e.group?.getChatHistory) {
source = (await e.group.getChatHistory(e.source.seq, 1)).pop()
} else if (e.friend?.getChatHistory) {
source = (await e.friend.getChatHistory(e.source.time, 1)).pop()
}
}
let originalPic = Cfg.get('originalPic') * 1
// 获取原消息
let source
if (e.isGroup) {
source = (await e.group.getChatHistory(e.source.seq, 1)).pop()
} else {
source = (await e.friend.getChatHistory(e.source.time, 1)).pop()
}
if (source) {
let imgPath = await redis.get(`miao:original-picture:${source.message_id}`)
if (imgPath) {
@ -48,17 +52,12 @@ export async function getOriginalPicture (e) {
}
return true
}
if (source.time) {
let time = new Date()
// 对at错图像的增加嘲讽...
if (time / 1000 - source.time < 3600) {
e.reply(segment.image(`file://${process.cwd()}/plugins/miao-plugin/resources/common/face/what.jpg`))
return true
}
}
// 对at错图像的增加嘲讽...
e.reply(segment.image(`file://${process.cwd()}/plugins/miao-plugin/resources/common/face/what.jpg`))
return false
}
e.reply('消息太过久远了,俺也忘了原图是啥了,下次早点来吧~')
return true
return false
}
/* #敌人等级 */

View File

@ -76,13 +76,14 @@ class App {
cls.prototype[key] = async function (e) {
e = this.e || e
const self_id = e.self_id || e.bot?.uin || Bot.uin
if (event === 'poke') {
if (e.notice_type === 'group') {
if (e.target_id !== Bot.uin && !e.isPoke) {
if (e.target_id !== self_id && !e.isPoke) {
return false
}
// group状态下戳一戳的发起人是operator
if (e.user_id === Bot.uin) {
if (e.user_id === self_id) {
e.user_id = e.operator_id
}
}

View File

@ -77,11 +77,20 @@ const { changelogs, currentVersion } = readLogFile('miao')
const yunzaiVersion = packageJson.version
const isV3 = yunzaiVersion[0] === '3'
const isMiao = packageJson.name === 'miao-yunzai'
let isMiao = false
let name = "Yunzai-Bot"
if (packageJson.name === 'miao-yunzai') {
isMiao = true
name = "Miao-Yunzai"
} else if (packageJson.name === 'trss-yunzai') {
isMiao = true
name = "TRSS-Yunzai"
}
let Version = {
isV3,
isMiao,
name,
get version () {
return currentVersion
},

View File

@ -6,7 +6,6 @@ const Render = {
if (!e.runtime) {
console.log('未找到e.runtime请升级至最新版Yunzai')
}
let BotName = Version.isMiao ? 'Miao-Yunzai' : 'Yunzai-Bot'
return e.runtime.render('miao-plugin', path, params, {
retType: cfg.retMsgId ? 'msgId' : 'default',
beforeRender ({ data }) {
@ -30,7 +29,7 @@ const Render = {
sys: {
scale: Cfg.scale(cfg.scale || 1)
},
copyright: `Created By ${BotName}<span class="version">${Version.yunzai}</span>${pluginName}</span>`,
copyright: `Created By ${Version.name}<span class="version">${Version.yunzai}</span>${pluginName}</span>`,
pageGotoParams: {
waitUntil: 'networkidle2'
}