Skip to content

Commit

Permalink
feat: mjp 使用 redis 记录每一位群成员最近的taskID
Browse files Browse the repository at this point in the history
  • Loading branch information
misaka20002 committed Oct 11, 2024
1 parent 8c9e4b6 commit ffd2d8f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions apps/MJ_Painting.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class MJ_Painting extends plugin {
}
]
})
this.lastTaskId = null
}

async setConfig(e) {
Expand Down Expand Up @@ -120,7 +119,7 @@ export class MJ_Painting extends plugin {
if (result) {
await this.reply(`图片生成完成!\n原始提示词:${prompt}\n任务ID:${taskId}\n图片链接:${result.imageUrl}`)
await this.reply(segment.image(result.imageUrl))
this.lastTaskId = taskId
redis.set(`sf_plugin:MJ_Painting:lastTaskId:${e.user_id}`, taskId, { EX: 7 * 24 * 60 * 60 }); // 写入redis,有效期7天
} else {
await this.reply('生成图片失败,请稍后重试。')
}
Expand Down Expand Up @@ -225,7 +224,7 @@ export class MJ_Painting extends plugin {
const match = e.msg.match(/^#(放大|微调|重绘)(左上|右上|左下|右下)\s*(.*)$/)
if (match) {
const [, action, position, taskId] = match
let useTaskId = taskId.trim() || this.lastTaskId
let useTaskId = taskId.trim() || await redis.get(`sf_plugin:MJ_Painting:lastTaskId:${e.user_id}`)

if (!useTaskId) {
await this.reply('请提供任务ID或先生成一张图片。')
Expand Down Expand Up @@ -262,7 +261,7 @@ export class MJ_Painting extends plugin {
if (result) {
await this.reply(`操作完成!\n操作类型:${action}${position}\n新任务ID:${newTaskId}\n图片链接:${result.imageUrl}`)
await this.reply(segment.image(result.imageUrl))
this.lastTaskId = newTaskId
redis.set(`sf_plugin:MJ_Painting:lastTaskId:${e.user_id}`, newTaskId, { EX: 7 * 24 * 60 * 60 }); // 写入redis,有效期7天
} else {
await this.reply('操作失败,请稍后重试。')
}
Expand Down

0 comments on commit ffd2d8f

Please sign in to comment.