permissionItems = PermissionDAO.getInstance().selectForFieldValuesArgs(args);
38 | if (permissionItems != null && !permissionItems.isEmpty()) return permissionItems.get(0);
39 | return null;
40 | }
41 |
42 | /**
43 | * 向数据库中添加一天记录
44 | * @param targetId 发送者qq号
45 | * @param commandId EventHandler注解中的permissionIndex
46 | * @see CheckPermission
47 | * @see PermissionItem
48 | */
49 | public void addPermissionItem(long targetId, int commandId) {
50 | PermissionItem item = new PermissionItem(targetId, String.valueOf(commandId));
51 | updatePermissionItem(item);
52 | }
53 |
54 | /**
55 | * 向数据库中添加一条记录
56 | * @param targetId 发送者qq号
57 | * @param commandId EventHandler注解中的permissionIndex
58 | * @param permits 权限等级 防止下克上
59 | * @param remain 剩余次数
60 | * @see CheckPermission
61 | * @see PermissionItem
62 | */
63 | public void addPermissionItem(long targetId, int commandId, int permits, int remain) {
64 | PermissionItem item = new PermissionItem(targetId, commandId, permits, remain);
65 | updatePermissionItem(item);
66 | }
67 |
68 | /**
69 | * 从数据库中移除一条记录
70 | * 根据发送者qq号和permissionIndex从数据库中移除一条记录
71 | * @param targetId 发送者qq号
72 | * @param commandId EventHandler注解中的permissionIndex
73 | * @see CheckPermission
74 | * @see PermissionItem
75 | */
76 | public void removePermissionItem(long targetId, int commandId) {
77 | PermissionItem item = new PermissionItem(targetId, String.valueOf(commandId));
78 | PermissionDAO.getInstance().delete(item);
79 | }
80 |
81 | /**
82 | * 启用权限
83 | * 根据发送者qq号和permissionIndex从数据库中启用一条记录
84 | * @param targetId 发送者qq号
85 | * @param commandId EventHandler注解中的permissionIndex
86 | * @see CheckPermission
87 | * @see PermissionItem
88 | */
89 | public void enablePermissionItem(long targetId, int commandId) {
90 | PermissionItem item = new PermissionItem(targetId, String.valueOf(commandId));
91 | updatePermissionItem(item);
92 | }
93 |
94 | /**
95 | * 启用权限
96 | * 根据发送者qq号和permissionIndex从数据库中启用一条记录
97 | * @param targetId 发送者qq号
98 | * @param commandId EventHandler注解中的permissionIndex
99 | * @param permits 权限等级
100 | * @see CheckPermission
101 | * @see PermissionItem
102 | */
103 | public void enablePermissionItem(long targetId, int commandId, int permits) {
104 | PermissionItem item = new PermissionItem(targetId, commandId, permits);
105 | updatePermissionItem(item);
106 | }
107 |
108 | /**
109 | * 关闭权限而不删除记录
110 | * 根据发送者qq号和permissionIndex从数据库中关闭一条记录
111 | * @param targetId 发送者qq号
112 | * @param commandId EventHandler注解中的permissionIndex
113 | * @see CheckPermission
114 | * @see PermissionItem
115 | */
116 | public void disablePermissionItem(long targetId, int commandId) {
117 | PermissionItem item = new PermissionItem(targetId, String.valueOf(commandId));
118 | updatePermissionItem(item);
119 | }
120 |
121 | /**
122 | * 关闭权限而不删除记录
123 | * 根据发送者qq号和permissionIndex从数据库中关闭一条记录
124 | * @param targetId 发送者qq号
125 | * @param commandId EventHandler注解中的permissionIndex
126 | * @param permits 权限等级 防止下克上
127 | * @see CheckPermission
128 | * @see PermissionItem
129 | */
130 | public void disablePermissionItem(long targetId, int commandId, int permits) {
131 | PermissionItem item = new PermissionItem(targetId, commandId, permits);
132 | updatePermissionItem(item);
133 | }
134 |
135 | /**
136 | * 更新数据库中的权限信息
137 | * @param item 权限存储类
138 | */
139 | public void updatePermissionItem(PermissionItem item) {
140 | PermissionDAO.getInstance().insert(item);
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/src/main/java/net/diyigemt/miraiboot/utils/builder/ExternalResourceBuilder.java:
--------------------------------------------------------------------------------
1 | package net.diyigemt.miraiboot.utils.builder;
2 |
3 | import net.diyigemt.miraiboot.entity.HttpProperties;
4 | import net.mamoe.mirai.Mirai;
5 | import net.mamoe.mirai.utils.ExternalResource;
6 | import net.diyigemt.miraiboot.utils.HttpUtil;
7 |
8 | import java.io.File;
9 | import java.io.IOException;
10 | import java.io.InputStream;
11 |
12 | /**
13 | * 外部资源构造器类
14 | * 请不要用该class声明变量
15 | * @author Haythem
16 | * @since 1.0.0
17 | */
18 | public class ExternalResourceBuilder {
19 |
20 | /**
21 | * 外部资源构造器
22 | * 用于构造URL来源的输入,支持HTTP高级设置
23 | */
24 | public ExternalResource ExtResourceBuilder(String path, HttpProperties properties){
25 | ExternalResource externalResource = null;
26 | try{
27 | if(path.contains("http")){//URL
28 | InputStream inputStream = null;
29 | if(properties != null){
30 | inputStream = HttpUtil.getInputStream_advanced(path, properties);
31 | }else{
32 | inputStream = HttpUtil.getInputStream(path);
33 | }
34 | externalResource = Mirai.getInstance().getFileCacheStrategy().newCache(inputStream);
35 | }else {//LOCAL
36 | File file = new File(path);
37 | externalResource = ExternalResource.create(file);
38 | FileMessageBuilder.FileName = file.getName();
39 | }
40 | }catch (IOException e){
41 | externalResource = null;
42 | }catch (Exception e){
43 | e.printStackTrace();
44 | }
45 | return externalResource;
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/net/diyigemt/miraiboot/utils/builder/FileMessageBuilder.java:
--------------------------------------------------------------------------------
1 | package net.diyigemt.miraiboot.utils.builder;
2 |
3 | import net.diyigemt.miraiboot.entity.EnhancedMessageChain;
4 | import net.diyigemt.miraiboot.entity.HttpProperties;
5 | import net.mamoe.mirai.event.events.MessageEvent;
6 | import net.mamoe.mirai.message.data.MessageChain;
7 | import net.mamoe.mirai.message.data.MessageChainBuilder;
8 | import net.mamoe.mirai.utils.ExternalResource;
9 | import net.diyigemt.miraiboot.entity.MessageEventPack;
10 |
11 | import java.io.File;
12 | import java.util.regex.Matcher;
13 | import java.util.regex.Pattern;
14 |
15 | /**
16 | * 自定义群文件消息构造器
17 | * 样例:
18 | * EnhancedMessageChain chains = new FileMessageBuilder(MessageEventPack eventPack).build();
19 | *
20 | * 注:请不要用此类创建变量
21 | *
22 | * @author Haythem
23 | * @since 1.0.0
24 | */
25 |
26 | public class FileMessageBuilder {
27 |
28 | private final Pattern windowsPattern = Pattern.compile("[A-z]:\\\\([A-Za-z0-9_\u4e00-\u9fa5]+\\\\)*");
29 |
30 | private final Pattern linuxPattern = Pattern.compile("/([A-Za-z0-9_\u4e00-\u9fa5]+/?)+");
31 |
32 | private MessageEvent event = null;
33 |
34 | private MessageEventPack messageEventPack = null;
35 |
36 | private EnhancedMessageChain chains = new EnhancedMessageChain();
37 |
38 | private boolean isUTTPRequestSuccess = true;
39 |
40 | public static String FileName = null;
41 |
42 | public HttpProperties properties = null;
43 |
44 |
45 | /**
46 | * 自定义语音消息构造器
47 | * 可以自定义语音和文字消息构成
48 | * 样例:
49 | * EnhancedMessageChain chains = new FileMessageBuilder(eventPack)
50 | * .add("1234\n")
51 | * .add("1234\n", "5678\n")
52 | * .add(enhancedMessageChain)
53 | * .add(LocalFilePath)
54 | * .add(urlPath)
55 | * .add(file)
56 | * .send();(或.build();)
57 | * }
58 | *
59 | * @param eventPack 事件封装
60 | * @author Haythem
61 | * @since 1.0.0
62 | */
63 | public FileMessageBuilder(MessageEventPack eventPack) {
64 | this.messageEventPack = eventPack;
65 | this.event = eventPack.getEvent();
66 | }
67 |
68 | /**
69 | * 自定义语音消息构造器
70 | * 可以自定义语音和文字消息构成
71 | * 样例:
72 | * EnhancedMessageChain chains = new FileMessageBuilder(eventPack)
73 | * .add("1234\n")
74 | * .add("1234\n", "5678\n")
75 | * .add(enhancedMessageChain)
76 | * .add(LocalFilePath)
77 | * .add(urlPath)
78 | * .add(file)
79 | * .send();(或.build();)
80 | * }
81 | *
82 | * @param eventPack 事件封装
83 | * @author Haythem
84 | * @since 1.0.0
85 | */
86 | public FileMessageBuilder(MessageEventPack eventPack, HttpProperties properties){
87 | this.messageEventPack = eventPack;
88 | this.event = eventPack.getEvent();
89 | this.properties = properties;
90 | }
91 |
92 | /**
93 | * 添加群文件消息方法
94 | * 支持以下类型输入:
95 | *
96 | * 1: MessageChain消息链
97 | * 2: EnhancedMessageChain加强的消息链
98 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
99 | * 4: File 打开的文件类
100 | *
101 | * 注:
102 | * 1: 请勿上传大小为0字节的文件
103 | * 2: URL支持重定向
104 | *
105 | * @param messageChain 当前类型: MessageChain 消息链
106 | */
107 | public FileMessageBuilder add(MessageChain messageChain) {
108 | this.chains.append(messageChain);
109 | return this;
110 | }
111 |
112 | /**
113 | * 添加群文件消息方法
114 | * 支持以下类型输入:
115 | *
116 | * 1: MessageChain消息链
117 | * 2: EnhancedMessageChain加强的消息链
118 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
119 | * 4: File 打开的文件类
120 | *
121 | * 注:
122 | * 1: 请勿上传大小为0字节的文件
123 | * 2: URL支持重定向
124 | *
125 | * @param messageChain 当前类型: EnhancedMessageChain 加强消息链
126 | */
127 | public FileMessageBuilder add(EnhancedMessageChain messageChain){
128 | this.chains.append(messageChain);
129 | return this;
130 | }
131 |
132 | /**
133 | * 添加群文件消息方法
134 | * 支持以下类型输入:
135 | *
136 | * 1: MessageChain消息链
137 | * 2: EnhancedMessageChain加强的消息链
138 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
139 | * 4: File 打开的文件类
140 | *
141 | * 注:
142 | * 1: 请勿上传大小为0字节的文件
143 | * 2: URL支持重定向
144 | *
145 | * @param file 当前类型: File 打开的文件类
146 | */
147 | public FileMessageBuilder add(File file) {
148 | ExternalResource resource = ExternalResource.create(file);
149 | MessageChain chain = new MessageChainBuilder().build();
150 | chain = chain.plus(ExternalResource.uploadAsFile(resource, messageEventPack.getGroup(), "/" + file.getName()));
151 | this.chains.append(chain);
152 | return this;
153 | }
154 |
155 | /**
156 | * 添加群文件消息方法
157 | * 支持以下类型输入:
158 | *
159 | * 1: MessageChain消息链
160 | * 2: EnhancedMessageChain加强的消息链
161 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
162 | * 4: File 打开的文件类
163 | *
164 | * 注:
165 | * 1: 请勿上传大小为0字节的文件
166 | * 2: URL支持重定向
167 | * 3: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
168 | * "联网获取素材失败"
169 | *
170 | * @param s 当前类型: String...可变长字符串
171 | */
172 | public FileMessageBuilder add(String... s) {
173 | for (String i : s) {
174 | MessageChain chain = new MessageChainBuilder().build();
175 | Matcher windowsMatcher = windowsPattern.matcher(i);
176 | Matcher linuxMatcher = linuxPattern.matcher(i);
177 | if (!(windowsMatcher.find() || linuxMatcher.find()) && !i.contains("http")) {
178 | chain = chain.plus(i);
179 | this.chains.append(chain);
180 | }else {
181 | ExternalResource resource = ExtResBuilder(i);
182 | if (isUTTPRequestSuccess) {
183 | chain = chain.plus(ExternalResource.uploadAsFile(resource, messageEventPack.getGroup(), "/" + FileName));
184 | this.chains.append(chain);
185 | } else {
186 | chain = chain.plus("联网获取数据失败");
187 | this.chains.append(chain);
188 | }
189 | }
190 | }
191 | return this;
192 | }
193 |
194 | /**
195 | * 构造器结尾
196 | * 该方法返回构造完成的加强消息链
197 | * @return EnhancedMessageChain 加强消息链
198 | */
199 | public EnhancedMessageChain build() {
200 | return this.chains;
201 | }
202 |
203 | /**
204 | * 构造器结尾
205 | * 该方法返回并自动发送构造完成的加强消息链
206 | * 注:当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
207 | * "联网获取素材失败"
208 | *
209 | * @return EnhancedMessageChain 加强消息链
210 | */
211 | public EnhancedMessageChain send() {
212 | for (MessageChain messageChain : chains) {
213 | event.getSubject().sendMessage(messageChain);
214 | try{
215 | Thread.sleep(500);
216 | } catch (InterruptedException e) {
217 | continue;
218 | }
219 | }
220 | return this.chains;
221 | }
222 |
223 | private ExternalResource ExtResBuilder(String path){
224 | ExternalResource resource = new ExternalResourceBuilder().ExtResourceBuilder(path, properties);
225 | if(resource == null){
226 | isUTTPRequestSuccess = false;
227 | }
228 | return resource;
229 | }
230 | }
231 |
--------------------------------------------------------------------------------
/src/main/java/net/diyigemt/miraiboot/utils/builder/ImageMessageBuilder.java:
--------------------------------------------------------------------------------
1 | package net.diyigemt.miraiboot.utils.builder;
2 |
3 | import net.diyigemt.miraiboot.entity.EnhancedMessageChain;
4 | import net.diyigemt.miraiboot.entity.HttpProperties;
5 | import net.mamoe.mirai.event.events.MessageEvent;
6 | import net.mamoe.mirai.message.data.EmptyMessageChain;
7 | import net.mamoe.mirai.message.data.MessageChain;
8 | import net.mamoe.mirai.message.data.MessageChainBuilder;
9 | import net.mamoe.mirai.utils.ExternalResource;
10 | import net.diyigemt.miraiboot.entity.MessageEventPack;
11 |
12 | import java.io.File;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | /**
17 | * 自定义图片消息构造器
18 | * 样例:
19 | * EnhancedMessageChain chains = new ImageMessageBuilder(MessageEventPack eventPack).build();
20 | *
21 | * 注:请不要用此类创建变量
22 | * @author Haythem
23 | * @since 1.0.0
24 | */
25 | public class ImageMessageBuilder {
26 |
27 | private final Pattern windowsPattern = Pattern.compile("[A-z]:\\\\([A-Za-z0-9_\u4e00-\u9fa5]+\\\\)*");
28 |
29 | private final Pattern linuxPattern = Pattern.compile("/([A-Za-z0-9_\u4e00-\u9fa5]+/?)+");
30 |
31 | private MessageEvent event = null;
32 |
33 | private MessageEventPack messageEventPack = null;
34 |
35 | private MessageChain chain = new MessageChainBuilder().build();
36 |
37 | private EnhancedMessageChain chains = new EnhancedMessageChain();
38 |
39 | private boolean isUTTPRequestSuccess = true;
40 |
41 | private HttpProperties properties = null;
42 |
43 | /**
44 | * 自定义图片消息构造器
45 | * 可以自定义图文消息构成
46 | * 样例:
47 | * EnhancedMessageChain chain = new ImageMessageBuilder(MessageEventPack)
48 | * .add(messageChain)
49 | * .add("1234\n")
50 | * .add("1234\n", "5678\n")
51 | * .add(enhancedMessageChain)
52 | * .add(LocalFilePath)
53 | * .add(urlPath)
54 | * .add(file)
55 | * .send();(或.build();)
56 | *}
57 | * @param eventPack 事件封装
58 | * @author Haythem
59 | * @since 1.0.0
60 | */
61 | public ImageMessageBuilder(MessageEventPack eventPack){
62 | this.messageEventPack = eventPack;
63 | this.event = eventPack.getEvent();
64 | }
65 |
66 | /**
67 | * 自定义图片消息构造器
68 | * 可以自定义图文消息构成
69 | * 样例:
70 | * EnhancedMessageChain chain = new ImageMessageBuilder(MessageEventPack)
71 | * .add(messageChain)
72 | * .add("1234\n")
73 | * .add("1234\n", "5678\n")
74 | * .add(enhancedMessageChain)
75 | * .add(LocalFilePath)
76 | * .add(urlPath)
77 | * .add(file)
78 | * .send();(或.build();)
79 | *}
80 | * @param eventPack 事件封装
81 | * @author Haythem
82 | * @since 1.0.0
83 | */
84 | public ImageMessageBuilder(MessageEventPack eventPack, HttpProperties properties){
85 | this.messageEventPack = eventPack;
86 | this.event = eventPack.getEvent();
87 | this.properties = properties;
88 | }
89 |
90 | /**
91 | * 添加图文消息方法
92 | * 支持以下类型输入:
93 | *
94 | * 1: MessageChain消息链
95 | * 2: EnhancedMessageChain加强的消息链
96 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
97 | * 4: File 打开的文件类
98 | *
99 | * 注:
100 | * 1: 请不要插入和图片无关的素材,如有需求,请使用与素材类型对应的其它Builder
101 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
102 | * "联网获取素材失败"
103 | * @param messageChain 当前类型: 消息链
104 | */
105 | public ImageMessageBuilder add(MessageChain messageChain){
106 | chain = chain.plus(messageChain);
107 | return this;
108 | }
109 |
110 | /**
111 | * 添加图文消息方法
112 | * 支持以下类型输入:
113 | *
114 | * 1: MessageChain消息链
115 | * 2: EnhancedMessageChain加强的消息链
116 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
117 | * 4: File 打开的文件类
118 | *
119 | * 注:
120 | * 1: 请不要插入和图片无关的素材,如有需求,请使用与素材类型对应的其它Builder
121 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
122 | * "联网获取素材失败"
123 | * @param messageChain 当前类型: 加强消息链
124 | */
125 | public ImageMessageBuilder add(EnhancedMessageChain messageChain){
126 | if(!(chain instanceof EmptyMessageChain)){
127 | chains.append(chain);
128 | }
129 | chains.append(messageChain);
130 | this.chain = new MessageChainBuilder().build();
131 | return this;
132 | }
133 |
134 | /**
135 | * 添加图文消息方法
136 | * 支持以下类型输入:
137 | *
138 | * 1: MessageChain消息链
139 | * 2: EnhancedMessageChain加强的消息链
140 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
141 | * 4: File 打开的文件类
142 | *
143 | * 注:
144 | * 1: 请不要插入和图片无关的素材,如有需求,请使用与素材类型对应的其它Builder
145 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
146 | * "联网获取素材失败"
147 | * @param s 当前类型: String... 可变长字符串
148 | */
149 | public ImageMessageBuilder add(String... s){
150 | for(String i : s){
151 | Matcher windowsMatcher = windowsPattern.matcher(i);
152 | Matcher linuxMatcher = linuxPattern.matcher(i);
153 | if(!(windowsMatcher.find() || linuxMatcher.find()) && !i.contains("http")){
154 | chain = chain.plus(i);
155 | }else {
156 | ExternalResource resource = ExtResBuilder(i);
157 | if(isUTTPRequestSuccess){
158 | chain = chain.plus(ExternalResource.Companion.uploadAsImage(resource, event.getSubject()));
159 | }else {
160 | chain = chain.plus("联网获取数据失败");
161 | }
162 | }
163 | }
164 |
165 | return this;
166 | }
167 |
168 | /**
169 | * 添加图文消息方法
170 | * 支持以下类型输入:
171 | *
172 | * 1: MessageChain消息链
173 | * 2: EnhancedMessageChain加强的消息链
174 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
175 | * 4: File 打开的文件类
176 | *
177 | * 注:
178 | * 1: 请不要插入和图片无关的素材,如有需求,请使用与素材类型对应的其它Builder
179 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
180 | * "联网获取素材失败"
181 | * @param file 当前类型: 文件类
182 | */
183 | public ImageMessageBuilder add(File file){
184 | chain = chain.plus(ExternalResource.Companion.uploadAsImage(file, event.getSubject()));
185 | return this;
186 | }
187 |
188 | /**
189 | * 构造器结尾
190 | * 该方法返回构造完成的加强消息链
191 | * @return EnhancedMessageChain 加强消息链
192 | */
193 | public EnhancedMessageChain build(){
194 | this.chains.append(chain);
195 | return chains;
196 | }
197 |
198 | /**
199 | * 构造器结尾
200 | * 该方法返回并自动发送构造完成的加强消息链
201 | * 注:当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
202 | * "联网获取素材失败"
203 | * @return EnhancedMessageChain 加强消息链
204 | */
205 |
206 | public EnhancedMessageChain send(){
207 | this.chains.append(chain);
208 | for (MessageChain chain : chains){
209 | event.getSubject().sendMessage(chain);
210 | try{
211 | Thread.sleep(500);
212 | } catch (InterruptedException e) {
213 | continue;
214 | }
215 | }
216 | return chains;
217 | }
218 |
219 | private ExternalResource ExtResBuilder(String path){
220 | ExternalResource resource = new ExternalResourceBuilder().ExtResourceBuilder(path, properties);
221 | if(resource == null){
222 | isUTTPRequestSuccess = false;
223 | }
224 | return resource;
225 | }
226 | }
227 |
--------------------------------------------------------------------------------
/src/main/java/net/diyigemt/miraiboot/utils/builder/VoiceMessageBuilder.java:
--------------------------------------------------------------------------------
1 | package net.diyigemt.miraiboot.utils.builder;
2 |
3 | import net.diyigemt.miraiboot.entity.EnhancedMessageChain;
4 | import net.diyigemt.miraiboot.entity.HttpProperties;
5 | import net.mamoe.mirai.contact.Group;
6 | import net.mamoe.mirai.event.events.MessageEvent;
7 | import net.mamoe.mirai.message.data.MessageChain;
8 | import net.mamoe.mirai.message.data.MessageChainBuilder;
9 | import net.mamoe.mirai.utils.ExternalResource;
10 | import net.diyigemt.miraiboot.entity.MessageEventPack;
11 |
12 | import java.io.File;
13 | import java.util.regex.Matcher;
14 | import java.util.regex.Pattern;
15 |
16 | /**
17 | * 自定义语音消息构造器
18 | * 样例:
19 | * EnhancedMessageChain = new VoiceMessageBuilder(MessageEventPack eventPack).build();
20 | *
21 | * 注:请不要用此类创建变量
22 | * @author Haythem
23 | * @since 1.0.0
24 | */
25 |
26 | public class VoiceMessageBuilder {
27 |
28 | private final Pattern windowsPattern = Pattern.compile("[A-z]:\\\\([A-Za-z0-9_\u4e00-\u9fa5]+\\\\)*");
29 |
30 | private final Pattern linuxPattern = Pattern.compile("/([A-Za-z0-9_\u4e00-\u9fa5]+/?)+");
31 |
32 | private MessageEvent event = null;
33 |
34 | private MessageEventPack messageEventPack = null;
35 |
36 | private EnhancedMessageChain chains = new EnhancedMessageChain();
37 |
38 | private boolean isUTTPRequestSuccess = true;
39 |
40 | private HttpProperties properties = null;
41 |
42 | /**
43 | * 自定义语音消息构造器
44 | * 可以自定义语音和文字消息构成
45 | * 样例:
46 | * EnhancedMessageChain chains = new VoiceMessageBuilder(eventPack)
47 | * .add("1234\n")
48 | * .add("1234\n", "5678\n")
49 | * .add(enhancedMessageChain)
50 | * .add(LocalFilePath)
51 | * .add(urlPath)
52 | * .add(file)
53 | * .send();(或.build();)
54 | *}
55 | * @param eventPack 事件封装
56 | * @author Haythem
57 | * @since 1.0.0
58 | */
59 | public VoiceMessageBuilder(MessageEventPack eventPack){
60 | this.messageEventPack = eventPack;
61 | this.event = messageEventPack.getEvent();
62 | }
63 |
64 | /**
65 | * 自定义语音消息构造器
66 | * 可以自定义语音和文字消息构成
67 | * 可以使用HTTP高级属性
68 | * 样例:
69 | * EnhancedMessageChain chains = new VoiceMessageBuilder(eventPack)
70 | * .add("1234\n")
71 | * .add("1234\n", "5678\n")
72 | * .add(enhancedMessageChain)
73 | * .add(LocalFilePath)
74 | * .add(urlPath)
75 | * .add(file)
76 | * .send();(或.build();)
77 | *}
78 | * @param eventPack 事件封装
79 | * @author Haythem
80 | * @since 1.0.0
81 | */
82 | public VoiceMessageBuilder(MessageEventPack eventPack, HttpProperties properties){
83 | this.messageEventPack = eventPack;
84 | this.event = messageEventPack.getEvent();
85 | this.properties = properties;
86 | }
87 |
88 | /**
89 | * 添加语音消息方法
90 | * 支持以下类型输入:
91 | *
92 | * 1: MessageChain消息链
93 | * 2: EnhancedMessageChain加强的消息链
94 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
95 | * 4: File 打开的文件类
96 | *
97 | * 注:
98 | * 1: 请不要插入和语音无关的素材,如有需求,请使用与素材类型对应的其它Builder
99 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
100 | * "联网获取素材失败"
101 | * @param messageChain 当前类型: MessageChain 消息链
102 | */
103 | public VoiceMessageBuilder add(MessageChain messageChain){
104 | this.chains.append(messageChain);
105 | return this;
106 | }
107 |
108 | /**
109 | * 添加语音消息方法
110 | * 支持以下类型输入:
111 | *
112 | * 1: MessageChain消息链
113 | * 2: EnhancedMessageChain加强的消息链
114 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
115 | * 4: File 打开的文件类
116 | *
117 | * 注:
118 | * 1: 请不要插入和语音无关的素材,如有需求,请使用与素材类型对应的其它Builder
119 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
120 | * "联网获取素材失败"
121 | * @param messageChain 当前类型: EnhancedMessageChain 消息链
122 | */
123 | public VoiceMessageBuilder add(EnhancedMessageChain messageChain){
124 | this.chains.append(messageChain);
125 | return this;
126 | }
127 |
128 | /**
129 | * 添加语音消息方法
130 | * 支持以下类型输入:
131 | *
132 | * 1: MessageChain消息链
133 | * 2: EnhancedMessageChain加强的消息链
134 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
135 | * 4: File 打开的文件类
136 | *
137 | * 注:
138 | * 1: 请不要插入和语音无关的素材,如有需求,请使用与素材类型对应的其它Builder
139 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
140 | * "联网获取素材失败"
141 | * @param s 当前类型: String... 可变长字符串
142 | */
143 | public VoiceMessageBuilder add(String... s){
144 | for(String i : s){
145 | MessageChain chain = new MessageChainBuilder().build();
146 | Matcher windowsMatcher = windowsPattern.matcher(i);
147 | Matcher linuxMatcher = linuxPattern.matcher(i);
148 | if(!(windowsMatcher.find() || linuxMatcher.find()) && !i.contains("http")){
149 | chain = chain.plus(i);
150 | this.chains.append(chain);
151 | }else {
152 | ExternalResource resource = ExtResBuilder(i);
153 | if(isUTTPRequestSuccess){
154 | chain = chain.plus(this.messageEventPack.uploadAudio(resource));
155 | this.chains.append(chain);
156 | }else {
157 | chain = chain.plus("联网获取数据失败");
158 | this.chains.append(chain);
159 | }
160 | }
161 | }
162 | return this;
163 | }
164 |
165 | /**
166 | * 添加语音消息方法
167 | * 支持以下类型输入:
168 | *
169 | * 1: MessageChain消息链
170 | * 2: EnhancedMessageChain加强的消息链
171 | * 3: String...可变长字符串,字符串支持本地路径、URL和文字消息
172 | * 4: File 打开的文件类
173 | *
174 | * 注:
175 | * 1: 请不要插入和语音无关的素材,如有需求,请使用与素材类型对应的其它Builder
176 | * 2: 当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
177 | * "联网获取素材失败"
178 | * @param file 当前类型: File 打开的文件类
179 | */
180 | public VoiceMessageBuilder add(File file){
181 | MessageChain chain = new MessageChainBuilder().build();
182 | chain = chain.plus(this.messageEventPack.uploadAudio(ExternalResource.create(file)));
183 | chains.append(chain);
184 | return this;
185 | }
186 |
187 | /**
188 | * 构造器结尾
189 | * 该方法返回构造完成的加强消息链
190 | * @return EnhancedMessageChain 加强消息链
191 | */
192 | public EnhancedMessageChain build(){
193 | return this.chains;
194 | }
195 |
196 | /**
197 | * 构造器结尾
198 | * 该方法返回并自动发送构造完成的加强消息链
199 | * 注:当使用URL素材时,如果网络不佳未能获得素材会发送以下纯文本消息:
200 | * "联网获取素材失败"
201 | * @return EnhancedMessageChain 加强消息链
202 | */
203 | public EnhancedMessageChain send(){
204 | for (MessageChain messageChain : chains){
205 | event.getSubject().sendMessage(messageChain);
206 | try{
207 | Thread.sleep(500);
208 | } catch (InterruptedException e) {
209 | continue;
210 | }
211 | }
212 | return this.chains;
213 | }
214 |
215 | private ExternalResource ExtResBuilder(String path){
216 | ExternalResource resource = new ExternalResourceBuilder().ExtResourceBuilder(path, properties);
217 | if(resource == null){
218 | isUTTPRequestSuccess = false;
219 | }
220 | return resource;
221 | }
222 | }
223 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/MANIFEST.MF:
--------------------------------------------------------------------------------
1 | Manifest-Version: 1.0
2 | Main-Class: net.diyigemt.miraiboot.Main
3 |
4 |
--------------------------------------------------------------------------------
/src/main/resources/application-example.yml:
--------------------------------------------------------------------------------
1 | miraiboot:
2 | bots:
3 | -
4 | account: 123 # qq号
5 | password:
6 | kind: PLAIN # 密码类型 目前仅支持PLAIN纯文本类型
7 | value: pwd # qq密码
8 | configuration:
9 | protocol: ANDROID_PHONE # qq登录协议 支持 ANDROID_PHONE ANDROID_PAD ANDROID_WATCH
10 | device: device.json # 设备信息文件名
11 | # 可以配置多个 在@EventFilter中修改bot字段可以指定不同的bot处理事件
12 | - account: 123 # qq号
13 | password:
14 | kind: PLAIN # 密码类型 目前仅支持PLAIN纯文本类型
15 | value: pwd # qq密码
16 | configuration:
17 | protocol: ANDROID_PHONE # qq登录协议 支持 ANDROID_PHONE ANDROID_PAD ANDROID_WATCH
18 | device: device.json # 设备信息文件名
19 | logger:
20 | network: false # 是否在控制台显示bot的网络信息
21 | eventStatus: true # 是否在控制台打印事件执行失败信息 暂时不起作用
22 | debug: false # 是否在控制台打印事件解析信息 暂时不起作用
23 | alias: # 指令别名 将会自动注册 配置方式为 指令全名:别名
24 | configs: # 全局配置 所有全局配置均可以主动从GlobalConfig类中拿到 具体请看注释
25 | DEFAULT_COMMAND_START: "" # 默认指令开头 当@EventHandler中没有指定start时使用改配置
26 | DEFAULT_EVENT_NET_TIMEOUT: 300000 # 默认的上下文监听超时时间 5分钟
27 |
--------------------------------------------------------------------------------
/src/main/resources/banner.txt:
--------------------------------------------------------------------------------
1 | ██████ ██████ ███ ███ ███████████ █████
2 | ░░██████ ██████ ░░░ ░░░ ░░███░░░░░███ ░░███
3 | ░███░█████░███ ████ ████████ ██████ ████ ░███ ░███ ██████ ██████ ███████
4 | ░███░░███ ░███ ░░███ ░░███░░███ ░░░░░███ ░░███ ░██████████ ███░░███ ███░░███░░░███░
5 | ░███ ░░░ ░███ ░███ ░███ ░░░ ███████ ░███ ░███░░░░░███░███ ░███░███ ░███ ░███
6 | ░███ ░███ ░███ ░███ ███░░███ ░███ ░███ ░███░███ ░███░███ ░███ ░███ ███
7 | █████ █████ █████ █████ ░░████████ █████ ███████████ ░░██████ ░░██████ ░░█████
8 | ░░░░░ ░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░░░░░░░░░ ░░░░░░ ░░░░░░ ░░░░░
9 |
--------------------------------------------------------------------------------
/介绍.md:
--------------------------------------------------------------------------------
1 | 在开发基于指令和权限的机器人的过程中感觉mirai-console-plugin的开发方式很难受(没办法debug) 于是有了开发一个包含mirai-core项目的想法
2 | 然后觉得判断消息事件太麻烦逐渐发展成了一个框架
3 | 在这里感谢以下[xiangming-bot](https://github.com/Chuanwise/xiaoming-bot)这个项目 让这个框架多了一个粗糙的上下文交互的功能
4 | **先占个坑 项目这两天测试完就发布**
5 | 当然也可以去仓库自己拉下来complie一个体验版2333
6 |
7 | 仓库在这里->[miraiboot](https://github.com/diyigemt/mirai-boot)
8 |
9 | ## 介绍
10 |
11 | miraiboot是是对mirai框架的简单Java封装。
12 |
13 | 目的是为了让Java开发者更方便地开发基于指令响应的机器人。
14 |
15 | ## 特点
16 |
17 | 1. 不用关心mirai-core的代码
18 |
19 | miraiboot提供了一系列方便的工具类对mirai-core的核心功能依赖进行封装,如消息回复、语音、图片等本地文件的发送等,对于简单的qq机器人开发,Java开发者不需要在去接触kotlin代码,更适合于Java初级开发者。
20 |
21 | 2. 自带简单的消息过滤器和权限管理模块
22 |
23 | miraiboot提供了一系列的工具,可以方便地对消息事件进行过滤和权限管理。
24 |
25 | 权限管理基于SQLite且已经进行了封装,开发者无需考虑实现。
26 |
27 | 3. 注解驱动开发
28 |
29 | miraiboot所有的事件和异常处理都通过注解完成,开发者只需要对处理方法加上对应的注解,其余的都交由miraiboot进行管理,让开发者专注于功能的实现。
30 |
31 | ## 一些展示
32 |
33 | 权限功能:
34 |
35 | 
36 |
37 | ExceptionHandler:
38 |
39 | 
40 |
41 | 上下文交互:
42 |
43 | 
44 |
45 | 
46 |
47 | 
48 |
49 | 仓库在这里->[miraiboot](https://github.com/diyigemt/mirai-boot)
50 |
51 |
--------------------------------------------------------------------------------