Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extra为null报错 #16

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![Maven-Central](https://img.shields.io/maven-central/v/cn.enaium/kook-spring-boot-starter?style=flat-square)
![JitPack](https://img.shields.io/jitpack/version/com.github.Enaium/kook-spring-boot-starter?style=flat-square)
![GitHub](https://img.shields.io/github/license/enaium/kook-spring-boot-starter?style=flat-square)
![Enaium的频道](https://www.kookapp.cn/api/v3/badge/guild?style=0&guild_id=7057670786047912)
[![Enaium的频道](https://www.kookapp.cn/api/v3/badge/guild?style=0&guild_id=7057670786047912)](https://kook.top/YaP12f)

支持了所有的Http接口和Websocket事件,可以在`test`里查看例子

Expand All @@ -32,4 +32,4 @@ implementation("cn.enaium:kook-spring-boot-starter:最新版本")

## pr

提交pr时请提交到`develop`而不是`master`
提交pr时请提交到`develop`而不是`master`
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public DefaultHandler(ObjectMapper objectMapper, ApplicationEventPublisher publi
try {
jsonNode = new ObjectMapper().readValue(message, JsonNode.class);
} catch (JsonProcessingException e) {
//添加日志
LOGGER.error("JSON解析失败:{}"+e);
throw new RuntimeException(e);
}

Expand Down Expand Up @@ -103,22 +105,27 @@ public DefaultHandler(ObjectMapper objectMapper, ApplicationEventPublisher publi
}
case 0 -> {//事件
final var data = jsonNode.get("d");
final var extra = data.get("extra");
final var type = extra.get("type").asText();

final List<Event> list = events.stream().filter(it -> it.type().equals(type)).toList();
if (list.isEmpty()) {
LOGGER.warn("未知事件:{}", type);
} else {
list.forEach(it -> {
try {
final Object event = objectMapper.readValue(message, it.klass());
publisher.publishEvent(event);
} catch (JsonProcessingException e) {
LOGGER.error("事件处理失败", e);
}
});
if (data.has("extra")) {
final var extra = data.get("extra");
final var type = extra.get("type").asText();

final List<Event> list = events.stream().filter(it -> it.type().equals(type)).toList();
if (list.isEmpty()) {
LOGGER.warn("未知事件:{}", type);
} else {
list.forEach(it -> {
try {
final Object event = objectMapper.readValue(message, it.klass());
publisher.publishEvent(event);
} catch (JsonProcessingException e) {
LOGGER.error("事件处理失败", e);
}
});
}
}else {
LOGGER.error("data extra null exception:{}",jsonNode);
}

}
}
}).then();
Expand Down
Loading