mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-02-07 21:10:05 +08:00
抽离 常用key到 mj constants 里面
This commit is contained in:
parent
defe628026
commit
3fe04ac98e
@ -2,7 +2,36 @@ package cn.iocoder.yudao.framework.ai.midjourney.constants;
|
|||||||
|
|
||||||
public final class MjConstants {
|
public final class MjConstants {
|
||||||
|
|
||||||
public static final String CHANNEL_ID = "channel_id";
|
/**
|
||||||
|
* 消息 - 编号
|
||||||
|
*/
|
||||||
|
public static final String MSG_ID = "id";
|
||||||
|
/**
|
||||||
|
* 消息 - 类型
|
||||||
|
* 现在已知:
|
||||||
|
* 0:我们发送的消息,和指令
|
||||||
|
* 20: mj生成图片发送过程中
|
||||||
|
* 19: 选择了某一张图片后的通知
|
||||||
|
*/
|
||||||
|
public static final String MSG_TYPE = "type";
|
||||||
|
/**
|
||||||
|
* 平道id
|
||||||
|
*/
|
||||||
|
public static final String MSG_CHANNEL_ID = "channel_id";
|
||||||
|
/**
|
||||||
|
* 内容
|
||||||
|
*
|
||||||
|
* "**南极应该是什么样子? --v 6.0 --style raw** - <@972721304891453450> (32%) (fast, stealth)",
|
||||||
|
*/
|
||||||
|
public static final String MSG_CONTENT = "content";
|
||||||
|
/**
|
||||||
|
* 组件(图片生成好之后才有)
|
||||||
|
*/
|
||||||
|
public static final String MSG_COMPONENTS = "components";
|
||||||
|
/**
|
||||||
|
* 附件(生成中比较模糊的图片)
|
||||||
|
*/
|
||||||
|
public static final String MSG_ATTACHMENTS = "attachments";
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,12 +12,9 @@ import cn.iocoder.yudao.framework.ai.midjourney.constants.MjGennerateStatusEnum;
|
|||||||
import cn.iocoder.yudao.framework.ai.midjourney.constants.MjMessageTypeEnum;
|
import cn.iocoder.yudao.framework.ai.midjourney.constants.MjMessageTypeEnum;
|
||||||
import cn.iocoder.yudao.framework.ai.midjourney.util.MjUtil;
|
import cn.iocoder.yudao.framework.ai.midjourney.util.MjUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.dv8tion.jda.api.utils.data.DataObject;
|
import net.dv8tion.jda.api.utils.data.DataObject;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@ -39,25 +36,28 @@ public class MjMessageListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 转换几个重要的信息
|
||||||
MjMessage mjMessage = new MjMessage();
|
MjMessage mjMessage = new MjMessage();
|
||||||
mjMessage.setId(data.getString("id"));
|
mjMessage.setId(data.getString(MjConstants.MSG_ID));
|
||||||
mjMessage.setType(data.getInt("type"));
|
mjMessage.setType(data.getInt(MjConstants.MSG_TYPE));
|
||||||
mjMessage.setRawData(StrUtil.str(raw.toJson(), "UTF-8"));
|
mjMessage.setRawData(StrUtil.str(raw.toJson(), "UTF-8"));
|
||||||
mjMessage.setContent(MjUtil.parseContent(data.getString("content")));
|
mjMessage.setContent(MjUtil.parseContent(data.getString(MjConstants.MSG_CONTENT)));
|
||||||
|
// 转换 components
|
||||||
if (!data.getArray("components").isEmpty()) {
|
if (!data.getArray(MjConstants.MSG_COMPONENTS).isEmpty()) {
|
||||||
String componentsJson = StrUtil.str(data.getArray("components").toJson(), "UTF-8");
|
String componentsJson = StrUtil.str(data.getArray(MjConstants.MSG_COMPONENTS).toJson(), "UTF-8");
|
||||||
List<MjMessage.ComponentType> components = JSON.parseArray(componentsJson, MjMessage.ComponentType.class);
|
List<MjMessage.ComponentType> components = JSON.parseArray(componentsJson, MjMessage.ComponentType.class);
|
||||||
mjMessage.setComponents(components);
|
mjMessage.setComponents(components);
|
||||||
}
|
}
|
||||||
if (!data.getArray("attachments").isEmpty()) {
|
// 转换附件
|
||||||
String attachmentsJson = StrUtil.str(data.getArray("attachments").toJson(), "UTF-8");
|
if (!data.getArray(MjConstants.MSG_ATTACHMENTS).isEmpty()) {
|
||||||
|
String attachmentsJson = StrUtil.str(data.getArray(MjConstants.MSG_ATTACHMENTS).toJson(), "UTF-8");
|
||||||
List<MjMessage.Attachment> attachments = JSON.parseArray(attachmentsJson, MjMessage.Attachment.class);
|
List<MjMessage.Attachment> attachments = JSON.parseArray(attachmentsJson, MjMessage.Attachment.class);
|
||||||
mjMessage.setAttachments(attachments);
|
mjMessage.setAttachments(attachments);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 转换状态
|
// 转换状态
|
||||||
convertGenerateStatus(mjMessage);
|
convertGenerateStatus(mjMessage);
|
||||||
|
//
|
||||||
|
log.info("message 信息 {}", JSONUtil.toJsonPrettyStr(mjMessage));
|
||||||
System.err.println(JSONUtil.toJsonPrettyStr(mjMessage));
|
System.err.println(JSONUtil.toJsonPrettyStr(mjMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ public class MjMessageListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean ignoreAndLogMessage(DataObject data, MjMessageTypeEnum messageType) {
|
private boolean ignoreAndLogMessage(DataObject data, MjMessageTypeEnum messageType) {
|
||||||
String channelId = data.getString(MjConstants.CHANNEL_ID);
|
String channelId = data.getString(MjConstants.MSG_CHANNEL_ID);
|
||||||
if (!CharSequenceUtil.equals(channelId, midjourneyConfig.getChannelId())) {
|
if (!CharSequenceUtil.equals(channelId, midjourneyConfig.getChannelId())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user