From d3a3a6e6bafa36c2c333f19fc0a6bf594fa8a926 Mon Sep 17 00:00:00 2001 From: yutou Date: Thu, 13 May 2021 12:00:24 +0800 Subject: [PATCH] update --- .../com/yutou/bilibili/BiliBili/Live.java | 22 +++++++------------ .../yutou/bilibili/BiliBili/LiveUtils.java | 15 +++++-------- .../java/com/yutou/bilibili/Tools/Log.java | 2 +- 3 files changed, 14 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/yutou/bilibili/BiliBili/Live.java b/src/main/java/com/yutou/bilibili/BiliBili/Live.java index dbeaae2..2c848fc 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/Live.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/Live.java @@ -10,6 +10,7 @@ import com.yutou.bilibili.BiliBili.Tools.SaveLive; import com.yutou.bilibili.QQBot.QQBotManager; import com.yutou.bilibili.Tools.AppTools; import com.yutou.bilibili.Tools.Log; +import com.yutou.bilibili.Tools.RedisTools; import com.yutou.bilibili.Tools.Tools; import com.yutou.bilibili.interfaces.DownloadInterface; import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliLiveData; @@ -613,21 +614,14 @@ public class Live implements ApplicationContextAware { } public GiftData getGiftData(int id) { - for (GiftData data : LiveUtils.LiveGiftConfig.giftDataList) { - if (data.getId() == id) { - return data; - } - } + JSONObject item=JSONObject.parseObject(RedisTools.get("bili_gift_"+id,2)); GiftData data = new GiftData(); - BilibiliLiveData liveData = service.queryGiftOfId(id); - if (liveData == null) { - return null; - } - data.setName(liveData.getGiftname()); - data.setPrice(liveData.getPrice()); - data.setIcon(""); - data.setDesc("这是阿B没有收录的礼物,金额可能不准(无法判别为免费礼物)"); - data.setRights("?"); + data.setPrice(item.getInteger("price")); + data.setName(item.getString("name")); + data.setId(item.getInteger("id")); + data.setRights(item.getString("rights")); + data.setIcon(item.getString("img_basic")); + data.setDesc(item.getString("desc")); return data; } } diff --git a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java index ad9ce2d..77117d9 100644 --- a/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java +++ b/src/main/java/com/yutou/bilibili/BiliBili/LiveUtils.java @@ -9,6 +9,7 @@ import com.yutou.bilibili.BiliBili.Services.IBiliBiliLiveService; import com.yutou.bilibili.BiliBili.Tools.SaveLive; import com.yutou.bilibili.Tools.AppTools; import com.yutou.bilibili.Tools.Log; +import com.yutou.bilibili.Tools.RedisTools; import com.yutou.bilibili.mybatis.Bili.mybatis.model.BilibiliUpInfo; import org.springframework.util.StringUtils; @@ -389,7 +390,6 @@ public class LiveUtils { @Resource IBiliBiliLiveService service; private static LiveGiftConfig config; - public static List giftDataList = new ArrayList<>(); public static LiveGiftConfig getInstance() { if (config == null) { @@ -403,19 +403,14 @@ public class LiveUtils { } public void init() { - giftDataList = new ArrayList<>(); JSONObject json = http_get("https://api.live.bilibili.com/xlive/web-room/v1/giftPanel/giftConfig?platform=pc"); + if(json==null){ + return; + } JSONArray list = json.getJSONObject("data").getJSONArray("list"); for (Object o : list) { JSONObject item = (JSONObject) o; - GiftData data = new GiftData(); - data.setPrice(item.getInteger("price")); - data.setName(item.getString("name")); - data.setId(item.getInteger("id")); - data.setRights(item.getString("rights")); - data.setIcon(item.getString("img_basic")); - data.setDesc(item.getString("desc")); - giftDataList.add(data); + RedisTools.set(2,"bili_gift_"+item.getInteger("id"),item.toJSONString()); } } diff --git a/src/main/java/com/yutou/bilibili/Tools/Log.java b/src/main/java/com/yutou/bilibili/Tools/Log.java index a1e4e7c..5c9d85a 100644 --- a/src/main/java/com/yutou/bilibili/Tools/Log.java +++ b/src/main/java/com/yutou/bilibili/Tools/Log.java @@ -27,7 +27,7 @@ public class Log { } public static void i(String timer,int roomId,Object log){ String logFlag=RedisTools.get("live-log",1); - if(logFlag!=null&&logFlag.equals("true")) { + if("true".equals(logFlag)) { getLogger("[" + timer.replace(":", "_") + "]" + roomId).log(Level.INFO, log.toString()); } }