摸鱼模块:图片提前下载,后续再发送

This commit is contained in:
Yutousama 2022-04-18 23:13:39 +08:00
parent b25a146e9a
commit 731d7734d5

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.AppTools;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
import com.yutou.qqbot.utlis.Log; import com.yutou.qqbot.utlis.Log;
import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.event.events.MessageEvent;
@ -37,20 +38,29 @@ public class Moyu extends Model {
@Override @Override
public void onTime(Long qq, String time) { public void onTime(Long qq, String time) {
super.onTime(qq, time); super.onTime(qq, time);
if ("07:00:00".equals(time)) {
downloadImage();
}
if ("10:00:00".equals(time)) { if ("10:00:00".equals(time)) {
send(qq); send(qq);
} }
} }
private void send(Long qq){ private void downloadImage() {
String ret = HttpTools.get("https://api.j4u.ink/proxy/remote/moyu.json"); String ret = HttpTools.get("https://api.j4u.ink/proxy/remote/moyu.json");
JSONObject json = JSONObject.parseObject(ret); JSONObject json = JSONObject.parseObject(ret);
HttpTools.download(json.getJSONObject("data").getString("moyu_url"), qq+"_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);
QQBotManager.getInstance().sendMessage(file, qq, "");
} }
}); });
} }
private void send(Long qq) {
File file = new File(HttpTools.downloadPath + AppTools.getToDayTime() + "_moyu.jpg");
if (file.exists()) {
QQBotManager.getInstance().sendMessage(file, qq, "");
}
}
} }