Skip to content

Commit

Permalink
提交linux版本 优化插件体积
Browse files Browse the repository at this point in the history
  • Loading branch information
a1043710306 committed Nov 18, 2022
1 parent 7c258d0 commit 3b6a785
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 140 deletions.
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ dependencies{
implementation ("org.apache.commons:commons-lang3:3.12.0")


implementation ("org.springframework.boot:spring-boot-starter-web:2.7.2")

implementation ("com.alibaba:fastjson:2.0.10")

}
1 change: 0 additions & 1 deletion src/main/java/com/aabbcc/ImagePlugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.mamoe.mirai.console.plugin.jvm.JvmPluginDescriptionBuilder;
import net.mamoe.mirai.event.GlobalEventChannel;
import net.mamoe.mirai.utils.MiraiLogger;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.io.*;
import java.nio.file.Path;
Expand Down
30 changes: 0 additions & 30 deletions src/main/java/com/aabbcc/config/ThreadPool.java

This file was deleted.

14 changes: 2 additions & 12 deletions src/main/java/com/aabbcc/event/MsgEventHandler.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
package com.aabbcc.event;

import com.aabbcc.config.ThreadPool;
import com.aabbcc.utils.HttpUtils2;
import com.aabbcc.utils.PicUtils;
import kotlin.coroutines.CoroutineContext;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.console.plugin.jvm.JavaPluginScheduler;
import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.event.AbstractEvent;
import net.mamoe.mirai.event.EventHandler;
import net.mamoe.mirai.event.ListeningStatus;
import net.mamoe.mirai.event.SimpleListenerHost;
import net.mamoe.mirai.event.events.FriendMessageEvent;
import net.mamoe.mirai.event.events.GroupMessageEvent;
import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.event.events.MessageSyncEvent;
import net.mamoe.mirai.message.data.*;
import net.mamoe.mirai.utils.ExternalResource;
import net.mamoe.mirai.utils.MiraiLogger;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.io.File;
import java.io.IOException;
Expand All @@ -35,7 +25,7 @@
* 消息处理事件
*/
public class MsgEventHandler extends SimpleListenerHost {
private static Logger log= LoggerFactory.getLogger(HttpUtils2.class);
private static Logger log= LoggerFactory.getLogger(MsgEventHandler.class);
final JavaPluginScheduler threadPoolTaskExecutor;
final Properties properties;

Expand Down Expand Up @@ -97,7 +87,7 @@ private void MsgSend(MessageEvent event) throws IOException {
String aira2=properties.getProperty("aira2");
String outDir=properties.getProperty("outDir");
String r18=properties.getProperty("r18","1");
File file=PicUtils.getPicPath(aira2,outDir,Integer.valueOf(r18));
File file=PicUtils.getPicPath(outDir,Integer.valueOf(r18));
ExternalResource externalResource=ExternalResource.Companion.create(file);
Image image= ExternalResource.uploadAsImage(externalResource, event.getSubject());
event.getSubject().sendMessage(new MessageChainBuilder().append(image).build());
Expand Down
88 changes: 0 additions & 88 deletions src/main/java/com/aabbcc/utils/HttpUtils2.java

This file was deleted.

63 changes: 56 additions & 7 deletions src/main/java/com/aabbcc/utils/PicUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,62 @@
import com.aabbcc.Resp.ImageResp;
import com.aabbcc.api.API;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

public class PicUtils {
public static File getPicPath(String aira2c, String outDir, int r18) {
private static Logger log= LoggerFactory.getLogger(PicUtils.class);
// public static File getPicPath(String aira2c, String outDir, int r18) {
// //final String cmd="D:\\aria2\\aria2c.exe %s -d D:\\aria2\\pic -o %s";
// String cmd=String.format("%s %s -d %s -o %s",aira2c,"%s",outDir,"%s");
// //final String url="https://api.lolicon.app/setu/v2";
// String url=String.format(API.loliconApi,r18);
// ImageResp resp=HttpUtils2.httpByGet(url,ImageResp.class,true);
//
// if(resp.getData().size()!=0){
// String ext=resp.getData().get(0).getExt();
// String urld=resp.getData().get(0).getUrls().getOriginal();
// String fileName=String.format("%s.%s",System.nanoTime()+"p",ext);
// String dw=String.format(cmd,urld,fileName);
// try {
// CommandUtils.getInstance().execAndWait(dw);
// return Paths.get(outDir,fileName).toFile();
// } catch (IOException e) {
// e.printStackTrace();
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// return null;
// }


public static File getPicPath(String outDir, int r18) {
//final String cmd="D:\\aria2\\aria2c.exe %s -d D:\\aria2\\pic -o %s";
String cmd=String.format("%s %s -d %s -o %s",aira2c,"%s",outDir,"%s");
//final String url="https://api.lolicon.app/setu/v2";
String url=String.format(API.loliconApi,r18);
ImageResp resp=HttpUtils2.httpByGet(url,ImageResp.class,true);

//final String url="https://api.lolicon.app/setu/v2";
//String url=String.format(API.loliconApi,r18);
//ImageResp resp=HttpUtils2.httpByGet(url,ImageResp.class,true);
ImageResp resp=getPicDwn(r18);
if(resp.getData().size()!=0){
String ext=resp.getData().get(0).getExt();
String urld=resp.getData().get(0).getUrls().getOriginal();
String fileName=String.format("%s.%s",System.nanoTime()+"p",ext);

Path path = Paths.get(outDir, fileName);
String cmd=String.format("wget %s -O %s",urld, path.toString());

String dw=String.format(cmd,urld,fileName);
try {
CommandUtils.getInstance().execAndWait(dw);
return Paths.get(outDir,fileName).toFile();
return path.toFile();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
Expand All @@ -35,8 +68,24 @@ public static File getPicPath(String aira2c, String outDir, int r18) {
}
return null;
}
public static ImageResp getPicDwn(int r18){
String url=String.format(API.loliconApi,r18);
String cmd=String.format("curl %s",url);
try {
byte [] respdata=CommandUtils.getInstance().execAndWaitResult(cmd);
String resp=new String(respdata);
log.info("resp: {}",resp);
return JSONObject.parseObject(resp,ImageResp.class);
}catch (IOException e){
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
return null;
}


public static void main(String args[]){
System.out.println(getPicPath("D:\\aria2\\aria2c.exe","D:\\aria2\\pic",2));
// System.out.println(getPicPath("D:\\aria2\\aria2c.exe","D:\\aria2\\pic",2));
}
}

0 comments on commit 3b6a785

Please sign in to comment.