This commit is contained in:
Yutousama 2022-07-23 10:49:28 +08:00
parent 10675c373a
commit c10abbe82e
2 changed files with 28 additions and 6 deletions

View File

@ -38,31 +38,44 @@ public class Moyu extends Model {
} }
@Override @Override
public 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(); downloadImage(false,qq);
} }
if ("10:00:00".equals(time)) { if ("10:00:00".equals(time)) {
send(qq); 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"); 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() {
@Override @Override
public void onDownload(File file) { public void onDownload(File file) {
super.onDownload(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) { 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);
if (file.exists()) { if (file.exists()) {
QQBotManager.getInstance().sendMessage(file, qq, ""); QQBotManager.getInstance().sendMessage(file, qq, "");
}else{
downloadImage(true,qq);
} }
} }
} }

View File

@ -14,6 +14,7 @@ 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", System.err.printf("[%s]%s - %s%n",
AppTools.getToDayNowTimeToString(), AppTools.getToDayNowTimeToString(),
@ -21,4 +22,12 @@ public class Log {
AppTools.getExceptionString(e) AppTools.getExceptionString(e)
); );
} }
public static void i(Object tag, Object log) {
if (tag instanceof String) {
i("[" + tag + "]" + log);
} else {
i(tag.getClass().getSimpleName(), log);
}
}
} }