修复下载摸鱼图片会死循环问题

修复电池签到任务周任务为空问题
This commit is contained in:
yutou 2023-06-20 09:40:27 +08:00
parent 43a816066d
commit 4f5bcc9df3
3 changed files with 25 additions and 15 deletions

View File

@ -19,8 +19,8 @@ public class AppUserTask {
private DayTask dayTask; private DayTask dayTask;
public List<WeekTask> getWeekTask() { public List<WeekTask> getWeekTask() {
if(weekTask == null){ if (weekTask == null) {
weekTask=new ArrayList<>(); weekTask = new ArrayList<>();
} }
return weekTask; return weekTask;
} }
@ -28,12 +28,14 @@ public class AppUserTask {
public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) { public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("当前电池数量:").append(String.format("%.2f → %.2f", sb.append("当前电池数量:").append(String.format("%.2f → %.2f",
(double) oldTask.wallet.gold / 100, (double) oldTask.wallet.gold / 100,
(double) newTask.wallet.gold / 100) (double) newTask.wallet.gold / 100)
).append("\n"); ).append("\n");
sb.append("当前银瓜子数量:").append(newTask.wallet.silver).append("\n"); sb.append("当前银瓜子数量:").append(newTask.wallet.silver).append("\n");
sb.append("每日领取电池:").append(newTask.dayTask.toMessageFormat()).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(); return sb.toString();
} }

View File

@ -160,6 +160,7 @@ public class BiliBiliManga {
} }
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(BiliBiliManga.sign());
} }
@Data @Data

View File

@ -12,6 +12,7 @@ import com.yutou.qqbot.utlis.Log;
import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.event.events.MessageEvent;
import java.io.File; import java.io.File;
@UseModel @UseModel
public class Moyu extends Model { public class Moyu extends Model {
@Override @Override
@ -38,25 +39,27 @@ public class Moyu extends Model {
} }
@Override @Override
public synchronized void onTime(Long qq, String time) { public synchronized void onTime(Long qq, String time) {
super.onTime(qq, time); super.onTime(qq, time);
if ("07:00:00".equals(time)) { if ("07:00:00".equals(time)) {
downloadImage(false,qq); downloadImage(false, qq);
} }
if ("10:00:00".equals(time)) { if ("10:00:00".equals(time)) {
send(qq); send(qq);
} }
} }
private void downloadImage(boolean isSend,Long qq) { private void downloadImage(boolean isSend, Long qq) {
Log.i(this,"下载图片"); Log.i(this, "下载图片");
String ret = HttpTools.get("https://api.j4u.ink/v1/store/other/proxy/remote/moyu.json"); String ret = HttpTools.get("https://api.j4u.ink/v1/store/other/proxy/remote/moyu.json");
JSONObject json = JSON.parseObject(ret); JSONObject json = JSON.parseObject(ret);
HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() { HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() {
int count = 3;
@Override @Override
public void onDownload(File file) { public void onDownload(File file) {
super.onDownload(file); super.onDownload(file);
if(isSend){ if (isSend) {
send(qq); send(qq);
} }
} }
@ -65,18 +68,22 @@ public class Moyu extends Model {
public void onError(Exception e) { public void onError(Exception e) {
super.onError(e); super.onError(e);
e.printStackTrace(); e.printStackTrace();
downloadImage(isSend,qq); if (count == 0) {
return;
}
downloadImage(isSend, qq);
count--;
} }
}); });
} }
private void send(Long qq) { private void send(Long qq) {
File file = new File(HttpTools.downloadPath + AppTools.getToDayTime() + "_moyu.jpg"); 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()) { if (file.exists()) {
QQBotManager.getInstance().sendMessage(file, qq, ""); QQBotManager.getInstance().sendMessage(file, qq, "");
}else{ } else {
downloadImage(true,qq); downloadImage(true, qq);
} }
} }
} }