改成使用注解来注册模块

This commit is contained in:
Yutousama 2022-07-16 12:34:14 +08:00
parent d76090af75
commit 05e8814b91
27 changed files with 76 additions and 64 deletions

21
pom.xml
View File

@ -35,17 +35,17 @@
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-jvm</artifactId>
<version>2.10.4</version>
<version>2.11.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-jdk8</artifactId>
<version>1.6.1-native-mt</version>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
<version>1.6.1-native-mt</version>
<version>1.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
@ -60,7 +60,7 @@
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>
<version>2.0.6</version>
<version>2.0.7</version>
</dependency>
<dependency>
@ -117,18 +117,25 @@
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.4.1</version>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.20.1</version>
<version>3.21.1</version>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java-util</artifactId>
<version>3.20.1</version>
<version>3.21.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.reflections/reflections
-->
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.10.2</version>
</dependency>
</dependencies>

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class QQBotApplication {
public static final String version="QQBot v.1.2.29";
public static final String version="QQBot v.1.3";
public static void main(String[] args) {
System.out.println("version = " + version);
SpringApplication.run(QQBotApplication.class, args);

View File

@ -1,17 +1,16 @@
package com.yutou.qqbot;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONFactory;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.Listeners.QQMessageListener;
import com.yutou.qqbot.MessageEvent.Message;
import com.yutou.qqbot.models.Animal.TurnipProphet;
import com.yutou.qqbot.models.Commands.BTDownload;
import com.yutou.qqbot.models.Commands.BaiduDown;
import com.yutou.qqbot.models.Commands.Bangumi;
import com.yutou.qqbot.models.Commands.BTDownload;
import com.yutou.qqbot.models.Commands.Moyu;
import com.yutou.qqbot.models.Commands.System.*;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.models.WebSign.BaiHeHui;
import com.yutou.qqbot.models.WebSign.BiliBiliMangeSign;
import com.yutou.qqbot.models.WebSign.Tsdm;
import com.yutou.qqbot.models.XiaoMi.MiRouter;
@ -30,7 +29,6 @@ import net.mamoe.mirai.utils.ExternalResource;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
@ -38,29 +36,6 @@ public class QQBotManager {
public static Long defGroup = 891655174L;
static {
Model.classList.add(QQSetu.class);
Model.classList.add(Audio.class);
Model.classList.add(BtFlash.class);
Model.classList.add(Cmd.class);
Model.classList.add(Help.class);
Model.classList.add(IP.class);
Model.classList.add(OpenPC.class);
Model.classList.add(Restart.class);
Model.classList.add(ToolsIdea.class);
Model.classList.add(UpdateIP.class);
Model.classList.add(Version.class);
Model.classList.add(Bangumi.class);
Model.classList.add(TurnipProphet.class);
Model.classList.add(Tsdm.class);
Model.classList.add(BaiduDown.class);
Model.classList.add(MiRouter.class);
Model.classList.add(GetSeTu.class);
Model.classList.add(BTDownload.class);
Model.classList.add(BiliBiliMangeSign.class);
Model.classList.add(Moyu.class);
}
private static QQBotManager botManager = null;
private Bot bot;
@ -73,7 +48,6 @@ public class QQBotManager {
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
if (isRun != null && (boolean) isRun) {
isLogin = true;
isInit = true;
init();
}
}
@ -110,7 +84,7 @@ public class QQBotManager {
}
String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:" + QQBotApplication.version);
Log.i(str);
isInit = true;
}
}).start();
bot.join();
@ -120,7 +94,7 @@ public class QQBotManager {
}
public static QQBotManager getInstance() {
public synchronized static QQBotManager getInstance() {
if (botManager == null && !isInit) {
botManager = new QQBotManager();
}
@ -247,8 +221,8 @@ public class QQBotManager {
json.put("t1", 3234567890L);
System.out.println("json = " + json);
String tmp=json.toString();
JSONObject json2=JSON.parseObject(tmp);
String tmp = json.toString();
JSONObject json2 = JSON.parseObject(tmp);
System.out.println("json2 = " + json2);
}

View File

@ -3,6 +3,7 @@ package com.yutou.qqbot.models.Animal;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*;
@ -16,7 +17,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@UseModel
public class TurnipProphet extends Model {
public static class TurnipData {
public static final String MODEL = "趋势:";

View File

@ -8,6 +8,7 @@ import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.TextFormat;
import com.google.protobuf.UnknownFieldSet;
import com.google.protobuf.util.JsonFormat;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.bilibili.*;
import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.interfaces.ObjectInterface;
@ -30,7 +31,7 @@ import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.Inflater;
@UseModel
public class BiliVideo extends Model {
public String downloadPath = "tmp";

View File

@ -1,11 +1,12 @@
package com.yutou.qqbot.models.Commands;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.ObjectInterface;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.AppTools;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class BTDownload extends Model {
private static final String DownloadHomePath="/media/yutou/disk_lvm/public/download/";
@Override

View File

@ -1,5 +1,6 @@
package com.yutou.qqbot.models.Commands;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.ObjectInterface;
import com.yutou.qqbot.models.Model;
@ -8,7 +9,7 @@ import com.yutou.qqbot.utlis.Log;
import net.mamoe.mirai.event.events.MessageEvent;
import java.io.File;
@UseModel
public class BaiduDown extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,5 +1,6 @@
package com.yutou.qqbot.models.Commands;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.models.Model;
@ -14,7 +15,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@UseModel
public class Bangumi extends Model {

View File

@ -2,6 +2,7 @@ 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;
@ -11,7 +12,7 @@ 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() {

View File

@ -1,9 +1,10 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.models.audio.QQAudio;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class Audio extends Model {
@Override

View File

@ -1,10 +1,11 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.HttpTools;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class BtFlash extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,9 +1,10 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.RedisTools;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class Cmd extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,9 +1,10 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class Help extends Model {
@Override

View File

@ -1,9 +1,10 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.RedisTools;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class IP extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,12 +1,13 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.RedisTools;
import net.mamoe.mirai.event.events.MessageEvent;
import java.text.SimpleDateFormat;
import java.util.Date;
@UseModel
public class OpenPC extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,10 +1,11 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.AppTools;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class Restart extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,12 +1,13 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.IdeaTools;
import com.yutou.qqbot.utlis.RedisTools;
import com.yutou.qqbot.utlis.StringUtils;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class ToolsIdea extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,9 +1,10 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.RedisTools;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class UpdateIP extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,9 +1,10 @@
package com.yutou.qqbot.models.Commands.System;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import net.mamoe.mirai.event.events.MessageEvent;
@UseModel
public class Version extends Model {
@Override
public boolean isUserPublic() {

View File

@ -2,6 +2,7 @@ package com.yutou.qqbot.models.WebSign;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*;
@ -11,7 +12,7 @@ import org.openqa.selenium.WebElement;
import java.io.File;
import java.util.concurrent.TimeUnit;
@UseModel
public class BaiHeHui extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,5 +1,6 @@
package com.yutou.qqbot.models.WebSign;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.bilibili.BiliBiliManga;
import com.yutou.qqbot.bilibili.BiliLogin;
@ -9,7 +10,7 @@ import com.yutou.qqbot.utlis.QRCodeUtils;
import net.mamoe.mirai.event.events.MessageEvent;
import java.io.File;
@UseModel
public class BiliBiliMangeSign extends Model {
@Override
public boolean isUserPublic() {

View File

@ -2,6 +2,7 @@ package com.yutou.qqbot.models.WebSign;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*;
@ -10,7 +11,7 @@ import org.openqa.selenium.WebDriver;
import java.io.File;
import java.util.concurrent.TimeUnit;
@UseModel
public class NicePT extends Model {
@Override
public boolean isUserPublic() {

View File

@ -3,6 +3,7 @@ package com.yutou.qqbot.models.WebSign;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*;
@ -11,7 +12,7 @@ import org.openqa.selenium.*;
import java.io.File;
import java.util.concurrent.TimeUnit;
@UseModel
public class Tsdm extends Model {
@Override
public boolean isUserPublic() {

View File

@ -3,6 +3,7 @@ package com.yutou.qqbot.models.XiaoMi;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.HttpTools;
@ -12,7 +13,7 @@ import net.mamoe.mirai.event.events.MessageEvent;
import java.util.HashSet;
import java.util.Set;
@UseModel
public class MiRouter extends Model {
public static String redis_key = "MiRouterDevices";

View File

@ -3,6 +3,7 @@ package com.yutou.qqbot.models.setu;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
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;
@ -21,7 +22,7 @@ import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@UseModel
public class GetSeTu extends Model {
@Override
public boolean isUserPublic() {

View File

@ -1,16 +1,19 @@
package com.yutou.qqbot.utlis;
import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.QQNumberManager;
import com.yutou.qqbot.models.Model;
import net.mamoe.mirai.Bot;
import net.mamoe.mirai.contact.Group;
import org.reflections.Reflections;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
@ -18,6 +21,9 @@ import java.util.TimerTask;
public class ApplicationInit implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
Reflections ref = new Reflections("com.yutou.qqbot.models");
Set<Class<?>> annotatedWith = ref.getTypesAnnotatedWith(UseModel.class);
Model.classList.addAll(annotatedWith);
new Timer().schedule(new TimerTask() {
private String oldTime = "";

View File

@ -347,8 +347,11 @@ public class BangumiTools {
public static void main(String[] args) {
List<String> list = BangumiTools.reportSearchBangumi("处刑少女的生存之道");
for (String s : list) {
/*for (String s : list) {
System.out.println(s);
}
}*/
JSONObject test=new JSONObject();
test.put("data",JSON.toJSON(list));
System.out.println(test);
}
}