diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index 1408e3a..c5f1c65 100644 --- a/src/main/java/com/yutou/qqbot/QQBotApplication.java +++ b/src/main/java/com/yutou/qqbot/QQBotApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class QQBotApplication { - public static final String version="QQBot v.1.3.5.2"; + public static final String version="QQBot v.1.3.6"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index ca1fe89..32b406f 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -300,4 +300,33 @@ public class BiliBiliUtils { File file=BiliBiliUtils.download(url,"16.mp4",false); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath()); } + + public static boolean sendLiveDanmu(long roomId,String msg){ + JSONObject body=new JSONObject(); + body.put("msg",msg); + body.put("roomid",roomId); + body.put("color",16777215); + body.put("fontsize",25); + body.put("rnd",System.currentTimeMillis()/1000); + body.put("csrf",BiliLogin.getCookieToken()); + body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body)); + return post.getInteger("code")==0; + } + public static String liveSignIn(){ + //{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"} + JSONObject body=new JSONObject(); + body.put("csrf",BiliLogin.getCookieToken()); + body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); + return post.getString("message"); + } + public static boolean checkLiveRoom(int roomId){ + JSONObject body=new JSONObject(); + body.put("room_id",roomId); + body.put("csrf",BiliLogin.getCookieToken()); + body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); + return post.getInteger("code")==0; + } } diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java index 44aac46..153b2f4 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.HttpTools; +import com.yutou.qqbot.utlis.StringUtils; import java.io.File; import java.nio.charset.StandardCharsets; @@ -69,6 +70,13 @@ public class BiliLogin { JSONObject jsonObject = BiliBiliUtils.getLoginInfo(); return jsonObject.getInteger("code")==0; } + public static String getCookieToken(){ + if (StringUtils.isEmpty(ConfigTools.readFile(new File("bilibili.cookie")))) { + return null; + } + JSONObject json = JSON.parseObject(ConfigTools.readFile(new File("bilibili.cookie"))); + return json.getString("bili_jct"); + } public static void main(String[] args) { diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java new file mode 100644 index 0000000..bfbf257 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -0,0 +1,68 @@ +package com.yutou.qqbot.models.BiliBili; + +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.bilibili.BiliBiliManga; +import com.yutou.qqbot.bilibili.BiliBiliUtils; +import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.RedisTools; +import net.mamoe.mirai.event.events.MessageEvent; + +import java.util.Set; + +public class BiliBiliLive extends Model { + @Override + public boolean isUserPublic() { + return false; + } + + @Override + public String[] getUsePowers() { + return new String[]{ + Model.QQGroupCommands.BILI_LIVE_DANMU_SEND + }; + } + + @Override + public String getModelName() { + return "BiliBili Live Sign in"; + } + + @Override + public synchronized void onTime(Long qq, String time) { + super.onTime(qq, time); + if("00:01:00".equals(time)){ + QQBotManager.getInstance().sendMessage(qq, BiliBiliUtils.liveSignIn()); + Set biliLive = RedisTools.list_get("bili_live"); + StringBuilder builder=new StringBuilder(); + for (String id : biliLive) { + boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.getInteger(id), "打卡"); + builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n"); + } + QQBotManager.getInstance().sendMessage(qq,builder.toString()); + } + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + try { + Integer roomId = Integer.getInteger(msg); + StringBuilder message; + if(BiliBiliUtils.checkLiveRoom(roomId)&&!RedisTools.list_isExist("bili_live",roomId+"")){ + RedisTools.list_add("bili_live",roomId+""); + message = new StringBuilder("live sign Add Success"); + }else{ + message = new StringBuilder("live sign Add Error\n"); + message.append("-----live sign roomId-----\n"); + Set biliLive = RedisTools.list_get("bili_live"); + for (String id : biliLive) { + message.append(id).append("\n"); + } + } + QQBotManager.getInstance().sendMessage(qq,message.toString()); + }catch (Exception e){ + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index f871a88..c6e2e5d 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -35,6 +35,8 @@ public abstract class Model implements ModelInterface { public final static String QQ_BANGUMI_INFO = "!保存动画信息>"; public final static String QQ_MOYU = "!摸鱼"; + public final static String BILI_LIVE_DANMU_SEND="!b站签到"; + } public static class QQFromCommands {