Skip to content

Commit

Permalink
修复了又一些bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Touch-Night committed Jan 11, 2023
1 parent 7c50fa4 commit 1873cff
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/main/java/net/touchnight/CAIListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,20 @@ private ListeningStatus onEvent(MessageEvent event) throws Exception {
if (Id == "") {
MessageChain chain = new MessageChainBuilder()
.append(new QuoteReply(event.getMessage()))
.append(getAns(realMsg).getString("我还不知道我是谁,请先用 " + CommandPrefix + "重设ID <newID> 指令来让我知道我的身份"))
.append(getAns(realMsg, event).getString("我还不知道我是谁,请先用 " + CommandPrefix + "重设ID <newID> 指令来让我知道我的身份"))
.build();
event.getSubject().sendMessage(chain);
} else {
MessageChain chain = new MessageChainBuilder()
.append(new QuoteReply(event.getMessage()))
.append(getAns(realMsg).getString("我不认识" + Id + "这个ID对应的角色,它似乎没有出现在你AI乌托邦的聊天列表中"))
.append(getAns(realMsg, event).getString("我不认识" + Id + "这个ID对应的角色,它似乎没有出现在你AI乌托邦的聊天列表中"))
.build();
event.getSubject().sendMessage(chain);
}
} else {
MessageChain chain = new MessageChainBuilder()
.append(new QuoteReply(event.getMessage()))
.append(getAns(realMsg).getString("content"))
.append(getAns(realMsg, event).getString("content"))
.build();
event.getSubject().sendMessage(chain);
}
Expand Down Expand Up @@ -240,7 +240,7 @@ private void resetPrefix(String msg, MessageEvent event) {
}
}

private JSONObject getAns(String msg) throws Exception {
private JSONObject getAns(String msg, MessageEvent event) {
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(50, TimeUnit.SECONDS)
.readTimeout(50, TimeUnit.SECONDS)
Expand All @@ -258,15 +258,23 @@ private JSONObject getAns(String msg) throws Exception {
.addHeader("Te", "trailers")
.addHeader("Authorization", Authorization)
.build();
Response response = client.newCall(request).execute();
String stringAns1 = response.body().string();
JSONObject jsonAns = JSONObject.parseObject(stringAns1);
String stringAns2 = jsonAns.getString("data");
JSONObject jsonAns2 = JSONObject.parseObject(stringAns2);
MsgId = jsonAns2.getString("id");
System.out.println(msg);
response.close();
return jsonAns2;
try {
Response response = client.newCall(request).execute();
String stringAns1 = response.body().string();
JSONObject jsonAns = JSONObject.parseObject(stringAns1);
String stringAns2 = jsonAns.getString("data");
JSONObject jsonAns2 = JSONObject.parseObject(stringAns2);
MsgId = jsonAns2.getString("id");
System.out.println(msg);
response.close();
return jsonAns2;
} catch (Exception e) {
MessageChain chain = new MessageChainBuilder()
.append("似乎密钥未填写或已经过期,使用 " + CommandPrefix + "微信登录 来重新获取密钥吧")
.build();
event.getSubject().sendMessage(chain);
return null;
}
}

private String reSend(String id, MessageEvent event) {
Expand Down Expand Up @@ -321,14 +329,18 @@ private String getHello(String id) throws Exception {
.addHeader("Te", "trailers")
.addHeader("Authorization", Authorization)
.build();
Response response = client.newCall(request).execute();
String stringAns1 = response.body().string();
JSONObject jsonAns = JSONObject.parseObject(stringAns1);
String stringAns2 = jsonAns.getString("data");
JSONObject jsonAns2 = JSONObject.parseObject(stringAns2);
String Hello = jsonAns2.getString("greeting");
response.close();
return Hello;
try {
Response response = client.newCall(request).execute();
String stringAns1 = response.body().string();
JSONObject jsonAns = JSONObject.parseObject(stringAns1);
String stringAns2 = jsonAns.getString("data");
JSONObject jsonAns2 = JSONObject.parseObject(stringAns2);
String Hello = jsonAns2.getString("greeting");
response.close();
return Hello;
} catch (Exception e) {
return "似乎密钥未填写或已经过期,使用 " + CommandPrefix + "微信登录 来重新获取密钥吧";
}
}

private void Flush(MessageEvent event) throws Exception {
Expand Down

0 comments on commit 1873cff

Please sign in to comment.