diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index 25b4b13..126a35a 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -143,8 +143,13 @@ public class BotCommandProcess { @Argument(force = false, name = "date") Date queryTime, @Argument(force = false, name = "force") boolean force, @Argument(force = false, name = "mode", defaultValue = "DAILY") String contentMode, - @Argument(force = false, name = "type", defaultValue = "ALL") String contentType + @Argument(force = false, name = "type", defaultValue = "ALL") String contentType, + @Argument(force = false, name = "p", defaultValue = "1") int pageIndex ) throws InterruptedException { + if(pageIndex <= 0) { + return "色图姬找不到指定页数的排行榜!"; + } + Date queryDate = queryTime; if (queryDate == null) { queryDate = new Date(); @@ -212,8 +217,10 @@ public class BotCommandProcess { log.warn("配置项 {} 的参数值格式有误!", imageLimitPropertyKey); } + int startsIndex = itemLimit * pageIndex - (itemLimit - 1); List rankingInfoList = CacheStoreCentral.getCentral() - .getRankingInfoByCache(type, mode, queryDate, 1, Math.max(0, itemLimit), false); + .getRankingInfoByCache(type, mode, queryDate, + Math.max(1, startsIndex), Math.max(0, itemLimit), false); if(rankingInfoList.isEmpty()) { return "无法查询排行榜,可能排行榜尚未更新。"; } diff --git a/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreCentral.java b/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreCentral.java index 22fe1b9..0319333 100644 --- a/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreCentral.java +++ b/src/main/java/net/lamgc/cgj/bot/cache/CacheStoreCentral.java @@ -402,7 +402,7 @@ public final class CacheStoreCentral { result = rankingCache.getCache(requestSign, start - 1, range); log.trace("RequestSign [{}] 缓存命中.", requestSign); } - return PixivDownload.getRanking(result, start - 1, range); + return result; } /** diff --git a/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java b/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java index a113c87..45ba669 100644 --- a/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java +++ b/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java @@ -4,7 +4,6 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.google.gson.reflect.TypeToken; import io.netty.handler.codec.http.HttpHeaderNames; import net.lamgc.cgj.exception.HttpRequestException; import org.apache.http.Header; @@ -32,7 +31,6 @@ import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; -@SuppressWarnings("ALL") public class PixivDownload { private final static Logger log = LoggerFactory.getLogger(PixivDownload.class); @@ -249,43 +247,6 @@ public class PixivDownload { }); } - /** - * 从JsonArray获取数据 - * @param rankingList JsonArray对象 - * @param rankStart 开始索引, 从0开始 - * @param range 范围 - * @return 返回List对象 - */ - public static List getRanking(List rankingList, int rankStart, int range) { - log.debug("正在读取JsonArray...(rankStart: {}, range: {})", rankStart, range); - ArrayList results = new ArrayList<>(rankingList.size()); - for (int rankIndex = rankStart; rankIndex < rankStart + range; rankIndex++) { - JsonElement jsonElement = rankingList.get(rankIndex - rankStart); - JsonObject rankInfo = jsonElement.getAsJsonObject(); - int rank = rankInfo.get("rank").getAsInt(); - int illustId = rankInfo.get("illust_id").getAsInt(); - int authorId = rankInfo.get("user_id").getAsInt(); - String authorName = rankInfo.get("user_name").getAsString(); - String title = rankInfo.get("title").getAsString(); - log.trace("Array-当前到第 {}/{} 名(总共 {} 名), IllustID: {}, Author: ({}) {}, Title: {}", rank, rankStart + range, range, illustId, authorId, authorName, title); - results.add(rankInfo); - } - log.debug("JsonArray读取完成."); - return results; - } - - /** - * 从JsonArray获取数据 - * @param rankingArray JsonArray对象 - * @param rankStart 开始索引, 从0开始 - * @param range 范围 - * @return 返回List对象 - */ - public static List getRanking(JsonArray rankingArray, int rankStart, int range) { - List list = new Gson().fromJson(rankingArray, new TypeToken>(){}.getType()); - return getRanking(list, rankStart, range); - } - /** * 获取排行榜. *

注意: 如果范围实际上没超出, 但返回排行榜不足, 会导致与实际请求的数量不符, 需要检查

@@ -421,6 +382,7 @@ public class PixivDownload { /** * 插图质量 */ + @SuppressWarnings("unused") public enum PageQuality{ /** * 原图画质