mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Add] StringListRedisCacheStore 增加类型为String的RedisListCacheStore实现;
[Change] BotCommandProcess 更换pagesCache的缓存组件(RedisPoolCacheStore<List<String>> -> StringListRedisCacheStore);
This commit is contained in:
parent
f844d150e8
commit
c1427379c6
@ -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<JsonElement> searchBodyCache = new JsonRedisCacheStore(BotEventHandler.redisServer, "searchBody", gson);
|
||||
private final static CacheStore<List<JsonObject>> rankingCache = new JsonObjectRedisListCacheStore(BotEventHandler.redisServer, "ranking", gson);
|
||||
private final static CacheStore<List<String>> pagesCache = new RedisPoolCacheStore<List<String>>(BotEventHandler.redisServer, "imagePages") {
|
||||
@Override
|
||||
protected String parse(List<String> dataObj) {
|
||||
return gson.toJson(dataObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> analysis(String dataStr) {
|
||||
return gson.fromJson(dataStr, new TypeToken<List<String>>(){}.getType());
|
||||
}
|
||||
};
|
||||
private final static CacheStore<List<String>> 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,
|
||||
|
30
src/main/java/net/lamgc/cgj/bot/cache/StringListRedisCacheStore.java
vendored
Normal file
30
src/main/java/net/lamgc/cgj/bot/cache/StringListRedisCacheStore.java
vendored
Normal file
@ -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<String> {
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user