Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
fix: CozeBot_ReplyMsgCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
CatX_feitu committed Feb 22, 2024
1 parent 56de3b2 commit 4d64548
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CozeProxy/src/main/java/catx/feitu/CozeProxy/CozeGPT.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CozeGPT(CozeGPTConfig config,boolean autoLogin) throws Exception {
*/
public void login() throws Exception {
cozeEventListener = new CozeEventListener();
protocol.setConfig(new UniversalEventListenerConfig(config.serverID ,config.botID));
protocol.setConfig(new UniversalEventListenerConfig(config.serverID ,config.botID,!config.Disable_CozeBot_ReplyMsgCheck));
protocol.eventListener = cozeEventListener;
protocol.login(config.loginApp ,config.token ,config.Proxy);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,11 @@ public void sendMessage(String channelID , String message , List<UploadFile> fil
Thread.sleep(1000);
int attempt = 0; // 重试次数
Message latestMessage = api_discord.getLatestMessage(channelID);
if (!latestMessage.getUser().isBot()) { // 如果是bot就已经出现 不需要再等待
if (!latestMessage.getUser().isBot() && (config.filterReply || latestMessage.getMentions().contains(config.filterSelfUserID))) { // 如果是bot就已经出现 不需要再等待
while (!latestMessage.getUser().isBot()) {
if (attempt > 20) { return; }
latestMessage = api_discord.getLatestMessage(channelID);
try { Thread.sleep(500); } catch (InterruptedException ignored) {}
System.out.println(attempt);
System.out.println(latestMessage.getId());
attempt++;
}
}
Expand All @@ -120,7 +118,6 @@ public void sendMessage(String channelID , String message , List<UploadFile> fil
);
if (latestMessage.isHasComponents()) { return; }
try { Thread.sleep(1000); } catch (InterruptedException ignored) {}
System.out.println(attempt);
attempt++;
}
} catch (Exception ignored) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ public class UniversalEventListenerConfig {
public String filterServerID;
public String filterUserID;
public String filterSelfUserID;
public UniversalEventListenerConfig(String serverID, String userID) {
public boolean filterReply;
public UniversalEventListenerConfig(String serverID, String userID , boolean reply) {
filterServerID = serverID;
filterUserID = userID;
filterReply = reply;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ public List<Message> getMessages(String channelId) throws Exception {

for (int i = 0; i < data.size(); i++) {
JSONObject object = data.getJSONObject(i);

String id = object.getString("id");
List<Attachment> attachments = new ArrayList<>();
List<User> mentions = new ArrayList<>();

JSONObject object_author = object.getJSONObject("author");
User user = new User(object_author.getString("id") ,object_author.getString("username") ,object_author.getBooleanValue("bot"));
Expand All @@ -151,10 +151,19 @@ public List<Message> getMessages(String channelId) throws Exception {
object_attachments_object.getString("url")
));
}
JSONArray object_mentions = object.getJSONArray("mentions");
for(int j = 0; j < object_attachments.size(); j++) {
JSONObject object_mentions_object = object_attachments.getJSONObject(j);
mentions.add(new User(
object_mentions_object.getString("id"),
object_mentions_object.getString("username"),
false
));
}
messages.add(new Message(id,
object.getIntValue("type"),
object.getString("content"),
user, attachments ,!object.getJSONArray("components").isEmpty()));
user, attachments ,mentions ,!object.getJSONArray("components").isEmpty()));
}
return messages;
}
Expand All @@ -169,6 +178,7 @@ public Message getMessage(String channelId ,String messageId) throws Exception {
String id = object.getString("id");
if (!Objects.equals(id, messageId)) continue;
List<Attachment> attachments = new ArrayList<>();
List<User> mentions = new ArrayList<>();

JSONObject object_author = object.getJSONObject("author");
User user = new User(object_author.getString("id") ,object_author.getString("username") ,object_author.getBoolean("bot"));
Expand All @@ -183,10 +193,19 @@ public Message getMessage(String channelId ,String messageId) throws Exception {
object_attachments_object.getString("url")
));
}
JSONArray object_mentions = object.getJSONArray("mentions");
for(int j = 0; j < object_attachments.size(); j++) {
JSONObject object_mentions_object = object_attachments.getJSONObject(j);
mentions.add(new User(
object_mentions_object.getString("id"),
object_mentions_object.getString("username"),
false
));
}
return new Message(id,
object.getIntValue("type"),
object.getString("content"),
user, attachments ,!object.getJSONArray("components").isEmpty());
user, attachments ,mentions ,!object.getJSONArray("components").isEmpty());
}
throw new InvalidMessageException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ public class Message {
private final String content;
private final User user;
private final List<Attachment> attachments;
private final List<User> mentions;
private final boolean hasComponents;


public Message(String id, int type, String content , User user , List<Attachment> attachments ,boolean hasComponents) {
public Message(String id, int type, String content , User user , List<Attachment> attachments , List<User> mentions ,boolean hasComponents) {
this.id = id;
this.type = type;
this.content = content;
this.user = user;
this.attachments = attachments;
this.mentions = mentions;
this.hasComponents = hasComponents;
}

Expand All @@ -37,6 +39,9 @@ public String getContent() {
public List<Attachment> getAttachments() {
return attachments;
}
public List<User> getMentions() {
return mentions;
}

public boolean isHasComponents() {
return hasComponents;
Expand Down

0 comments on commit 4d64548

Please sign in to comment.