From c1427379c6739bbe32f6e0abd87325aac2690c3a Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 17 Apr 2020 18:25:48 +0800 Subject: [PATCH] =?UTF-8?q?[Add]=20StringListRedisCacheStore=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=B1=BB=E5=9E=8B=E4=B8=BAString=E7=9A=84RedisListCac?= =?UTF-8?q?heStore=E5=AE=9E=E7=8E=B0;=20[Change]=20BotCommandProcess=20?= =?UTF-8?q?=E6=9B=B4=E6=8D=A2pagesCache=E7=9A=84=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E7=BB=84=E4=BB=B6(RedisPoolCacheStore>=20->=20Str?= =?UTF-8?q?ingListRedisCacheStore);?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/bot/BotCommandProcess.java | 41 +++++++++++++------ .../bot/cache/StringListRedisCacheStore.java | 30 ++++++++++++++ 2 files changed, 59 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/lamgc/cgj/bot/cache/StringListRedisCacheStore.java diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index 448740f..1e38b55 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -2,7 +2,6 @@ package net.lamgc.cgj.bot; import com.google.common.base.Strings; import com.google.common.base.Throwables; -import com.google.common.reflect.TypeToken; import com.google.common.util.concurrent.ThreadFactoryBuilder; import com.google.gson.*; import io.netty.handler.codec.http.HttpHeaderNames; @@ -55,17 +54,7 @@ public class BotCommandProcess { new LocalHashCacheStore<>(), 3600000, 900000); private final static CacheStore searchBodyCache = new JsonRedisCacheStore(BotEventHandler.redisServer, "searchBody", gson); private final static CacheStore> rankingCache = new JsonObjectRedisListCacheStore(BotEventHandler.redisServer, "ranking", gson); - private final static CacheStore> pagesCache = new RedisPoolCacheStore>(BotEventHandler.redisServer, "imagePages") { - @Override - protected String parse(List dataObj) { - return gson.toJson(dataObj); - } - - @Override - protected List analysis(String dataStr) { - return gson.fromJson(dataStr, new TypeToken>(){}.getType()); - } - }; + private final static CacheStore> pagesCache = new StringListRedisCacheStore(BotEventHandler.redisServer, "imagePages"); /** * 图片异步缓存执行器 @@ -133,6 +122,34 @@ public class BotCommandProcess { return helpStrBuilder.toString(); } + @Command(commandName = "info") + public static String artworkInfo(@Argument(name = "id") int illustId) { + try { + if(isNoSafe(illustId, globalProp, false)) { + return "阅览禁止:该作品已被封印!!"; + } + + JsonObject illustPreLoadData = getIllustPreLoadData(illustId, false); + StringBuilder builder = new StringBuilder("---------------- 作品信息 ----------------\n"); + builder.append("作品Id: ").append(illustId).append("\n"); + builder.append("作品标题:").append(illustPreLoadData.get("illustTitle").getAsString()).append("\n"); + builder.append("作者(作者Id):").append(illustPreLoadData.get("userName").getAsString()) + .append("(").append(illustPreLoadData.get("userId").getAsInt()).append(")\n"); + builder.append("点赞数:").append(illustPreLoadData.get(PreLoadDataComparator.Attribute.LIKE.attrName).getAsInt()).append("\n"); + builder.append("收藏数:").append(illustPreLoadData.get(PreLoadDataComparator.Attribute.BOOKMARK.attrName).getAsInt()).append("\n"); + builder.append("围观数:").append(illustPreLoadData.get(PreLoadDataComparator.Attribute.VIEW.attrName).getAsInt()).append("\n"); + builder.append("评论数:").append(illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt()).append("\n"); + builder.append("页数:").append(illustPreLoadData.get(PreLoadDataComparator.Attribute.PAGE.attrName).getAsInt()).append("页\n"); + builder.append("---------------- 作品图片 ----------------\n"); + builder.append(getImageById(illustId, PixivDownload.PageQuality.REGULAR, 1)).append("\n"); + builder.append("使用 \".cgj image -id ").append(illustId).append("\" 获取原图。"); + return builder.toString(); + } catch (IOException e) { + e.printStackTrace(); + } + return "尚未支持"; + } + @Command public static String ranking( @Argument(force = false, name = "date") Date queryTime, diff --git a/src/main/java/net/lamgc/cgj/bot/cache/StringListRedisCacheStore.java b/src/main/java/net/lamgc/cgj/bot/cache/StringListRedisCacheStore.java new file mode 100644 index 0000000..0875a0e --- /dev/null +++ b/src/main/java/net/lamgc/cgj/bot/cache/StringListRedisCacheStore.java @@ -0,0 +1,30 @@ +package net.lamgc.cgj.bot.cache; + +import redis.clients.jedis.JedisPool; +import redis.clients.jedis.JedisPoolConfig; + +import java.net.URI; + +public class StringListRedisCacheStore extends RedisListCacheStore { + public StringListRedisCacheStore(URI redisServerUri, String prefix) { + super(redisServerUri, prefix); + } + + public StringListRedisCacheStore(URI redisServerUri, JedisPoolConfig config, int timeout, String password, String prefix) { + super(redisServerUri, config, timeout, password, prefix); + } + + public StringListRedisCacheStore(JedisPool pool, String prefix) { + super(pool, prefix); + } + + @Override + public String parseData(String dataObj) { + return dataObj; + } + + @Override + public String analysisData(String str) { + return str; + } +}