Skip to content

Commit

Permalink
Update MessageChannel.java
Browse files Browse the repository at this point in the history
  • Loading branch information
mcchampions committed Apr 14, 2024
1 parent f7276b0 commit a05bac9
Showing 1 changed file with 39 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
import lombok.extern.slf4j.Slf4j;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* 消息频道实现
Expand Down Expand Up @@ -96,7 +100,7 @@ public Result withdrawMessage(@NonNull String messageId, String reason) {
* @return result
*/
public Result pinMessage(@NonNull String messageId) {
return getBot().getApi().V2.getChannelMessageApi().setChannelMessageTop(messageId,1);
return getBot().getApi().V2.getChannelMessageApi().setChannelMessageTop(messageId, 1);
}

/**
Expand All @@ -106,7 +110,7 @@ public Result pinMessage(@NonNull String messageId) {
* @return result
*/
public Result unpinMessage(@NonNull String messageId) {
return getBot().getApi().V2.getChannelMessageApi().setChannelMessageTop(messageId,0);
return getBot().getApi().V2.getChannelMessageApi().setChannelMessageTop(messageId, 0);
}

/**
Expand Down Expand Up @@ -143,7 +147,33 @@ public Map<Emoji, Integer> getMessageReactionList(@NonNull String messageId) {
* @return 用户列表
*/
public List<User> getMessageReactionMemberList(@NonNull String messageId, @NonNull Emoji emoji) {
return null;
return CompletableFuture.supplyAsync(() -> {
ExecutorService executorService = Executors.newFixedThreadPool(3);
List<User> userList = new ArrayList<>();
IslandImpl.Longer maxId = new IslandImpl.Longer(0);
List<CompletableFuture<?>> completableFutures = new ArrayList<>();
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
Result result = getBot().getApi().V2.getChannelMessageApi().getChannelMessageReactionMemberList(messageId, 1, emoji.getId(),
100, maxId.getValue()).ifFailure(r -> {
log.error("获取消息信息失败, 错误消息:{};状态code:{};错误数据:{}", r.getMessage(), r.getStatusCode(), r.getJSONObjectData());
});
if (result.isSuccess()) {
if (!(((IslandImpl) getIsland()).splice(result, userList, maxId, completableFutures, executorService))) {
break;
}
} else {
break;
}
}
CompletableFuture.allOf(completableFutures.toArray(CompletableFuture[]::new)).join();
executorService.shutdown();
return userList;
}).join();
}

/**
Expand All @@ -154,17 +184,18 @@ public List<User> getMessageReactionMemberList(@NonNull String messageId, @NonNu
* @return result
*/
public Result addMessageReaction(@NonNull String messageId, @NonNull Emoji emoji) {
return null;
return getBot().getApi().V2.getChannelMessageApi().addChannelMessageReaction(messageId, emoji.getId());
}

/**
* 移除表情反应
*
* @param messageId 消息id
* @param emoji 消息反应
* @param messageId 消息id
* @param emoji 消息反应
* @param dodoSourceId id
* @return result
*/
public Result removeMessageReaction(@NonNull String messageId, @NonNull Emoji emoji) {
return null;
public Result removeMessageReaction(@NonNull String messageId, @NonNull Emoji emoji, @NonNull String dodoSourceId) {
return getBot().getApi().V2.getChannelMessageApi().removeChannelMessageReaction(messageId, emoji.getId(), dodoSourceId);
}
}

0 comments on commit a05bac9

Please sign in to comment.