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

Commit

Permalink
last release for mirai-console 0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox committed Dec 5, 2020
1 parent 258b0f0 commit 5e07a61
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion src/main/java/shrbox/github/acgpro/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Connection {
public static String getURL(String keyword, Boolean isr18) {
try {
URL url;
String address = "https://api.lolicon.app/setu/?num=10&apikey=" + Main.config.getString("apikey");
final String address = "https://api.lolicon.app/setu/?num=10&apikey=" + Main.config.getString("apikey");
if (isr18) {
url = new URL(address + "&r18=2&" + "keyword=" + keyword);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package shrbox.github.acgpro;

public class Json_pre {
public class JsonPre {
short code;
}
22 changes: 11 additions & 11 deletions src/main/java/shrbox/github/acgpro/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@

class Main extends PluginBase {
public static Config config;
public static boolean ispulling = false;
public static int version = 20200929;
public static boolean isPulling = false;
short count = 0;
public void load_Config() {

public void load_Config() { //配置文件加载
config = loadConfig("config.yml");
config.setIfAbsent("apikey", "");
config.setIfAbsent("r18", false);
List<Long> r18_groups = new ArrayList<>();
Collections.addAll(r18_groups, 1145141919L, 123123123L);
config.setIfAbsent("r18-groups", r18_groups);
List<Long> r18Groups = new ArrayList<>();
Collections.addAll(r18Groups, 1145141919L, 123123123L);
config.setIfAbsent("r18-groups", r18Groups);
config.setIfAbsent("limit-mode", false);
config.save();
r18_groups.clear();
r18Groups.clear();
}
public void onEnable() {
load_Config();
JCommandManager.getInstance().register(this, new BlockingCommand(
JCommandManager.getInstance().register(this, new BlockingCommand( //注册命令
"acgreload", new ArrayList<>(), "重载ACGPro配置文件", "/acghreload"
) {
@Override
Expand All @@ -45,11 +45,11 @@ public boolean onCommandBlocking(@NotNull CommandSender commandSender, @NotNull
public void run() {
count = 0;
}
}, 60 * 1000, 60 * 1000);
}, 60 * 1000, 60 * 1000); //一分钟自动重置变量count
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) -> {
getEventListener().subscribeAlways(GroupMessageEvent.class, (GroupMessageEvent e) -> {//监听群消息
if (e.getMessage().contentToString().toLowerCase().contains("acg")) {
if (config.getBoolean("limit-mode") && Main.ispulling) {
if (config.getBoolean("limit-mode") && Main.isPulling) {//如果limit-mode为true,则同时只能存在一个图片下载任务
e.getGroup().sendMessage("[ACGPro] 正在下载图片,请稍后再试");
return;
}
Expand Down
64 changes: 32 additions & 32 deletions src/main/java/shrbox/github/acgpro/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,45 @@ public void boot(GroupMessageEvent event) {

@Override
public void run() {
String msgcontent = e.getMessage().contentToString().toLowerCase().replace("acg", "").trim();
short picnum = 1;
if (msgcontent.contains(" ")) {
String[] str = msgcontent.split(" ", 2);
msgcontent = str[0];
String msgContent = e.getMessage().contentToString().toLowerCase().replace("acg", "").trim();
short pigNum = 1;
if (msgContent.contains(" ")) {
String[] str = msgContent.split(" ", 2);
msgContent = str[0];
if (str[1] == null) return;
char[] picnum_ = str[1].toCharArray();
if (!Character.isDigit(picnum_[0])) return;
picnum = Short.parseShort(str[1]);
char[] pigNum_ = str[1].toCharArray();
if (!Character.isDigit(pigNum_[0])) return;
pigNum = Short.parseShort(str[1]);
}
List<Long> r18_groups = Main.config.getLongList("r18-groups");
boolean isr18 = false;
if (Main.config.getBoolean("r18") && r18_groups.contains(e.getGroup().getId())) isr18 = true;
String content = Connection.getURL(msgcontent, isr18);
List<Long> r18Groups = Main.config.getLongList("r18-groups");
boolean isR18 = false;
if (Main.config.getBoolean("r18") && r18Groups.contains(e.getGroup().getId())) isR18 = true;
String content = Connection.getURL(msgContent, isR18);
if (content.equals("")) {
e.getGroup().sendMessage("无法访问到接口");
return;
}
Gson gson = new Gson();
Json_pre json_pre = gson.fromJson(content, Json_pre.class);
String error_msg = null;
if (json_pre.code != 0) {
switch (json_pre.code) {
JsonPre jsonPre = gson.fromJson(content, JsonPre.class);
String errorMsg = null;
if (jsonPre.code != 0) {
switch (jsonPre.code) {
case -1:
error_msg = "内部错误";
errorMsg = "内部错误";
break;
case 401:
error_msg = "apikey不存在或被封禁";
errorMsg = "apikey不存在或被封禁";
break;
case 403:
error_msg = "由于不规范操作拒绝调用";
errorMsg = "由于不规范操作拒绝调用";
break;
case 404:
error_msg = "找不到符合关键词的图片";
errorMsg = "找不到符合关键词的图片";
break;
case 429:
error_msg = "达到调用额度限制";
errorMsg = "达到调用额度限制";
}
e.getGroup().sendMessage("[ACGPro] " + error_msg);
e.getGroup().sendMessage("[ACGPro] " + errorMsg);
return;
}
Json json = gson.fromJson(content, Json.class);
Expand All @@ -73,50 +73,50 @@ public void run() {
};
new Timer().schedule(timerTask, 80 * 1000);
*/
if (picnum == 1) {
if (pigNum == 1) {
Random random = new Random();
short index = (short) random.nextInt(json.data.size());
Data data = json.data.get(index);
e.getGroup().sendMessage("[ACGPro] 正在从服务器下载图片...");
Image image = null;
Main.ispulling = true;
Main.isPulling = true;
try {
image = e.getGroup().uploadImage(new URL(data.url.replace("i.pixiv.cat", "pixivi.sakuralo.top")));
} catch (Exception e) {
e.printStackTrace();
}
if (image == null) {
e.getGroup().sendMessage("[ACGPro] 图片下载错误");
Main.ispulling = false;
Main.isPulling = false;
return;
}
e.getGroup().sendMessage(MessageUtils.newChain(image)
.plus("作品标题: " + data.title + "\nPid: " + data.pid + "\n作者名: " + data.author + "\n作者UID: " + data.uid));
} else {
if (picnum > json.data.size()) picnum = (short) json.data.size();
e.getGroup().sendMessage("[ACGPro] 正在从服务器下载" + picnum + "张图片...");
for (short a = 0; a < picnum; a++) {
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;
Main.isPulling = true;
try {
image = e.getGroup().uploadImage(new URL(data.url.replace("i.pixiv.cat", "pixivi.sakuralo.top")));
} catch (Exception e) {
e.printStackTrace();
}
if (image == null) {
e.getGroup().sendMessage("[ACGPro] 图片下载错误");
Main.ispulling = false;
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) + "/" + picnum + "]"));
+ "\n[" + (a + 1) + "/" + pigNum + "]"));
}
}
//timerTask.cancel();
Main.ispulling = false;
Main.isPulling = false;
}
}

0 comments on commit 5e07a61

Please sign in to comment.