From 4f5bcc9df3015a55251e9e97d6bbd11a746c0506 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Tue, 20 Jun 2023 09:40:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD=E6=91=B8?= =?UTF-8?q?=E9=B1=BC=E5=9B=BE=E7=89=87=E4=BC=9A=E6=AD=BB=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8D=E7=94=B5=E6=B1=A0?= =?UTF-8?q?=E7=AD=BE=E5=88=B0=E4=BB=BB=E5=8A=A1=E5=91=A8=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/bilibili/AppUserTask.java | 14 ++++++----- .../yutou/qqbot/bilibili/BiliBiliManga.java | 1 + .../com/yutou/qqbot/models/Commands/Moyu.java | 25 ++++++++++++------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java index c5d43de..77efaed 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java +++ b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java @@ -19,8 +19,8 @@ public class AppUserTask { private DayTask dayTask; public List getWeekTask() { - if(weekTask == null){ - weekTask=new ArrayList<>(); + if (weekTask == null) { + weekTask = new ArrayList<>(); } return weekTask; } @@ -28,12 +28,14 @@ public class AppUserTask { public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) { StringBuilder sb = new StringBuilder(); sb.append("当前电池数量:").append(String.format("%.2f → %.2f", - (double) oldTask.wallet.gold / 100, - (double) newTask.wallet.gold / 100) - ).append("\n"); + (double) oldTask.wallet.gold / 100, + (double) newTask.wallet.gold / 100) + ).append("\n"); sb.append("当前银瓜子数量:").append(newTask.wallet.silver).append("\n"); sb.append("每日领取电池:").append(newTask.dayTask.toMessageFormat()).append("\n"); - newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n")); + if (newTask.weekTask != null && !newTask.getWeekTask().isEmpty()) { + newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n")); + } return sb.toString(); } diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java index 130116d..0ed25cb 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java @@ -160,6 +160,7 @@ public class BiliBiliManga { } public static void main(String[] args) { + System.out.println(BiliBiliManga.sign()); } @Data diff --git a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java index 0ae1468..e936f1c 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java @@ -12,6 +12,7 @@ import com.yutou.qqbot.utlis.Log; import net.mamoe.mirai.event.events.MessageEvent; import java.io.File; + @UseModel public class Moyu extends Model { @Override @@ -38,25 +39,27 @@ public class Moyu extends Model { } @Override - public synchronized void onTime(Long qq, String time) { + public synchronized void onTime(Long qq, String time) { super.onTime(qq, time); if ("07:00:00".equals(time)) { - downloadImage(false,qq); + downloadImage(false, qq); } if ("10:00:00".equals(time)) { send(qq); } } - private void downloadImage(boolean isSend,Long qq) { - Log.i(this,"下载图片"); + private void downloadImage(boolean isSend, Long qq) { + Log.i(this, "下载图片"); String ret = HttpTools.get("https://api.j4u.ink/v1/store/other/proxy/remote/moyu.json"); JSONObject json = JSON.parseObject(ret); HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() { + int count = 3; + @Override public void onDownload(File file) { super.onDownload(file); - if(isSend){ + if (isSend) { send(qq); } } @@ -65,18 +68,22 @@ public class Moyu extends Model { public void onError(Exception e) { super.onError(e); e.printStackTrace(); - downloadImage(isSend,qq); + if (count == 0) { + return; + } + downloadImage(isSend, qq); + count--; } }); } private void send(Long qq) { File file = new File(HttpTools.downloadPath + AppTools.getToDayTime() + "_moyu.jpg"); - Log.i(this,"发送图片 : file.exists = "+file.exists()+" qq = "+qq); + Log.i(this, "发送图片 : file.exists = " + file.exists() + " qq = " + qq); if (file.exists()) { QQBotManager.getInstance().sendMessage(file, qq, ""); - }else{ - downloadImage(true,qq); + } else { + downloadImage(true, qq); } } }