Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Commit

Permalink
bugfix & new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jan 11, 2021
1 parent 463f1aa commit 553bb13
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 37 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ apikey: '' //填写apikey
r18: false //是否开启r18
r18-groups: //允许r18的群
- 1145141919810
limit-mode: false //限制模式,只能同时存在一个任务
FlashImageMode: true //闪照模式,发送图片为闪照
AutoRecall: 0 //自动撤回时间,0为禁用
MaxThread: 10 //最大线程数
OriginalImages: false //原图模式
```

# Download
Expand Down
59 changes: 36 additions & 23 deletions src/main/java/shrbox/github/acgpro/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,77 @@

class Main extends PluginBase {
public static Config config;
public static boolean isPulling = false;
short count = 0;
public boolean limitMode;
public static boolean flashImageMode;
public static int autoRecall;

public void load_Config() { //配置文件加载
short pullCount = 0;
public static short threadRunning = 0;

short maxPullCount = 10;
public boolean limitMode = false;
public static boolean flashImageMode = false;
public static int autoRecall = 0;
short maxThread = 10;
public static boolean originalImages = false;

public void loadConfig() { //配置文件加载
config = loadConfig("config.yml");

config.setIfAbsent("apikey", "");
config.setIfAbsent("r18", false);
config.setIfAbsent("MaxPullCount", 10); //每分钟最多请求的次数
config.setIfAbsent("FlashImageMode", false); //闪照模式
config.setIfAbsent("AutoRecall", 0); //自动撤回
config.setIfAbsent("MaxThread", 10); //最大线程数
config.setIfAbsent("OriginalImages", false); //原图模式

List<Long> r18Groups = new ArrayList<>();
Collections.addAll(r18Groups, 1145141919L, 123123123L);
config.setIfAbsent("r18-groups", r18Groups);
config.setIfAbsent("limit-mode", false);
config.setIfAbsent("FlashImageMode", false);
config.setIfAbsent("AutoRecall", 0);
config.save();
r18Groups.clear();

config.save();

maxPullCount = (short) config.getInt("MaxPullCount");
flashImageMode = config.getBoolean("FlashImageMode");
autoRecall = config.getInt("AutoRecall");
limitMode = config.getBoolean("limit-mode");
maxThread = (short) config.getInt("MaxThread");
originalImages = config.getBoolean("OriginalImages");
}

public void onEnable() {
load_Config();

public void registerCommands() {
JCommandManager.getInstance().register(this, new BlockingCommand( //注册命令
"acgreload", new ArrayList<>(), "重载ACGPro配置文件", "/acghreload"
) {
@Override
public boolean onCommandBlocking(@NotNull CommandSender commandSender, @NotNull List<String> list) {
load_Config();
loadConfig();
commandSender.sendMessageBlocking("重载成功");
return true;
}
});
}

public void onEnable() {
loadConfig();
registerCommands();

new Timer().schedule(new TimerTask() {
@Override
public void run() {
count = 0;
pullCount = 0;
}
}, 60 * 1000, 60 * 1000); //一分钟自动重置变量count
}, 60 * 1000, 60 * 1000); //一分钟自动重置变量

System.setProperty("http.agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)");

getEventListener().subscribeAlways(GroupMessageEvent.class, (GroupMessageEvent e) -> {//监听群消息
if (e.getMessage().contentToString().toLowerCase().contains("acg")) {
if (limitMode && Main.isPulling) {//如果limit-mode为true,则同时只能存在一个图片下载任务
e.getGroup().sendMessage("[ACGPro] 正在下载图片,请稍后再试");
return;
}
if (count > 15) {
if (pullCount > maxPullCount || threadRunning >= maxThread) {
e.getGroup().sendMessage(MessageUtils.newChain(new At(e.getSender())).plus("[ACGPro] 请先喝口水再尝试"));
return;
}
count++;
new Thread().boot(e);
pullCount++;
new Thread().newThread(e);
}
});
}
Expand Down
34 changes: 21 additions & 13 deletions src/main/java/shrbox/github/acgpro/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Thread extends java.lang.Thread {
GroupMessageEvent e;

public void boot(GroupMessageEvent event) {
public void newThread(GroupMessageEvent event) {
this.e = event;
this.start();
}
Expand Down Expand Up @@ -83,19 +83,23 @@ public void run() {
Data data = json.data.get(index);
e.getGroup().sendMessage("[ACGPro] 正在从服务器下载图片...");
Image image = null;
Main.isPulling = true;
Main.threadRunning++;
String imageURL = data.url.replace("i.pixiv.cat", "pixivi.sakuralo.top");
String imageURL_ss = imageURL.replace("img-original", "c/540x540_70/img-master")
.replace(".jpg", "_master1200.jpg")
.replace(".png", "_master1200.jpg");
String imageURL_ss = imageURL;
if (!Main.originalImages) {
imageURL_ss = imageURL.replace("img-original", "c/540x540_70/img-master")
.replace(".jpg", "_master1200.jpg")
.replace(".png", "_master1200.jpg");
}

try {
image = e.getGroup().uploadImage(new URL(imageURL_ss));
} catch (Exception e) {
e.printStackTrace();
}
if (image == null) {
e.getGroup().sendMessage("[ACGPro] 图片下载错误");
Main.isPulling = false;
Main.threadRunning--;
return;
}
e.getGroup().sendMessage("作品标题: " + data.title
Expand Down Expand Up @@ -123,19 +127,23 @@ public void run() {
for (short a = 0; a < pigNum; a++) {
Data data = json.data.get(a);
Image image = null;
Main.isPulling = true;
Main.threadRunning++;
String imageURL = data.url.replace("i.pixiv.cat", "pixivi.sakuralo.top");
String imageURL_ss = imageURL.replace("img-original", "c/540x540_70/img-master")
.replace(".jpg", "_master1200.jpg")
.replace(".png", "_master1200.jpg");
String imageURL_ss = imageURL;
if (!Main.originalImages) {
imageURL_ss = imageURL.replace("img-original", "c/540x540_70/img-master")
.replace(".jpg", "_master1200.jpg")
.replace(".png", "_master1200.jpg");
}

try {
image = e.getGroup().uploadImage(new URL(imageURL));
image = e.getGroup().uploadImage(new URL(imageURL_ss));
} catch (Exception e) {
e.printStackTrace();
}
if (image == null) {
e.getGroup().sendMessage("[ACGPro] 图片下载错误");
Main.isPulling = false;
Main.threadRunning--;
continue;
}
e.getGroup().sendMessage("作品标题: " + data.title + "\nPid: "
Expand All @@ -160,6 +168,6 @@ public void run() {
}
}
//timerTask.cancel();
Main.isPulling = false;
Main.threadRunning--;
}
}

0 comments on commit 553bb13

Please sign in to comment.