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

Commit

Permalink
add FlashImageMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Jan 9, 2021
1 parent 5e07a61 commit 4e4212e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .idea/ACGPro.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {
jcenter()
}

val miraiCoreVersion = "+"
val miraiCoreVersion = "1.3.0"
val miraiConsoleVersion = "0.5.2"

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/shrbox/github/acgpro/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Main extends PluginBase {
public static Config config;
public static boolean isPulling = false;
short count = 0;
public static boolean flashImageMode;

public void load_Config() { //配置文件加载
config = loadConfig("config.yml");
Expand All @@ -25,8 +26,10 @@ public void load_Config() { //配置文件加载
Collections.addAll(r18Groups, 1145141919L, 123123123L);
config.setIfAbsent("r18-groups", r18Groups);
config.setIfAbsent("limit-mode", false);
config.setIfAbsent("FlashImageMode", false);
config.save();
r18Groups.clear();
flashImageMode = config.getBoolean("FlashImageMode");
}
public void onEnable() {
load_Config();
Expand Down
58 changes: 47 additions & 11 deletions src/main/java/shrbox/github/acgpro/Thread.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package shrbox.github.acgpro;

import com.google.gson.Gson;
import net.mamoe.mirai.contact.Contact;
import net.mamoe.mirai.message.GroupMessageEvent;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.MessageUtils;
import net.mamoe.mirai.message.MessageReceipt;
import net.mamoe.mirai.message.data.*;

import java.net.URL;
import java.util.List;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;

public class Thread extends java.lang.Thread {
GroupMessageEvent e;
Expand Down Expand Up @@ -80,8 +83,12 @@ public void run() {
e.getGroup().sendMessage("[ACGPro] 正在从服务器下载图片...");
Image image = null;
Main.isPulling = true;
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");
try {
image = e.getGroup().uploadImage(new URL(data.url.replace("i.pixiv.cat", "pixivi.sakuralo.top")));
image = e.getGroup().uploadImage(new URL(imageURL_ss));
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -90,17 +97,35 @@ public void run() {
Main.isPulling = false;
return;
}
e.getGroup().sendMessage(MessageUtils.newChain(image)
.plus("作品标题: " + data.title + "\nPid: " + data.pid + "\n作者名: " + data.author + "\n作者UID: " + data.uid));
e.getGroup().sendMessage("作品标题: " + data.title
+ "\nPid: " + data.pid
+ "\n作者名: " + data.author
+ "\n作者UID: " + data.uid
+ "\n原图: " + imageURL);
if (Main.flashImageMode) {
MessageReceipt<Contact> msg = e.getGroup().sendMessage(FlashImage.from(image));
new Timer().schedule(new TimerTask() {
@Override
public void run() {
msg.recall();
}
}, 20 * 1000);
} else {
e.getGroup().sendMessage(image);
}
} else {
if (pigNum > json.data.size()) pigNum = (short) json.data.size();
e.getGroup().sendMessage("[ACGPro] 正在从服务器下载" + pigNum + "张图片...");
for (short a = 0; a < pigNum; a++) {
Data data = json.data.get(a);
Image image = null;
Main.isPulling = true;
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");
try {
image = e.getGroup().uploadImage(new URL(data.url.replace("i.pixiv.cat", "pixivi.sakuralo.top")));
image = e.getGroup().uploadImage(new URL(imageURL));
} catch (Exception e) {
e.printStackTrace();
}
Expand All @@ -109,11 +134,22 @@ public void run() {
Main.isPulling = false;
continue;
}
e.getGroup().sendMessage(MessageUtils.newChain(image)
.plus("作品标题: " + data.title + "\nPid: "
+ data.pid + "\n作者名: " + data.author
+ "\n作者UID: " + data.uid
+ "\n[" + (a + 1) + "/" + pigNum + "]"));
e.getGroup().sendMessage("作品标题: " + data.title + "\nPid: "
+ data.pid + "\n作者名: " + data.author
+ "\n作者UID: " + data.uid
+ "\n原图: " + imageURL
+ "\n[" + (a + 1) + "/" + pigNum + "]");
if (Main.flashImageMode) {
MessageReceipt<Contact> msg = e.getGroup().sendMessage(FlashImage.from(image));
new Timer().schedule(new TimerTask() {
@Override
public void run() {
msg.recall();
}
}, 20 * 1000);
} else {
e.getGroup().sendMessage(image);
}
}
}
//timerTask.cancel();
Expand Down

0 comments on commit 4e4212e

Please sign in to comment.