20
20
21
21
import static cn .kloping .lsys .utils .MessageUtils .createImageInGroup ;
22
22
23
+ /**
24
+ * @author github-kloping
25
+ */
23
26
public class Loader {
24
27
public static Conf conf = new Conf (0 , 12 );
25
28
26
- public static final String baseUrl = "http://49.232.209.180:20041/api/search/pic?keyword=%s&num=%s&type=%s" ;
29
+ public static final String BASE_URL = "http://49.232.209.180:20041/api/search/pic?keyword=%s&num=%s&type=%s" ;
27
30
28
- public static final InvokeGroup invokeGroup = new InvokeGroup ("getPic" );
31
+ public static final InvokeGroup INVOKE_GROUP = new InvokeGroup ("getPic" );
29
32
30
33
public static long cd = 0 ;
31
34
32
35
static {
33
- invokeGroup .getInvokes ().put ("发张.*" , "getPicOne" );
34
- invokeGroup .getInvokesAfter ().put ("发张.*" , new String []{"<Image = $1>" , "获取失败" });
36
+ INVOKE_GROUP .getInvokes ().put ("发张.*" , "getPicOne" );
37
+ INVOKE_GROUP .getInvokesAfter ().put ("发张.*" , new String []{"<Image = $1>" , "获取失败" });
35
38
36
- invokeGroup .getInvokes ().put ("搜图菜单" , "method" );
37
- invokeGroup .getInvokesAfter ().put ("搜图菜单" , new String []{"<At = ?>\n 搜图菜单\n 发张 xx\n 百度搜图 xx\n 堆糖搜图 xx" });
39
+ INVOKE_GROUP .getInvokes ().put ("搜图菜单" , "method" );
40
+ INVOKE_GROUP .getInvokesAfter ().put ("搜图菜单" , new String []{"<At = ?>\n 搜图菜单\n 发张 xx\n 百度搜图 xx\n 堆糖搜图 xx" });
38
41
39
- invokeGroup .getInvokes ().put ("百度搜图.*" , "getBaidPics" );
40
- invokeGroup .getInvokesAfter ().put ("百度搜图.*" , new String []{"搜索到了$1个结果" , "获取失败" });
42
+ INVOKE_GROUP .getInvokes ().put ("百度搜图.*" , "getBaidPics" );
43
+ INVOKE_GROUP .getInvokesAfter ().put ("百度搜图.*" , new String []{"搜索到了$1个结果" , "获取失败" });
41
44
42
- invokeGroup .getInvokes ().put ("堆糖搜图.*" , "getDuitPics" );
43
- invokeGroup .getInvokesAfter ().put ("堆糖搜图.*" , new String []{"搜索到了$1个结果" , "获取失败" });
45
+ INVOKE_GROUP .getInvokes ().put ("堆糖搜图.*" , "getDuitPics" );
46
+ INVOKE_GROUP .getInvokesAfter ().put ("堆糖搜图.*" , new String []{"搜索到了$1个结果" , "获取失败" });
44
47
45
48
conf = FileInitializeValue .getValue (Resource .rootPath + "/conf/Lsys/lsys-getPic.json" , conf , true );
46
49
}
47
50
48
- public static final Function2 <User , Request , Result > fun2 = (user , request ) -> {
51
+ public static final Function2 <User , Request , Result > FUN2 = (user , request ) -> {
49
52
try {
50
53
if (cd > 0 ) {
51
54
System .err .println ("冷却中..." );
52
55
return null ;
53
56
}
54
57
String name = request .getStr ().substring (request .getOStr ().indexOf ("." ));
55
58
String names = URLEncoder .encode (name , "utf-8" );
56
- JSONObject jo = JSON .parseObject (UrlUtils .getStringFromHttpUrl (String .format (baseUrl , names , conf .getNum (), "baidu" )));
59
+ JSONObject jo = JSON .parseObject (UrlUtils .getStringFromHttpUrl (String .format (BASE_URL , names , conf .getNum (), "baidu" )));
57
60
startCd ();
58
61
ForwardMessageBuilder builder = new ForwardMessageBuilder (request .getEvent ().getSubject ());
59
62
long id = request .getEvent ().getBot ().getId ();
@@ -92,15 +95,15 @@ private static void startCd() {
92
95
});
93
96
}
94
97
95
- public static final Function2 <User , Request , Result > fun1 = (user , request ) -> {
98
+ public static final Function2 <User , Request , Result > FUN1 = (user , request ) -> {
96
99
try {
97
100
if (cd > 0 ) {
98
101
System .err .println ("冷却中..." );
99
102
return null ;
100
103
}
101
104
String name = request .getStr ().substring (request .getOStr ().indexOf ("." ));
102
105
String names = URLEncoder .encode (name , "utf-8" );
103
- JSONObject jo = JSON .parseObject (UrlUtils .getStringFromHttpUrl (String .format (baseUrl , names , "1" , "duit" )));
106
+ JSONObject jo = JSON .parseObject (UrlUtils .getStringFromHttpUrl (String .format (BASE_URL , names , "1" , "duit" )));
104
107
String picUrl = jo .getJSONArray ("data" ).getString (0 );
105
108
startCd ();
106
109
return new Result (new Object []{picUrl }, 0 );
@@ -110,15 +113,15 @@ private static void startCd() {
110
113
return new Result (new Object []{}, 1 );
111
114
};
112
115
113
- public static final Function2 <User , Request , Result > fun3 = (user , request ) -> {
116
+ public static final Function2 <User , Request , Result > FUN3 = (user , request ) -> {
114
117
try {
115
118
if (cd > 0 ) {
116
119
System .err .println ("冷却中..." );
117
120
return null ;
118
121
}
119
- String name = request .getStr ().substring (request .getOStr ().indexOf ("." ));
122
+ String name = request .getStr ().substring (request .getOStr ().indexOf ("." )). trim () ;
120
123
String names = URLEncoder .encode (name , "utf-8" );
121
- JSONObject jo = JSON .parseObject (UrlUtils .getStringFromHttpUrl (String .format (baseUrl , names , conf .getNum (), "duit" )));
124
+ JSONObject jo = JSON .parseObject (UrlUtils .getStringFromHttpUrl (String .format (BASE_URL , names , conf .getNum (), "duit" )));
122
125
startCd ();
123
126
ForwardMessageBuilder builder = new ForwardMessageBuilder (request .getEvent ().getSubject ());
124
127
long id = request .getEvent ().getBot ().getId ();
@@ -164,11 +167,6 @@ private static void startCd() {
164
167
// }
165
168
// }
166
169
167
- public static final Runnable runnable = () -> {
168
- if (!Resource .conf .getInvokeGroups ().containsKey ("getPic" ))
169
- Resource .conf .getInvokeGroups ().put ("getPic" , invokeGroup );
170
- };
171
-
172
170
public static void loadConf () {
173
171
conf = FileInitializeValue .getValue (Resource .rootPath + "/conf/Lsys/lsys-getPic.json" , conf , true );
174
172
}
@@ -177,12 +175,17 @@ public static void applyConf() {
177
175
FileInitializeValue .putValues (Resource .rootPath + "/conf/Lsys/lsys-getPic.json" , conf , true );
178
176
}
179
177
178
+ public static final Runnable RUNNABLE = () -> {
179
+ if (!Resource .conf .getInvokeGroups ().containsKey ("getPic" ))
180
+ Resource .conf .getInvokeGroups ().put ("getPic" , INVOKE_GROUP );
181
+ };
182
+
180
183
public static void load () {
181
- Resource .loadConfAfter .add (runnable );
184
+ Resource .loadConfAfter .add (RUNNABLE );
182
185
183
- Methods .invokes .put ("getPicOne" , fun1 );
184
- Methods .invokes .put ("getBaidPics" , fun2 );
185
- Methods .invokes .put ("getDuitPics" , fun3 );
186
+ Methods .invokes .put ("getPicOne" , FUN1 );
187
+ Methods .invokes .put ("getBaidPics" , FUN2 );
188
+ Methods .invokes .put ("getDuitPics" , FUN3 );
186
189
187
190
Resource .i1 ();
188
191
}
0 commit comments