82 lines
2.3 KiB
Java
82 lines
2.3 KiB
Java
package com.yutou.qqbot.models.Commands;
|
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
import com.yutou.qqbot.Annotations.UseModel;
|
|
import com.yutou.qqbot.QQBotManager;
|
|
import com.yutou.qqbot.interfaces.DownloadInterface;
|
|
import com.yutou.qqbot.models.Model;
|
|
import com.yutou.qqbot.utlis.AppTools;
|
|
import com.yutou.qqbot.utlis.HttpTools;
|
|
import com.yutou.qqbot.utlis.Log;
|
|
import net.mamoe.mirai.event.events.MessageEvent;
|
|
|
|
import java.io.File;
|
|
@UseModel
|
|
public class Moyu extends Model {
|
|
@Override
|
|
public boolean isUserPublic() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public String[] getUsePowers() {
|
|
return new String[0];
|
|
}
|
|
|
|
@Override
|
|
public String getModelName() {
|
|
return "摸鱼提醒";
|
|
}
|
|
|
|
@Override
|
|
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
|
super.onMessage(qq, event, isGroup);
|
|
if (msg.equals(QQGroupCommands.QQ_MOYU)) {
|
|
send(qq);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public synchronized void onTime(Long qq, String time) {
|
|
super.onTime(qq, time);
|
|
if ("07:00:00".equals(time)) {
|
|
downloadImage(false,qq);
|
|
}
|
|
if ("10:00:00".equals(time)) {
|
|
send(qq);
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|