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 fe771ce..54f5bf8 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java @@ -38,31 +38,44 @@ public class Moyu extends Model { } @Override - public 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(); + downloadImage(false,qq); } if ("10:00:00".equals(time)) { send(qq); } } - private void downloadImage() { + 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() { @Override public void onDownload(File file) { super.onDownload(file); + if(isSend){ + send(qq); + } + } + + @Override + public void onError(Exception e) { + super.onError(e); + downloadImage(isSend,qq); } }); } private void send(Long qq) { File file = new File(HttpTools.downloadPath + AppTools.getToDayTime() + "_moyu.jpg"); + Log.i(this,"发送图片 : file.exists = "+file.exists()+" qq = "+qq); if (file.exists()) { QQBotManager.getInstance().sendMessage(file, qq, ""); + }else{ + downloadImage(true,qq); } } } diff --git a/src/main/java/com/yutou/qqbot/utlis/Log.java b/src/main/java/com/yutou/qqbot/utlis/Log.java index 2820797..d4f4c2b 100644 --- a/src/main/java/com/yutou/qqbot/utlis/Log.java +++ b/src/main/java/com/yutou/qqbot/utlis/Log.java @@ -6,7 +6,7 @@ public class Log { } public static void i(Object log) { - if (ConfigTools.load(ConfigTools.CONFIG, "logout",boolean.class,false)) { + if (ConfigTools.load(ConfigTools.CONFIG, "logout", boolean.class, false)) { System.out.printf("[%s]%s%n", AppTools.getToDayNowTimeToString(), log @@ -14,11 +14,20 @@ public class Log { } } - public static void e(String tag,Exception e){ + + public static void e(String tag, Exception e) { System.err.printf("[%s]%s - %s%n", AppTools.getToDayNowTimeToString(), tag, AppTools.getExceptionString(e) - ); + ); + } + + public static void i(Object tag, Object log) { + if (tag instanceof String) { + i("[" + tag + "]" + log); + } else { + i(tag.getClass().getSimpleName(), log); + } } }