|
@@ -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.util.MjUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
-import com.google.common.collect.Lists;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.dv8tion.jda.api.utils.data.DataObject;
|
|
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Slf4j
|
|
@@ -39,25 +36,28 @@ public class MjMessageListener {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ // 转换几个重要的信息
|
|
|
MjMessage mjMessage = new MjMessage();
|
|
|
- mjMessage.setId(data.getString("id"));
|
|
|
- mjMessage.setType(data.getInt("type"));
|
|
|
+ mjMessage.setId(data.getString(MjConstants.MSG_ID));
|
|
|
+ mjMessage.setType(data.getInt(MjConstants.MSG_TYPE));
|
|
|
mjMessage.setRawData(StrUtil.str(raw.toJson(), "UTF-8"));
|
|
|
- mjMessage.setContent(MjUtil.parseContent(data.getString("content")));
|
|
|
-
|
|
|
- if (!data.getArray("components").isEmpty()) {
|
|
|
- String componentsJson = StrUtil.str(data.getArray("components").toJson(), "UTF-8");
|
|
|
+ mjMessage.setContent(MjUtil.parseContent(data.getString(MjConstants.MSG_CONTENT)));
|
|
|
+ // 转换 components
|
|
|
+ if (!data.getArray(MjConstants.MSG_COMPONENTS).isEmpty()) {
|
|
|
+ String componentsJson = StrUtil.str(data.getArray(MjConstants.MSG_COMPONENTS).toJson(), "UTF-8");
|
|
|
List<MjMessage.ComponentType> components = JSON.parseArray(componentsJson, MjMessage.ComponentType.class);
|
|
|
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);
|
|
|
mjMessage.setAttachments(attachments);
|
|
|
}
|
|
|
-
|
|
|
// 转换状态
|
|
|
convertGenerateStatus(mjMessage);
|
|
|
+ //
|
|
|
+ log.info("message 信息 {}", JSONUtil.toJsonPrettyStr(mjMessage));
|
|
|
System.err.println(JSONUtil.toJsonPrettyStr(mjMessage));
|
|
|
}
|
|
|
|
|
@@ -72,7 +72,7 @@ public class MjMessageListener {
|
|
|
}
|
|
|
|
|
|
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())) {
|
|
|
return true;
|
|
|
}
|